Problem
ensure_future_partitions(3) runs at startup (main.rs:200) and issues CREATE TABLE IF NOT EXISTS ... PARTITION OF DDL for each missing monthly partition across 2 tables (events and delivery_log).
Issues
-
DDL during startup: CREATE TABLE ... PARTITION OF takes an ACCESS EXCLUSIVE lock on the parent table. If other pods are serving queries, the DDL blocks behind them AND blocks all subsequent readers.
-
No lock timeout on partition DDL: partition creation uses a bare sqlx query with no statement or lock timeout. If another long-running query holds a conflicting lock, partition creation blocks indefinitely.
-
Sequential partition creation: partitions are created one at a time in a loop (partition.rs:18-53). If 6 partitions need creating (3 months x 2 tables), that is 6 sequential DDL statements.
-
Catch-all partition overlap: when a _p_future catch-all partition already covers the range, the overlap error (42P17) is swallowed with an info log. This means partition management never actually creates new partitions until the catch-all is detached — which there is no code for. The catch-all partition will accumulate all future data in one unpartitioned bucket.
-
No partition pruning validation: there are no metrics or checks confirming that query plans actually use partition pruning.
Proposed changes
- Move partition management to a separate pre-deploy step or background task.
- Add
SET lock_timeout before partition DDL to cap wait time.
- Add a partition-count metric polled in the metrics loop.
- Document or implement catch-all partition lifecycle (detach/split as time passes).
Priority
Medium — partition DDL is infrequent but each occurrence is a deploy-time risk. The catch-all accumulation is a slow-burn correctness issue.
Problem
ensure_future_partitions(3)runs at startup (main.rs:200) and issuesCREATE TABLE IF NOT EXISTS ... PARTITION OFDDL for each missing monthly partition across 2 tables (eventsanddelivery_log).Issues
DDL during startup:
CREATE TABLE ... PARTITION OFtakes anACCESS EXCLUSIVElock on the parent table. If other pods are serving queries, the DDL blocks behind them AND blocks all subsequent readers.No lock timeout on partition DDL: partition creation uses a bare sqlx query with no statement or lock timeout. If another long-running query holds a conflicting lock, partition creation blocks indefinitely.
Sequential partition creation: partitions are created one at a time in a loop (
partition.rs:18-53). If 6 partitions need creating (3 months x 2 tables), that is 6 sequential DDL statements.Catch-all partition overlap: when a
_p_futurecatch-all partition already covers the range, the overlap error (42P17) is swallowed with an info log. This means partition management never actually creates new partitions until the catch-all is detached — which there is no code for. The catch-all partition will accumulate all future data in one unpartitioned bucket.No partition pruning validation: there are no metrics or checks confirming that query plans actually use partition pruning.
Proposed changes
SET lock_timeoutbefore partition DDL to cap wait time.Priority
Medium — partition DDL is infrequent but each occurrence is a deploy-time risk. The catch-all accumulation is a slow-burn correctness issue.