Repository navigation
Check and log logical replication lag before upgrade for pg17+ - #3214
Merged
Merged
Conversation
FxKu
reviewed
Nov 2, 2026
| 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) |
Contributor
There was a problem hiding this comment.
how about we move this SQL part to a new function in database.go file?
FxKu
reviewed
Nov 2, 2026
| } | ||
| return laggingSlots, nil | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
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).
Collaborator
Author
There was a problem hiding this comment.
yeah, i only did it for this extended testing:D, otherwise there is not much to test
hughcapet
force-pushed
the
upgrade-logical-slots-precheck
branch
from
November 3, 2026 14:36
58e4303 to
9709165
Compare
Co-authored-by: hughcapet <27892524+hughcapet@users.noreply.github.com>
Co-authored-by: hughcapet <27892524+hughcapet@users.noreply.github.com>
Co-authored-by: hughcapet <27892524+hughcapet@users.noreply.github.com>
FxKu
approved these changes
Nov 4, 2026
hughcapet
marked this pull request as ready for review
November 5, 2026 08:26
hughcapet
requested review from
Jan-M,
idanovinda,
jopadi and
mikkeloscar
as code owners
November 5, 2026 08:26
Collaborator
Author
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.