Skip to content

fix: ReplicationPoller consumes slot if publication is not empty#1919

Merged
edgurgel merged 10 commits into
mainfrom
fix/replication-cdc-no-tables
Jun 12, 2026
Merged

fix: ReplicationPoller consumes slot if publication is not empty#1919
edgurgel merged 10 commits into
mainfrom
fix/replication-cdc-no-tables

Conversation

@edgurgel

@edgurgel edgurgel commented May 28, 2026

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

  • Change ReplicationPoller to only start a replication slot if the publication is not empty.
  • Also track when publication changes from empty to non-empty and vice-versa and react accordingly

The goal here is only to establish the replication slot when absolute necessary

Why do we even keep the ReplicationPoller up if there is no publication? If we don't whenever a postgres_changes join happens it will start it again. While this approach will leave this process up and running until it notices that there are no subscriptions (SubscriptionManager does this) and stop everything.

I've also fixed the case when fetching the publication tables could fail but we would assume that the publication was empty

Copilot AI 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.

Pull request overview

This PR adjusts the Postgres CDC RLS replication poller lifecycle so it reacts to an empty/non-empty publication by pausing/resuming polling and dropping/recreating the replication slot as publication tables come and go, reducing unnecessary WAL work.

Changes:

  • Add Replications.drop_replication_slot/2 and related tests.
  • Teach ReplicationPoller to check publication table OIDs periodically and stop polling / drop the slot when the publication becomes empty, then resume when tables reappear.
  • Add unit + integration coverage for the poller’s empty-publication behavior and slot toggling.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/extensions/postgres_cdc_rls/replication_poller.ex Adds publication OID tracking and slot drop/recreate behavior tied to publication emptiness.
lib/extensions/postgres_cdc_rls/replications.ex Introduces drop_replication_slot/2 helper for removing logical replication slots.
test/realtime/extensions/cdc_rls/replication_poller_test.exs Updates poller tests and adds coverage for “no tables → no polling” and toggling behavior.
test/realtime/extensions/cdc_rls/replications_test.exs Adds unit tests for drop_replication_slot/2.
test/realtime/extensions/cdc_rls/cdc_rls_test.exs Adds integration tests verifying slot toggling when publication/tables are changed.

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

Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex
Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex
Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex
@coveralls

coveralls commented May 28, 2026

Copy link
Copy Markdown

Coverage Status

Coverage is 91.507%fix/replication-cdc-no-tables into main. No base build found for main.

@edgurgel
edgurgel force-pushed the fix/replication-cdc-no-tables branch 2 times, most recently from 262d86b to eae2a1c Compare June 10, 2026 01:58
@edgurgel
edgurgel requested a review from Copilot June 10, 2026 02:05

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex Outdated
Comment thread test/realtime/extensions/cdc_rls/replication_poller_test.exs
Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex
@edgurgel
edgurgel requested a review from filipecabaco June 10, 2026 04:47

@leandrocp leandrocp 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.

Just 2 small suggestions, non-blocking.

Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex
Comment thread lib/extensions/postgres_cdc_rls/replication_poller.ex Outdated
@edgurgel
edgurgel force-pushed the fix/replication-cdc-no-tables branch from 01eea67 to 3e6308c Compare June 12, 2026 00:29
@blacksmith-sh

This comment has been minimized.

@edgurgel
edgurgel merged commit 59199ff into main Jun 12, 2026
60 of 63 checks passed
@edgurgel
edgurgel deleted the fix/replication-cdc-no-tables branch June 12, 2026 00:54
@realtime-release-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.107.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants