Repository navigation
Releases
Releases · datastone-inc/pg_repack_safe
pg_repack_safe 1.0.0
Added
- The
pg_repack_safeextension and library for PostgreSQL 19, built with
PGXS. The library is loaded throughshared_preload_librarieson the
primary and on every standby, and installsobject_access,
ProcessUtilityandExecutorStarthooks, each chained to the previous
one. - The reader guard. A read of a table whose snapshot does not see a
committedREPACK (CONCURRENTLY)of that table fails with SQLSTATE
40001,cannot read table "..." with this snapshot, instead of reading
the table as empty. It covers every query through the executor (views,
functions, cursors, parallel plans, partitions, the TOAST table), the
reads anUPDATEorDELETEmakes to find its rows,COPY ... TO,
pg_dumpand logical replication's initial table copy, on the primary
and on hot standbys. AnINSERT's target table is not checked unless it
has a foreign key to itself, and a table the plan names but does not
read is not checked. A read without an MVCC snapshot of a table that has
a record is refused. Each backend keeps a copy of the records, reloaded
whenREPACK (CONCURRENTLY)invalidates it. COPY partitioned_table TOruns asCOPY (SELECT columns FROM partitioned_table) TO, so that a partition attached during theCOPYis
checked too. The output is the same; a partition that is a foreign table
is read where stock PostgreSQL raises an error, and the statement is
about 5% slower.- The record table
repack_safe.rewrites.REPACK (CONCURRENTLY)of a
table whose storage has blocks records the table and its TOAST table,
with the rewriting transaction's full ID (xid8), and deletes every
older record.repack_safe.prune_records()deletes them on request. A
deleted record still protects untilVACUUMfinds that no snapshot can
need it; on a hot standby, replaying its removal ends the snapshots that
still do. REPACK (CONCURRENTLY)is refused when the library was not loaded
throughshared_preload_libraries, in a database without the extension,
and when the record table is missing or does not have the definition the
extension created. Every query in a database whose record table is
missing, or has lost its definition or one of its two triggers, is
refused, except in binary-upgrade mode and in the session running
CREATE EXTENSION.- The record table is protected.
INSERT(by any route, logical
replication included),UPDATEandDELETEof records, an index, a
column change, a rewrite that does not keep every record and a change to
when its triggers fire are always refused (SQLSTATE 0A000). While it
holds records,DROPof the table, its triggers or the extension,
TRUNCATE, renaming the table and moving it to another schema are
refused unless a superuser setspg_repack_safe.allow_unprotected_removal
(SQLSTATE 55000).VACUUM FULL,CLUSTERandREPACKof it are refused
while it holds a deleted record. - The fixed schema
repack_safe. The extension cannot be created in or
moved to another schema. A schemarepack_safethat already exists is
used only if a superuser owns it. The extension requiresplpgsql. - Settings:
pg_repack_safe.precheck_snapshot_age(superuser, off by
default) makesREPACK (CONCURRENTLY)refuse to run, at its start and at
its swap, while a session in the database holds an old snapshot that
could later read the table;pg_repack_safe.allow_unprotected_removal
(superuser) lifts the removal refusals above;
pg_repack_safe.trace_storage_changes(superuser) reports each replaced
table storage as aNOTICE. repack_safe.status()returns true where the guard is in force, and
false with aWARNINGwhere the server did not load the library through
shared_preload_libraries. A session that loads the library later gets
the sameWARNING, which namessession_preload_librariesor
local_preload_librarieswhen the library is listed there.\dxshows
the check in the extension's comment.- A custom WAL resource manager (ID 149): each
REPACK (CONCURRENTLY)
writes a record before its commit, so a server that replays the WAL
without the library stops instead of serving the repacked table to old
snapshots. - The library's version,
1.0.0, shown bypg_get_loaded_modules()and
logged by the postmaster at start; the extension's version is1.0. The
primary and its standbys need the same major version of the library; an
upgrade installs the new build on the standbys first. - Logical replication: the records
REPACK (CONCURRENTLY)writes are not
sent to subscribers. A new subscription's initial copy reads the records
already there, which a subscriber with the extension refuses until the
record table is excluded from the publication (doc/installation.md,
"Logical Replication"). pg_upgradecarries the records over;pg_dumpleaves them behind.demo/demo.sh: a report, anUPDATE, aDELETEand apg_dumpon a
throwaway server, without and then with the extension.- Packaging:
META.jsonfor PGXN,make dist, andmake check-version.
make installcheckruns 8 regression, 9 isolation and 22 TAP files on
temporary servers, with test-only modules loaded from the build tree. - Documentation: the README, and in
doc/the problem in detail
(problem.md), installation and settings (installation.md), the design
argument (design.md), limits (limits.md), standby errors
(standbys.md), removal (removal.md) and development
(development.md).
Known gaps
Each is described in doc/limits.md:
- Functions of
pgrowlocksandamcheckread a table outside the executor
and return a wrong answer, with no error, to an old snapshot. - A foreign-key check against a repacked table from an old snapshot fails
with 23503, not 40001. - A standby without the library whose replay starts between a repack's
swap and its commit is not stopped.