Skip to content

fix missing dbname for sync_replication_slots#908

Open
thamerlan wants to merge 3 commits intoEnterpriseDB:masterfrom
thamerlan:patch-1
Open

fix missing dbname for sync_replication_slots#908
thamerlan wants to merge 3 commits intoEnterpriseDB:masterfrom
thamerlan:patch-1

Conversation

@thamerlan
Copy link
Copy Markdown

Preserve dbname from upstream conninfo when generating standby primary_conninfo.

Previously, repmgr explicitly skipped the 'dbname' parameter when building primary_conninfo for standby nodes. This worked fine for all versions prior to PostgreSQL 17 because the replication protocol ignores dbname.

However, in PostgreSQL 17+, the sync_replication_slots worker requires a valid dbname in the connection string. Without this change, standby nodes cannot use replication slots after failover or switchover.

This patch preserves the dbname from the upstream node's conninfo, if present, without adding any defaults. This approach is fully backward-compatible with older PostgreSQL versions and does not affect the existing replication logic.

Preserve dbname from upstream conninfo when generating standby primary_conninfo.

Previously, repmgr explicitly skipped the 'dbname' parameter when building
primary_conninfo for standby nodes. This worked fine for all versions prior
to PostgreSQL 17 because the replication protocol ignores dbname.

However, in PostgreSQL 17+, the sync_replication_slots worker requires a
valid dbname in the connection string. Without this change, standby nodes
cannot use replication slots after failover or switchover.

This patch preserves the dbname from the upstream node's conninfo, if present,
without adding any defaults. This approach is fully backward-compatible with
older PostgreSQL versions and does not affect the existing replication logic.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates repmgr’s standby primary_conninfo generation to preserve dbname from the upstream node’s conninfo so PostgreSQL 17+ sync_replication_slots can connect successfully after failover/switchover.

Changes:

  • Stop skipping dbname when building primary_conninfo.
  • Add logic intended to append dbname into the generated connection string.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8391 to +8396
if (strcmp(param_list->keywords[c], "dbname") == 0)
{
dbname_found = true;
appendPQExpBuffer(&conninfo_buf, " dbname=%s", param_list->values[c]);
continue;
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The special-cased dbname handling appends the value with %s instead of using appendConnStrVal(), so dbnames containing spaces, quotes, or backslashes will produce an invalid primary_conninfo string. It also unconditionally adds a leading space and bypasses the normal spacing logic. Prefer letting dbname go through the same generic path as other keywords (i.e., stop skipping it and remove this special-case), or at least build it with appendConnStrVal() and consistent spacing.

Copilot uses AI. Check for mistakes.
thamerlan and others added 2 commits March 28, 2026 17:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants