Commit a9e992f
feat: 3-table rotation for subscription and tick to cap held-xmin bloat (#61)
PgQ's event tables already rotate across event_<queue>_0/1/2 children so
dead tuples from long-held xmin stay bounded. The sibling metadata
tables (pgque.subscription, pgque.tick) are still plain UPDATE-heavy
tables, and R5 measured ~14k / ~7k peak dead tuples on them during a
30-min held-xmin window -- which drags iter-TPS 2-5x below the clean
baseline even though the event tables themselves stay clean.
This commit applies the same rotation pattern to both metadata tables:
* pgque.subscription becomes a UNION ALL view over three physical
children subscription_0/1/2, filtered to the currently-active child
via pgque.meta_rotation.cur_subscription_table. INSTEAD OF triggers
route INSERT/UPDATE/DELETE to that active child.
* pgque.tick becomes a UNION ALL view over tick_0/1/2 (no active-
child filter -- consumer sub_last_tick may legitimately reference
an older child). INSTEAD OF triggers route INSERT to the active
child.
* pgque.maint_rotate_metadata() performs the flip: truncate the
(cur+1)%3 slot, copy live subscription rows from cur to the new
slot, flip the pointer. Tick's flip is conditional: we only
truncate the target tick slot if no live sub_last_tick references
a tick_id that lives there.
* pgque.maint_rotate_metadata_step2() ticks last_rotation_step2_txid
in a separate transaction (same two-step pattern PgQ uses for event
rotation), and is scheduled alongside pgque.maint_rotate_tables_step2
by pgque.start().
Rotation period defaults to 30 seconds (tunable via GUC
`pgque.meta_rotation_period`). maint_operations() emits both the step1
and step2 calls for the maintenance orchestrator; maint() skips the
step2 calls because they must run in their own transactions.
pgque_uninstall.sql picks up the new children transitively via
DROP SCHEMA ... CASCADE -- no change to the public uninstall shape.
References #61 (issue). Acceptance criteria verified by R6 smoke test
(separate commit in tests-and-benchmarks repo).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cfb3bae commit a9e992f
2 files changed
Lines changed: 552 additions & 29 deletions
0 commit comments