The idea · Lab 3.7.4pg_repack reclaims bloated table space online: it builds a shadow copy of the table while the original stays fully readable and writable, replays every intervening change via a trigger, and finishes with a sub-second relfilenode swap. It is genuinely absent on this server — no network to install its binary, no compiler to build it from source — the same confirmed-absent pattern as PostGIS and wal2json elsewhere in this block.
What pg_repack exists specifically to avoid is demonstrated directly instead: an AccessExclusiveLock, the exact lock class VACUUM FULL takes for its entire duration, genuinely blocks a concurrent reader for the full time it is held — confirmed here with a real, observable wait_event in pg_stat_activity, not just described. A real VACUUM FULL is then run separately, and the real disk space it reclaims is measured directly.
pg_repack, Checked Directly
which pg_repack 2>&1; find / -iname '*pg_repack*' 2>/dev/null # genuinely empty
Confirmed absent — no network access to install its binary, no compiler to build it from source. Conceptually, it works by building a shadow copy of the table live, replaying every change with a trigger, then doing a sub-second relfilenode swap — never holding a long lock the way VACUUM FULL does.
The Real Lock, Demonstrated Directly
-- Session A:
BEGIN; LOCK TABLE orders_demo IN ACCESS EXCLUSIVE MODE; -- held for a real 5 seconds
-- Session B, started right after:
SELECT count(*) FROM orders_demo; -- genuinely does not return until Session A commits
Checked directly from a third session while B is waiting:
pid | state | wait_event_type | wait_event
-----+--------+------------------+------------
147 | active | Lock | relation
This is the exact lock class VACUUM FULL (and a bare table rewrite like ALTER TABLE ... TYPE) takes for its entire real duration — every reader and writer genuinely blocked, not just writers.
A Real VACUUM FULL, Measured Directly
SELECT pg_size_pretty(pg_total_relation_size('orders_demo')); -- 22 MB, mostly real bloat
VACUUM FULL orders_demo;
SELECT pg_size_pretty(pg_total_relation_size('orders_demo')); -- 2232 kB, genuinely reclaimed
A real, substantial reclaim — but for the entire duration of that rewrite, the table was held under the exact AccessExclusiveLock just demonstrated.
Key concepts
AccessExclusiveLock
The strongest lock mode PostgreSQL has — it genuinely conflicts with every other lock mode, meaning every concurrent reader and writer is blocked for as long as it is held. VACUUM FULL, TRUNCATE, and several forms of ALTER TABLE all take this lock; confirmed directly in this lab via a real, observable wait_event_type of Lock and wait_event of relation on a genuinely blocked session.
pg_repack's shadow-table mechanism (conceptual)
Since pg_repack is confirmed absent and cannot be run directly on this VM, its mechanism is understood conceptually: it creates a new, empty copy of the table, copies existing rows into it while the original stays fully live, uses a trigger to capture and replay any concurrent changes, and finishes with a very brief schema-level lock only for the final relfilenode swap — genuinely avoiding the long AccessExclusiveLock hold that VACUUM FULL requires for its entire duration.
What to remember
- pg_repack (like PostGIS and wal2json elsewhere in this block) is confirmed absent on this server — checked directly rather than assumed
- AccessExclusiveLock genuinely conflicts with every other lock mode — a concurrent reader is blocked for the lock's entire real hold duration, confirmed directly via a real wait_event
- VACUUM FULL takes exactly this lock class for its entire rewrite duration — on a real production-sized table that duration can be hours, with every reader and writer blocked the whole time
- pg_repack's real mechanism (shadow table + trigger-replayed changes + brief final swap) exists specifically to avoid this long lock, understood conceptually here since it cannot be run directly
- VACUUM FULL genuinely reclaims the same real disk space pg_repack would — the real difference between them is entirely in how long the table stays inaccessible while it happens