node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Add default fallback_application_name

Open sehrope opened this issue 6 years ago • 1 comments

How about adding a default value for fallback_application_name to show case the driver being used in the wild?

Some possible values:

  • Node.JS PostgreSQL Driver
  • Node.JS PostgreSQL Driver - pg
  • Node.JS PostgreSQL Driver - [email protected]

I like the last one as having the driver version number may also be useful for a DBA debugging via pg_stat_activity.

For comparison, the PostgreSQL JDBC (Java) driver defaults to "PostgreSQL Java Driver": https://github.com/pgjdbc/pgjdbc/blob/d0453b7582975438eb889082cffcfd8ebe6e3e4d/pgjdbc/src/main/java/org/postgresql/PGProperty.java#L318

If there's interest I can put together a patch for this. The defaults are already in one place so it's just a matter of changing fallback_application_name and updating a couple tests that expect the default name to be empty.

Thoughts?

sehrope avatar Apr 23 '19 21:04 sehrope


const { Pool } = require('pg');
const packageVersion = require('pg/package.json').version; // Import version from package.json

const pool = new Pool({
  // ... other connection parameters ...
  application_name: `Node.JS PostgreSQL Driver - pg@${packageVersion}` // Set default application name
});

pool.query('SELECT NOW()', (err, res) => {
  // Your query logic here
  pool.end();
});

ljluestc avatar Dec 23 '23 22:12 ljluestc