Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pgdog-config/src/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,13 @@ pub struct General {
/// https://docs.pgdog.dev/configuration/pgdog.toml/general/#cutover_save_config
#[serde(default)]
pub cutover_save_config: bool,

/// Append the client host address and port to the application_name set on connection start.
/// This helps identify the source of queries in pg_stat_activity.
///
/// _Default:_ `false`
#[serde(default)]
pub application_name_add_host: bool,
}

impl Default for General {
Expand Down Expand Up @@ -827,6 +834,7 @@ impl Default for General {
cutover_timeout: Self::cutover_timeout(),
cutover_timeout_action: Self::cutover_timeout_action(),
cutover_save_config: bool::default(),
application_name_add_host: bool::default(),
unique_id_function: Self::unique_id_function(),
}
}
Expand Down
18 changes: 18 additions & 0 deletions pgdog/src/frontend/client/query_engine/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ impl QueryEngine {
let begin_stmt = self.begin_stmt.take();

// 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()
.config
.general
.application_name_add_host
{
if let Some(addr) = *context.stream.peer_addr() {
let base = context
.params
.get_default("application_name", "PgDog")
.to_owned();
let with_host = format!("{} ({})", base, addr);
context
.params
.insert("application_name", with_host.as_str());
}
}
timeout(
query_timeout,
self.backend.link_client(
Expand Down