Skip to content

Check and log logical replication lag before upgrade for pg17+ - #3214

Merged
hughcapet merged 5 commits into
masterfrom
upgrade-logical-slots-precheck
Nov 5, 2026
Merged

hughcapet merged 5 commits into
masterfrom
upgrade-logical-slots-precheck

Conversation

@hughcapet

Copy link
Copy Markdown
Collaborator

For PostgreSQL 17+, check for logical replication slots with more than 32 MiB of lag before starting the upgrade script. This surfaces the issue earlier and avoids a confusing failure after the script has begun. PostgreSQL 17+ only: pg_upgrade added this logical replication lag check in that version.

Comment thread pkg/cluster/majorversionupgrade.go Outdated
if c.currentMajorVersion >= logicalReplicationSlotLagCheckMinVersion {
const logicalSlotLagQuery = `SELECT slot_name, pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)::bigint
FROM pg_replication_slots WHERE slot_type = 'logical'`
slotLagOutput, err := c.ExecCommand(podName, "psql", "-X", "-A", "-t", "-v", "ON_ERROR_STOP=1", "-U", c.OpConfig.SuperUsername, "-d", "postgres", "-c", logicalSlotLagQuery)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how about we move this SQL part to a new function in database.go file?

Comment thread pkg/cluster/majorversionupgrade.go Outdated
}
return laggingSlots, nil
}

@FxKu FxKu Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could the query not contain more logic instead of the go code? We could pass the tolerance value to the query and only return lagging slots or empty result. When empty we're good to go, when query returns slots we delay the major version upgrade. Could still be nice to know, though, which slots are lagging behind (which this PR currently supports).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, i only did it for this extended testing:D, otherwise there is not much to test

Co-authored-by: hughcapet <27892524+hughcapet@users.noreply.github.com>
Copilot AI and others added 2 commits November 4, 2026 13:05
Co-authored-by: hughcapet <27892524+hughcapet@users.noreply.github.com>
Co-authored-by: hughcapet <27892524+hughcapet@users.noreply.github.com>
@FxKu FxKu added this to the 2.1.0 milestone Nov 4, 2026
@FxKu FxKu moved this to Good state for merge in Postgres Operator Nov 4, 2026
@hughcapet
hughcapet marked this pull request as ready for review November 5, 2026 08:26
@hughcapet

Copy link
Copy Markdown
Collaborator Author

👍

@hughcapet
hughcapet merged commit aad8792 into master Nov 5, 2026
15 checks passed
@hughcapet
hughcapet deleted the upgrade-logical-slots-precheck branch November 5, 2026 09:04
@github-project-automation github-project-automation Bot moved this from Good state for merge to Done in Postgres Operator Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants