From 9a4157dadbf463ce479d68f3663824b4400d7f9a Mon Sep 17 00:00:00 2001 From: Alexey Kondratov Date: Wed, 4 Dec 2024 14:05:31 +0100 Subject: [PATCH] feat(compute): Set default application_name for pgbouncer connections (#9973) ## Problem When client specifies `application_name`, pgbouncer propagates it to the Postgres. Yet, if client doesn't do it, we have hard time figuring out who opens a lot of Postgres connections (including the `cloud_admin` ones). See this investigation as an example: https://neondb.slack.com/archives/C0836R0RZ0D ## Summary of changes I haven't found this documented, but it looks like pgbouncer accepts standard Postgres connstring parameters in the connstring in the `[databases]` section, so put the default `application_name=pgbouncer` there. That way, we will always see who opens Postgres connections. I did tests, and if client specifies a `application_name`, pgbouncer overrides this default, so it only works if it's not specified or set to blank `&application_name=` in the connection string. This is the last place we could potentially open some Postgres connections without `application_name`. Everything else should be either of two: 1. Direct client connections without `application_name`, but these should be strictly non-`cloud_admin` ones 2. Some ad-hoc internal connections, so if we see spikes of unidentified `cloud_admin` connections, we will need to investigate it again. Fixes neondatabase/cloud#20948 --- compute/etc/pgbouncer.ini | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compute/etc/pgbouncer.ini b/compute/etc/pgbouncer.ini index cb994f961c..abcd165636 100644 --- a/compute/etc/pgbouncer.ini +++ b/compute/etc/pgbouncer.ini @@ -1,5 +1,9 @@ [databases] -*=host=localhost port=5432 auth_user=cloud_admin +;; pgbouncer propagates application_name (if it's specified) to the server, but some +;; clients don't set it. We set default application_name=pgbouncer to make it +;; easier to identify pgbouncer connections in Postgres. If client sets +;; application_name, it will be used instead. +*=host=localhost port=5432 auth_user=cloud_admin application_name=pgbouncer [pgbouncer] listen_port=6432 listen_addr=0.0.0.0