Repository navigation
feat(postgres): enable replication slot failover on Postgres 17+ (fixes #877) - #882
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🦋 Changeset detectedLatest commit: 4fa66eb The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca8c1d650b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
simolus3
left a comment
There was a problem hiding this comment.
IMO, when it's enabled explicitly and we're connected to version <=16, an error might be better than silently disabling this (since it's a configuration error and users likely know what database version they're connecting to).
Without failover enabled on managed PostgreSQL environments (such as PlanetScale, Aurora, or HA standby setups), replication slots are dropped or lost during primary switchovers or failovers, forcing services to re-replicate snapshots from scratch.
Did you have a chance to test these changes in a setup you've mentioned and could share those steps? I added simple integration tests for this, but I think we might need a bit more.
Do you know if this is safe to enable by default? According to this document, it seems like synchronized_standby_slots need to be configured to ensure the secondary confirms rows before they reach the PowerSync Service. I don't think we need to check settings, but we should probably add documentation pointing towards options required for consistency?
8388d87 to
e7a1d06
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7a1d06137
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Thanks @simolus3! The error check for PostgreSQL <= 16 with PSYNC_S1147 is much clearer than silently disabling it, and keeping slot failover disabled by default is definitely the right call given the \synchronized_standby_slots\ requirement on standby instances. All 34 CI checks across PostgreSQL 11 through 18 are passing green. Ready for your review whenever you have a moment! |
|
Hi @stevensJourney - research summary before we change anything. What the docs say (PG 17, runtime-config-replication, synchronized_standby_slots):
Practical constraint: synchronized_standby_slots is a server-side setting on the primary, not a PowerSync client setting, and it names physical standby slots, which we do not own or know the names of. So from the replication connection we cannot verify it names the PowerSync failover slot specifically. What we can reliably check, alongside the existing PSYNC_S1147 version gate, is that the setting is non-empty. An empty value means the logical senders will not wait for the standby at all, which is precisely the misconfiguration you asked about. Options, in order of impact:
Given the empty case is exactly the silent-data-loss case, I would go with (1): settable only server-side, cheap to check, and consistent with how slot_failover already rejects unsupported versions. If you agree, I will implement option 1 with a test (a missing or empty synchronized_standby_slots raises the new code) and a note in the changeset/docs. If you prefer a softer behavior, or to keep it as a docs-only recommendation, tell me and I will do that instead. |
|
@Tyagiquamar thanks for doing the research. I think option 1 of checking that some physical standby slots are listed in |
Summary
Adds an option to enable logical replication slot failover (
FAILOVER true) when creating replication slots on PostgreSQL 17+. Since the option requires a new slot to be effective (and additional configuration for custom HA PostgreSQL clusters to work correctly), it is not enabled by default.Once this lands, we'd also have to expose the option in the dashboard.
See #877.
Problem & Root Cause
PostgreSQL 17 introduced native logical replication slot synchronization to physical standbys via the
(FAILOVER true)option inCREATE_REPLICATION_SLOT. Without failover enabled on managed PostgreSQL environments (such as PlanetScale, Aurora, or HA standby setups), replication slots are dropped or lost during primary switchovers or failovers, forcing services to re-replicate snapshots from scratch.Previously,
WalStream.startInitialReplicationcreated replication slots with an unparameterized:which defaults
failovertofalse.This adds an option to enable them, along with a version check and simple integration tests.