Rolling back
How to return a database to upstream's langgraph-checkpoint-postgres saver. Adopting it is
Adopting the saver.
Before patches were turned on
If every saver of ours has run with full_copies_only=True, every row it wrote is upstream's.
Deploy upstream's saver; nothing needs rewriting. Our tables stay until you drop them (below).
After patches were turned on: rehydrate
rehydrate rewrites every patch, every compressed full copy and every compressed pending write
as the row upstream's saver would have written, and deletes the side rows naming them.
- Size it. A dry run changes nothing and prints a
RehydrateReport: the rows it would rewrite (patches,full_copies,writes), the bytes they take now (stored_bytes) and the bytes they take as upstream's rows (rewritten_bytes, the figure to check against free disk). Plain rows can need several times the disk: about 7× on the 400-step benchmark thread (ADR-0010).
# Authenticate via PG* environment variables or .pgpass (avoids credentials in process args)
opc-rehydrate --dry-run
# or: python -m open_postgres_checkpointer.rehydrate --dry-run
# (an explicit CONNINFO argument is also accepted: opc-rehydrate "$DB_URI" --dry-run)
- Run it. Savers of ours may keep running.
rehydratefirst sets the patching-off switch (a row inopc_patching_off), which each saver of ours sees on its nextputand from then on writes only upstream's rows. It waits until every transaction that started before the switch has ended (a session left idle in a transaction holds it there; every 10 seconds of waiting it logs a warning naming each such session's pid andapplication_name), then rewrites rows in batches of at most--batch-bytesdecoded bytes (64 MiB by default). That bounds a batch's values, not the process: while a batch is sent the values are held about three times over (estimated from the copies the code makes), so size--batch-bytesat about a third of the memory the job may use. Each batch is one statement, so an interrupted run leaves every row readable; run it again to continue. It raisesCheckpointerErrorif a row of ours is left at the end.
opc-rehydrate
From Python (API reference):
from open_postgres_checkpointer.rehydrate import rehydrate
report = await rehydrate(DB_URI)
- Deploy upstream's saver. It reads every thread again. The switch stays set, so patching cannot be turned back on for this database.
Dropping our tables
Once no saver of ours runs, our tables can go. A saver of ours in any mode still writes thread head rows, so drop them only after the last one stops:
DROP INDEX CONCURRENTLY IF EXISTS opc_checkpoints_root_latest;
DROP TABLE IF EXISTS opc_blob_patch, opc_thread_head, opc_patching_off, opc_migrations;
DROP SEQUENCE IF EXISTS opc_head_seq;
Upstream's saver never reads these, so leaving them costs only their disk; the index on
checkpoints also costs a little on each root put until it is dropped.