Skip to content

Commit 106d20a

Browse files
authored
Truncate stale logging entries (older than 2025-11-06) (#76)
Migration 003 cleared `logging` for entries older than 2024-01-01. The DB has since grown to 17GB on the production instance, dominated by build-log text. Anything older than ~6 months is unlikely to be inspected and the retained log costs disk space + read cost on any query that reads full row payloads (the latter mostly fixed by 005's covering index, but disk space and table scans elsewhere still benefit). The cutoff (20251106000000) is fixed and approximately 6 months before the current development date. This UPDATE doesn't shrink the DB file. Freed page space is reused by future inserts; to actually reclaim disk space, run VACUUM in a maintenance window after this migration is deployed (it cannot run inside the migration's transaction). Verified locally: rows with build_dt before the cutoff have their logging text replaced; newer rows untouched.
1 parent 783ff4c commit 106d20a

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--------------------------------------------------------------------------------
2+
-- Up
3+
--------------------------------------------------------------------------------
4+
5+
-- Migration 003 cleared `logging` for entries older than 2024-01-01. Since
6+
-- then the DB has grown to ~17GB, dominated by the `logging` text column on
7+
-- `latest` rows. Anything older than ~6 months is unlikely to be inspected
8+
-- and the build log retained for it costs disk and per-row read cost
9+
-- (the latter mostly fixed by the covering index in 005, but the disk space
10+
-- and table scans elsewhere still benefit).
11+
--
12+
-- The cutoff is fixed; build_dt format is YYYYMMDDHHMMSS local time.
13+
--
14+
-- Note: this UPDATE doesn't shrink the DB file. Freed page bytes are reused
15+
-- by future inserts; to reclaim disk space, run VACUUM in a maintenance
16+
-- window after this migration is deployed (it's not part of the migration
17+
-- because VACUUM cannot run inside the migration's transaction).
18+
19+
UPDATE latest
20+
SET logging = 'Log eliminated due to age'
21+
WHERE build_dt < 20251106000000
22+
AND logging IS NOT NULL
23+
AND logging != 'Log eliminated due to age';
24+
25+
--------------------------------------------------------------------------------
26+
-- Down
27+
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)