Add pg_repack, so bloated tables can be rewritten without downtime - #5
Merged
Merged
Conversation
The meta dedup deleted 206,838,911 rows from meta and a similar number from track_meta. Deletes do not return space: meta is still a 62 GB heap holding 180.6M rows, with roughly 50 GB of hole in it and another 25 GB in track_meta. Autovacuum will not recover it either -- plain VACUUM only truncates free space at the physical end of a table, and meta's tail is the native-gid era where every row survived, so there is nothing there to truncate. That leaves VACUUM FULL, which holds an ACCESS EXCLUSIVE lock for the entire rewrite. On a 97 GB table that is half an hour or more with metadata lookups failing, which is not a thing to do to a live service to recover disk that is merely untidy rather than scarce. pg_repack does the same rewrite online, taking brief locks only at the start and end. Installed from PGDG as postgresql-$PG_MAJOR-repack, next to wal2json, which brings both the extension and the client binary; the binary lands in /usr/lib/postgresql/$PG_MAJOR/bin, already on PATH in this image. Verified postgresql-18-repack 1.5.3-1 exists in PGDG for both bookworm and trixie, so this does not depend on which suite the base image tracks. The extension still has to be created per database before use.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Why
The meta dedup deleted 206,838,911 rows from
metaand a similar number fromtrack_meta. Deletes do not return space to the filesystem, sometais still a 62 GB heap holding 180.6M rows — roughly 50 GB of hole, plus another 25 GB intrack_meta.Autovacuum will not recover it. Plain
VACUUMonly truncates free space at the physical end of a table, andmeta's tail is the native-gid era where every row survived the merge, so there is nothing there to truncate. Observed directly: four autovacuum cycles ran onmetaduring the merge and the heap sat at 62 GB through all of them.That leaves
VACUUM FULL, which holdsACCESS EXCLUSIVEfor the entire rewrite — half an hour or more on a 97 GB table, with metadata lookups failing throughout. Not something to do to a live service to recover disk that is untidy rather than scarce.pg_repackperforms the same rewrite online, taking brief locks only at the start and end.What
One line in the runtime stage, installed from PGDG next to
wal2json:Built from source would have matched
pg_acoustid, but the package ships both the extension and the client binary and tracks the PG major automatically, so there is nothing to pin or rebuild on the next upgrade.Verified
postgresql-18-repack1.5.3-1 exists in PGDG for both bookworm and trixie, so this does not depend on which suite the base image tracks.Checked by running the built image rather than trusting a green build:
Client and extension are both 1.5.3 —
pg_repackrefuses to run if they differ, so that is the check that matters.Deploying
Adds a package to the runtime image; no change to how the image starts or behaves. The
pg-*StatefulSets are pets withOnDelete, so picking this up means deleting pods one at a time — replicas first, then a Patroni switchover before the leader.CREATE EXTENSION pg_repackis still needed per database before use.Note
The commit message says the binary lands in
/usr/lib/postgresql/$PG_MAJOR/bin. It is actually/usr/bin/pg_repack. Both are on PATH, so behaviour is unaffected, but the message is wrong on that detail.