feat: add application_name_add_host setting#974
Conversation
Appends the client host address and port to application_name when connecting to the backend, matching PgBouncer behavior. Only applied at connection start, not on subsequent SET commands. Disabled by default. [general] application_name_add_host = true
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| // We may need to sync params with the server and that reads from the socket. | ||
| // If application_name_add_host is enabled, append client address to application_name. | ||
| // This matches PgBouncer behavior: only applied at connection start, not on SET. | ||
| if crate::config::config() |
There was a problem hiding this comment.
If you want to replicate pgbouncer behavior, I would recommend handling it here:
pgdog/pgdog/src/frontend/listener.rs
Line 172 in b9fb98f
The config is already available and you can mutate the params, i.e., if application_name is indeed in the startup params, you can add the peer_addr() there once.
Your current implementation will actually update the application_name with the IP address even if the client uses SET. This is probably how we want it to work actually; I find pgbouncer's implementation arbitrarily limited (probably because they don't parse / handle SET statements).
If we go with this, I would recommend handling this here:
pgdog/pgdog/src/frontend/client/mod.rs
Line 520 in b9fb98f
format! creates a new string).
Closes #253
What
Adds
application_name_add_hostsetting to[general]config, matching PgBouncer's behavior.When enabled, PgDog appends the client's IP address and port to the
application_nameparameter when connecting to the backend. This makesit easy to trace which client is behind which backend connection in
pg_stat_activity.Example:
myappbecomesmyapp (192.168.1.5:54321)Behavior
false)SET application_namecommandsConfig
Changes
pgdog-config/src/general.rs-> addedapplication_name_add_host: boolfield toGeneralstructsrc/frontend/client/query_engine/connect.rs-> appends client addr toapplication_namebeforelink_clientis called