Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(electric): Advance the active replication slot even when there are no writes to electrified tables #1402

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alco
Copy link
Member

@alco alco commented Jun 25, 2024

We've had the logic for advancing the main replication slot for some time now. That slot is used as a way to retain WAL records, allowing the sync service to maintain a window within which it can go back in time and replay old transactions.

A separate replication slot is used for the logical replication connection that the sync service maintains with Postgres when it's running. This slot is also known as the active replication slot.

The issue this PR addresses is caused by the fact that the active replication slot is never advanced when electrified tables aren't seeing any writes. This manifests as an endlessly growing replication lag and disk usage when the database sees a constant rate of writes to non-electrified tables:

Screenshot from 2024-03-23 18-19-05

With the fix in this PR in place, the sync service can now maintain constant replication lag that we can further adjust, for example, to prevent DigitalOcean from raising alerts about high replication lag. On the chart below you can see how disk usage goes down when the sync service is upgraded to a patched version: it never goes up the same way it used to:

Screenshot from 2024-06-25 13-00-58

And here's zoomed-in view of a 6-hour time span with the patched version running:
Screenshot from 2024-06-25 13-01-09

Fixes #1285.

alco added 2 commits June 25, 2024 13:04
This is needed to prevent the active replication slot from retaining too
much WAL when there's no write activity in electrified tables.
@alco alco force-pushed the alco/logical-message-ack branch from edc15f0 to 4fd8520 Compare June 26, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inactive replication slot causing warnings on DO managed Postgres
1 participant