Skip to content

Fix silent cleanup failure that filled the DB disk - #1

Open
digitalhen wants to merge 1 commit into
mainfrom
fix/cleanup-resilience-and-ml-ownership
Open

Fix silent cleanup failure that filled the DB disk#1
digitalhen wants to merge 1 commit into
mainfrom
fix/cleanup-resilience-and-ml-ownership

Conversation

@digitalhen

Copy link
Copy Markdown
Owner

What broke

The subway DB on supermac grew to 87 GB and filled the disk on June 12, crash-looping Postgres into recovery mode.

Root cause: the nightly cleanup (capture/cron/daily_stats.py::cleanup_db) ran db/cleanup_old_data.sql in a single transaction. That script ends with drop_chunks('route_station_5min_stats', …). TimescaleDB chunk ops are gated on table ownership, not GRANTs — and the ML feature tables (route_station_5min_stats, alerts_unique) were created by a superuser via peer auth, so as subway that drop_chunks raised must be owner of hypertable. The error rolled back the realtime drop_chunks earlier in the same transaction, so the firehose was never pruned. 16 days of stop_time_updates (~69 GB) piled up → disk full → crash.

Logged nightly since May 30 as FAILED computing <day>: must be owner of hypertable "route_station_5min_stats". The earlier 8ee59e9 GRANT-only fix didn't help because ownership ≠ privileges.

Changes

  • cleanup_db: run each statement in its own transaction (autocommit), log + continue on failure. A late drop_chunks error can no longer undo the earlier, critical realtime drops.
  • Migration: ALTER TABLE … OWNER TO subway for both ML tables so ownership is deterministic regardless of who applies it.

Prod already remediated (by hand)

  • ALTER TABLE … OWNER TO subway applied on supermac.
  • Backfilled the missing June 11 & June 12 rollups (daily/hourly/alerts_unique/route_5min) from firehose still on disk.
  • Ran cleanup as subway (verified the fix): 87 GB → 722 MB, disk 88% → 43% (after thinning the APFS local snapshots that were pinning the freed blocks).

🤖 Generated with Claude Code

The nightly cleanup ran cleanup_old_data.sql in a single transaction. Its
last drop_chunks targets route_station_5min_stats, and TimescaleDB chunk
ops are gated on table OWNERSHIP — not GRANTs. The ML feature tables had
been created by a superuser (peer auth on supermac), so as `subway` that
drop_chunks raised "must be owner of hypertable". Because everything ran
in one transaction, the error rolled back the realtime drop_chunks too, so
the firehose was never pruned: 16 days of stop_time_updates (~69 GB)
accumulated, filled supermac's disk, and crash-looped Postgres (June 2026).

- cleanup_db: run each statement in its own transaction (autocommit) and
  log+continue on failure, so a late drop_chunks error can't undo the
  earlier, critical realtime drops.
- migration: ALTER TABLE ... OWNER TO subway for alerts_unique and
  route_station_5min_stats, so ownership is deterministic regardless of who
  applies it (the prior GRANT-only fix in 8ee59e9 was insufficient).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@digitalhen
digitalhen force-pushed the fix/cleanup-resilience-and-ml-ownership branch from 69f0a3a to e781343 Compare July 23, 2026 03:25
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