Andreas Vöst
5 months
Andreas Vöst
7 months
Moritz Kraus
1 year
Claus-Theodor Riegg
1 year
Moritz Kraus
2 years

Set a fixed PGAPPNAME when using PgBouncer in transaction mode

Posted . Visible to the public.

When you are using PgBouncer with e.g. a Ruby on Rails application which uses different application_names for the PostgreSQL connection (for Puma, Sidekiq, Cronjobs, ...) PgBouncer will set the application name accordingly on each statement which is executed.

For example, the first connection to PgBouncer is from Puma using application_name = puma: cluster worker 3: 123456. PgBouncer will then execute SET application_name = puma: [...] before executing the statement.
After this query is done, the next connection to PgBouncer is from Sidekiq, where the application_name is /path/to/sidekiq and which uses the same connection from PgBouncer to PostgreSQL.
Then PgBouncer will execute SET application_name = /path/to/sidekiq before running the Sidekiq Query.

This can happen quite often and take a lot of resources. Due to that you should make sure all parts of your application will use the same application_name, e.g. by using PGAPPNAME Show archive.org snapshot . Keep in mind you will loose the knowledge of which application executed this query.

Last edit
Kim Klotz
License
Source code in this card is licensed under the MIT License.