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

Application Name should be set for Postgres Connection/Query

Open thoven87 opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. Allow options to set the Application names for each connection/Query

Describe the solution you'd like PostgresClient.Configuration should accept application name

It makes debuting which application querying the database for debug/audit purposes

Active queries can be retrieves easily with

SELECT 
    pid
    datname,
    usename,
    application_name,
    client_hostname,
    client_port,
    backend_start,
    query_start,
    query,
    state
FROM pg_stat_activity
WHERE state = 'active';

Describe alternatives you've considered Alternatively, a connection string should be allow to set the application instead of calling postgresql://username@localhost/database?application_name=my_application

withConnection{ connection in
 connection.query("SET application_name TO my_application")
let stream = connection.query("Some query")
}
`

**Additional context**
This is very useful incases where multiple services can access the same database.

thoven87 avatar Oct 11 '24 02:10 thoven87