feature: Add retention-based partition dropping - #33
Draft
codybswaney wants to merge 1 commit into
Draft
codybswaney wants to merge 1 commit into
codybswaney wants to merge 1 commit into
Conversation
Adds drop_partitions (and an opt-in maintain --drop-expired) to prune partitions outside a table's retention window. Retention is read from the settings comment as `retention:<N>`: the current period plus the N before it are kept. Tables without a retention are never pruned, and a malformed value is ignored rather than widening what gets dropped. Partitions are selected by bounds (range ends at or before the cutoff), so legacy-named and irregular (e.g. year-resetting weekly) layouts work. DEFAULT, MINVALUE/MAXVALUE and sub-partitioned children are never dropped, and nothing is dropped with CASCADE. Dropping a partition takes ACCESS EXCLUSIVE on the parent, so each partition is dropped oldest-first in its own transaction under lock_timeout (default 5s, shared with --lock-timeout). A timeout stops the run, keeping retained coverage contiguous; DropPartitionsError reports what was already dropped and the rest is retried on the next run. In maintain, tables are extended before they are pruned so a failed drop never costs runway, and the JSONL records gain partitions.dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
drop_partitionsand an opt-inmaintain --drop-expiredto prune partitions that fall outside a table's retention window.retention:<N>: the current period plus theNperiods before it are kept. Tables without it are never pruned. A malformed value (0,-1,3m, …) is ignored, so a typo can't widen what gets dropped.retentionand the job passes--drop-expired(default off).DEFAULT,MINVALUE/MAXVALUE, and sub-partitioned children. Nothing is dropped withCASCADE, so a dependent view or other object makes the drop fail loudly.ACCESS EXCLUSIVEon the parent. Each partition is dropped oldest-first in its own transaction underlock_timeout(shares--lock-timeout, default5s), and the partition is re-checked inside that transaction before the drop.DropPartitionsError.droppedreports what was already removed; the rest is retried on the next run.maintainextends before it prunes, so a failed drop never costs runway. JSONL records gainpartitions.droppedanddroppedPartitions(names), and the start record gainsdropExpired.--dry-runondrop_partitionslists what would be dropped.Validation
maintainintegration, settings parsing, and the cutoff math.drop_partitions --lock-timeout 1sgave up after ~1s, dropped nothing and exited 1. A writer arriving meanwhile waited ~0.8s, so writer delay is capped by the timeout.publish_via_partition_rootmodes, one with an actively streaming consumer duringmaintain --drop-expired.DELETEs.retention:3kept 2026-06 onward on 2026-09-22; weeklyretention:4kept the ISO week of 2026-08-24 onward.Notes / follow-ups
DETACH PARTITION … CONCURRENTLY(PG14+) would avoid theACCESS EXCLUSIVElock on the parent. It can't run in a transaction block, so it needs a non-transactional test harness. Left for a follow-up.🤖 Generated with Claude Code