Skip to content

feat(postgres): enable replication slot failover on Postgres 17+ (fixes #877) - #882

Merged
simolus3 merged 6 commits into
powersync-ja:mainfrom
Tyagiquamar:fix/postgres-17-replication-slot-failover
Nov 16, 2026
Merged

simolus3 merged 6 commits into
powersync-ja:mainfrom
Tyagiquamar:fix/postgres-17-replication-slot-failover

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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 in CREATE_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.startInitialReplication created replication slots with an unparameterized:

CREATE_REPLICATION_SLOT <slotName> LOGICAL pgoutput

which defaults failover to false.

This adds an option to enable them, along with a version check and simple integration tests.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T08:51:42.174045Z 4fa66eb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4fa66eb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@powersync/service-module-postgres Patch
@powersync/service-errors Patch
@powersync/service-image Minor
@powersync/service-schema Minor
@powersync/lib-services-framework Patch
@powersync/service-module-mssql Patch
@powersync/service-rsocket-router Patch
@powersync/service-core Minor
@powersync/lib-service-mongodb Patch
@powersync/lib-service-postgres Patch
@powersync/service-module-convex Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
test-client Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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 simolus3 left a comment

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.

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?

@simolus3
simolus3 force-pushed the fix/postgres-17-replication-slot-failover branch from 8388d87 to e7a1d06 Compare November 9, 2026 14:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

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!

@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

Hi @stevensJourney - research summary before we change anything.

What the docs say (PG 17, runtime-config-replication, synchronized_standby_slots):

  • A comma-separated list of physical standby replication slots the logical WAL senders wait for before releasing changes to failover logical replication slots. It guarantees failover slots do not consume changes that the physical standby has not yet received and flushed.
  • The standby also needs sync_replication_slots = true, and without the physical slot listed in synchronized_standby_slots, physical and logical slots are not kept in lockstep, and a promoted standby can be behind the replicator confirmed position: exactly the data-loss window you described.

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:

  1. Hard-fail at connect time when slot_failover=true and SHOW synchronized_standby_slots is empty (a new PSYNC_S1147-style code, like the PostgreSQL <17 check). This matches the existing fail-fast pattern and is zero-risk for correct setups; it does not affect users who never enable slot_failover.
  2. Warn loudly (log + continue) - gentler, but lets a silently-broken configuration through, which defeats the point.
  3. Document only - no code change.

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.

@stevensJourney

Copy link
Copy Markdown
Collaborator

@Tyagiquamar thanks for doing the research. I think option 1 of checking that some physical standby slots are listed in synchronized_standby_slots is a useful guard, even though it isn’t a complete check. I’d be happy if that was added :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants