Repository navigation
Protect TOAST values needed by shadow replication - #351
Conversation
94eeb91 to
a692688
Compare
There was a problem hiding this comment.
Auto-approved by the AI review gate on a692688. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
a692688 to
6526124
Compare
There was a problem hiding this comment.
Auto-approved by the AI review gate on 6526124. Details in the approver's comment on this pull request.
|
|
|
did 1-7: (edit: 1-6)
|
There was a problem hiding this comment.
Auto-approved by the AI review gate on 7a45844. Details in the approver's comment on this pull request.
|
upon closer review, 7 was costing too much. 150 lines for an optimization for subtransactions which all transactions had to pay. new code is +75/-118 relative to old code:
Details7: Reverted the version that tracked commits and aborts. It parsed every commit under a shared lock to help only savepoint workloads, and because batches are scanned in parallel, a late-seen commit could make it skip a read-ahead another transaction needed. Read-ahead is only a prefetch, so neither version could return a wrong value; this was purely a cost trade. Now a savepoint's value counts as its transaction's own only when WAL names the parent: the toplevel xid on a subtransaction's first record at wal_level=logical, or XLOG_XACT_ASSIGNMENT. Transactions without savepoints pay one integer check per record. A missing link falls back to the exact-xid check, so the worst case is the old wasted read-ahead. At wal_level=replica with fewer than 64 subtransactions nothing changes. |
28ad419 to
70d61b3
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 70d61b3. Configure here.
AI review gate — AI review passedClean review from: Cursor Bugbot. |
70d61b3 to
a0747c5
Compare
There was a problem hiding this comment.
Auto-approved by the AI review gate on a0747c5. Details in the approver's comment on this pull request.
a0747c5 to
bfe63d7
Compare
There was a problem hiding this comment.
Auto-approved by the AI review gate on bfe63d7. Details in the approver's comment on this pull request.
PostgreSQL can vacuum TOAST values before walshadow reads them. Hold back source cleanup while replication still needs those values. Check once a second so cleanup can resume promptly, and improve read-ahead so fewer writes wait for TOAST reads.
bfe63d7 to
9a46ea0
Compare
There was a problem hiding this comment.
Auto-approved by the AI review gate on 9a46ea0. Details in the approver's comment on this pull request.

PostgreSQL can vacuum TOAST values before walshadow reads them.
Hold back source cleanup while replication still needs those values.
Check once a second so cleanup can resume promptly, and improve
read-ahead so fewer writes wait for TOAST reads.
Note
High Risk
Changes replication feedback, manifest schema, and vacuum behavior cluster-wide while lagging; mis-pinned or released xmin can still lose TOAST values or bloat the source.
Overview
Adds
[toast] source_horizon_pin(default on in shadow mode) so walshadow tells PostgreSQL via hot-standby feedback xmin which row versions to keep until the resolved floor advances. A newHorizonPintracks samples from WALrunning_xactsand a 1 Hz sidecar SQL sampler (pg_snapshot_xmin+ insert LSN); the stream pump sends feedback when xmin changes, seeds from slot/saved manifesthorizon_xmin, and clears the pin when disabled.Resume manifests now persist
horizon_xminso restarts can re-hold the same horizon (especially with a physical slot).Read-ahead / planning is tightened: speculative reads are dropped only for reservations below the commit LSN; chunk births in the committing transaction invalidate earlier read-aheads for those value IDs; prescan treats same-transaction (and linked subxact) TOAST births as resolving from WAL, not shadow. Shadow replay polling starts faster and backs off.
Adds
shadow_toast_horizonbench plus integration tests for VACUUM during outage with/without pin, and expands architecture/docs/plans around partial reclamation fencing and future spill work.Reviewed by Cursor Bugbot for commit 9a46ea0. Bugbot is set up for automated code reviews on this repo. Configure here.