Skip to content

feat: add application_name_add_host setting#974

Open
Nihal-Pandey-2302 wants to merge 1 commit into
pgdogdev:mainfrom
Nihal-Pandey-2302:feat/application-name-add-host
Open

feat: add application_name_add_host setting#974
Nihal-Pandey-2302 wants to merge 1 commit into
pgdogdev:mainfrom
Nihal-Pandey-2302:feat/application-name-add-host

Conversation

@Nihal-Pandey-2302
Copy link
Copy Markdown

Closes #253

What

Adds application_name_add_host setting to [general] config, matching PgBouncer's behavior.

When enabled, PgDog appends the client's IP address and port to the
application_name parameter when connecting to the backend. This makes
it easy to trace which client is behind which backend connection in
pg_stat_activity.

Example: myapp becomes myapp (192.168.1.5:54321)

Behavior

  • Disabled by default (false)
  • Only applied at connection start, not on subsequent SET application_name commands
  • Silently skipped if peer address is unavailable (e.g. Unix sockets)

Config

[general]
application_name_add_host = true

Changes

  • pgdog-config/src/general.rs -> added application_name_add_host: bool field to General struct
  • src/frontend/client/query_engine/connect.rs -> appends client addr to application_name before link_client is called

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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 12, 2026

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 37.50000% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pgdog/src/frontend/client/query_engine/connect.rs 33.33% 10 Missing ⚠️

📢 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()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to replicate pgbouncer behavior, I would recommend handling it here:

let startup = match Startup::from_stream(&mut stream).await {

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:

let config = config::config();
and only doing this operation if it hasn't been done before; this avoids unnecessary allocations (format! creates a new string).

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.

Add "application_name_add_host" setting

3 participants