Skip to content

fix(postgres): advance replication slot on idle keepalives - #88

Merged
olucasandrade merged 4 commits into
fix/review-findings-20260924from
fix/postgres-keepalive-slot-advance
Sep 25, 2026
Merged

olucasandrade merged 4 commits into
fix/review-findings-20260924from
fix/postgres-keepalive-slot-advance

Conversation

@olucasandrade

Copy link
Copy Markdown
Owner

Plan

.claude/fix-plans/postgres-keepalive-slot-advance-20260924-212132.md

Problem

After the CHK-01 standby cap, keepalive ServerWALEnd updates clientXLogPos but is never persisted, so confirmed_flush_lsn cannot advance past the last published-table transaction. Heavy writes on unpublished tables retain WAL indefinitely.

Introduced by

fccab63

Implementation

  • Track non-streamed in-flight txs with txOpen (set on Begin, cleared on Commit / StreamCommit / StreamAbort).
  • On keepalive/heartbeat, call maybeAdvanceOnKeepalive: persist and ack clientXLogPos only when ahead of lastSavedLSN and idleForSlotAdvance() (walBuf empty, !streamedOpen, !txOpen). Otherwise keep ackLSN cap at lastSavedLSN (fail closed, CHK-01).
  • applyKeepalive centralizes ServerWALEnd update + advance/reply decision for the fake-walsender tests.

Validation

  • CGO_ENABLED=0 go test ./internal/source/postgres -count=1 — pass
  • Fake keepalive-only path asserts checkpoint + ack advance
  • Regression: in-flight Begin/insert caps ack at lastSavedLSN; published Commit still checkpoints; streamed open blocks advance

Residual risk

  • Conservatism: any open Begin…Commit (even with empty walBuf after mid-tx flush) blocks keepalive advance until Commit — unpublished WAL behind that tx still holds briefly.
  • Heartbeat/keepalive advance still depends on correctly proving idle state; a missed txOpen/streamedOpen clear would re-pin the slot (fail closed for CHK-01, not for WAL growth).

Persist and ack keepalive ServerWALEnd when no published-table work is
in flight so unpublished WAL no longer pins confirmed_flush_lsn, while
keeping the CHK-01 lastSavedLSN cap for in-flight commits.

Introduced-by: fccab63
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 5b3dd518-9d83-43da-9317-1e55ea55263d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Deploying kaptanto with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1125932
Status: ✅  Deploy successful!
Preview URL: https://f1180776.kaptanto.pages.dev
Branch Preview URL: https://fix-postgres-keepalive-slot.kaptanto.pages.dev

View logs

@olucasandrade
olucasandrade merged commit e81db64 into fix/review-findings-20260924 Sep 25, 2026
15 checks passed
@olucasandrade
olucasandrade deleted the fix/postgres-keepalive-slot-advance branch September 25, 2026 09:35
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.

1 participant