Skip to content

PostgresClient should support additionalStartupParameters #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thoven87 opened this issue Oct 11, 2024 · 4 comments · Fixed by #521
Closed

PostgresClient should support additionalStartupParameters #518

thoven87 opened this issue Oct 11, 2024 · 4 comments · Fixed by #521
Assignees
Labels
enhancement New feature or request

Comments

@thoven87
Copy link
Contributor

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 thoven87 added the enhancement New feature or request label Oct 11, 2024
@gwynne
Copy link
Member

gwynne commented Oct 11, 2024

@fabianfett Looks like this is available through the old PostgresConnection configuration but not through PostgresClient's.

@fabianfett
Copy link
Collaborator

@thoven87 sorry for the very slow response. You can achieve this with todays PostgresConnection API:

var configuration = PostgresConnection.Configuration(username: "my_username", tls: .disable)
configuration.options.additionalStartupParameters = [("application_name", "my_application")]

As @gwynne points out, this is not possible with today's PostgresClient API. However it should be fairly trivial to add this behavior.

@fabianfett fabianfett changed the title Application Name should be set for Postgres Connection/Query PostgresClient should support additionalStartupParameters Oct 21, 2024
@fabianfett
Copy link
Collaborator

@thoven87 PR raised as #521.

@thoven87
Copy link
Contributor Author

@thoven87 PR raised as #521.

Thank you! I'll take a look soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants