Skip to content

Set Postgres application_name for pgroll's migrator and state connections #762

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

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

andrew-farries
Copy link
Collaborator

Set the application_name parameter on the two PostgreSQL connections used by pgroll to help identify pgroll connections in monitoring tools.

Migrator connections use "pgroll" while state connections use "pgroll-state" as their application name.

These application names are visible in the pg_stat_activity table. For example, run this migration:

operations:
  - sql:
      up: |
        select pg_sleep(60);

And then

select application_name, query from pg_stat_activity

shows rows identifying the connections:

+------------------+------------------------------------------------------+
| application_name | query                                                |
|------------------+------------------------------------------------------|
| pgroll-state     | SELECT "pgroll".read_schema($1)                      |
| pgroll           | select pg_sleep(60);                                 |
| pgcli            | select application_name, query from pg_stat_activity |
+------------------+------------------------------------------------------+

Testcases are added to verify this behavior works as expected.

Ensure that both the migrator and state connections have their
application_name set to a specific value for easy identification in
pg_stat_activity.
@github-actions github-actions bot temporarily deployed to Docs Preview March 31, 2025 08:49 Inactive
@andrew-farries andrew-farries marked this pull request as ready for review March 31, 2025 08:53
@andrew-farries andrew-farries requested a review from kvch March 31, 2025 08:53
@andrew-farries andrew-farries merged commit c7e4fde into main Mar 31, 2025
30 checks passed
@andrew-farries andrew-farries deleted the set-application-name branch March 31, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants