Marc Dierig
11 months
Stefan Langenmaier
1 year
Andreas Vöst
1 month
Claus-Theodor Riegg
4 years
Andreas Vöst
3 months
Andreas Vöst
3 months
Kim Klotz
4 months
Claus-Theodor Riegg
8 years
Andreas Vöst
6 months
Andreas Vöst
8 months

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.