brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.04k stars 1.21k forks source link

Add default fallback_application_name #1883

Open sehrope opened 5 years ago

sehrope commented 5 years ago

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

Some possible values:

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?

ljluestc commented 6 months ago

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();
});