Open Postgres Checkpointer
A drop-in LangGraph PostgreSQL checkpointer that cuts disk usage 4×–12.5× using flat zstd patches, lock-free pooled concurrency, optimistic thread fencing, and production lifecycle primitives — on upstream's own tables.
Documentation · Why & How It Works · Quickstart · Benchmarks · Changelog
Status:
1.0.0is stable. Tested against upstream'slanggraph-checkpoint-conformancesuite. Please report bugs or edge cases in GitHub Issues.
Why Open Postgres Checkpointer?
Upstream's langgraph-checkpoint-postgres rewrites every changed channel value in full at every step (causing O(N²) disk and WAL growth on growing chat/agent state), serializes all traffic behind a single saver-wide asyncio.Lock, lets concurrent runs on one thread silently fork history, refuses to prune DeltaChannel threads, and omits operational primitives like thread listing and idle-thread expiry.
Open Postgres Checkpointer implements LangGraph's BaseCheckpointSaver directly on upstream's existing four tables — adopting existing databases in place with no data migration:
| Capability | langgraph-checkpoint-postgres |
open-postgres-checkpointer |
|---|---|---|
| Disk on plain graphs | O(N²) full rewrites every step | 4.0×–12.5× smaller via flat zstd-prefix patches (no graph changes) |
| Concurrency | Single saver-wide asyncio.Lock |
Lock-free connection pool + single-statement atomic put / put_writes (1.5×–1.7× turns/s) |
| Racing writers on one thread | Silently forks history | Optimistic fence raises ThreadConflictError |
| Retention & pruning | Refuses DeltaChannel threads |
aprune / prune works on DeltaChannel, plus keep_last=N thinning and adelete_for_runs |
| Thread operations | Manual SQL | Indexed alist_threads / list_threads, acopy_thread, and idle-thread asweep_expired |
| Adoption & rollback | — | Reads all upstream rows in place; full_copies_only=True rollout; online rollback via opc-rehydrate |
For turn-by-turn diagrams of how upstream stores checkpoints and how each optimization works, see Why & How It Works.
Installation
pip install "open-postgres-checkpointer[binary]"
Or with uv:
uv add "open-postgres-checkpointer[binary]"
[binary]installs psycopg's bundledlibpq. If your environment already provides PostgreSQL'slibpq, you can install bareopen-postgres-checkpointer(or[c]for psycopg's C extension). Importing without alibpqbackend raisesImportError: no pq wrapper available.
Quickstart
Async (recommended)
from open_postgres_checkpointer import AsyncOpenPostgresCheckpointer
async with AsyncOpenPostgresCheckpointer.from_conn_string(DB_URI) as saver:
await saver.setup() # once, from one process
graph = builder.compile(checkpointer=saver)
result = await graph.ainvoke(inputs, {"configurable": {"thread_id": "t1"}})
To own the checkpointer pool's lifecycle yourself (for example in a FastAPI lifespan or across multiple savers), use async with open_pool(DB_URI) as pool, AsyncOpenPostgresCheckpointer(pool) as saver:; open_pool applies the same defaults (see In a web service). Any psycopg_pool.AsyncConnectionPool configured with kwargs={"autocommit": True} works too. Upstream's single-connection and pipe constructors are not supported.
Sync
For code without an event loop of its own, OpenPostgresCheckpointer provides the same behavior over a private background loop thread:
from open_postgres_checkpointer import OpenPostgresCheckpointer
with OpenPostgresCheckpointer.from_conn_string(DB_URI) as saver:
saver.setup() # once, from one process
graph = builder.compile(checkpointer=saver)
result = graph.invoke(inputs, {"configurable": {"thread_id": "t1"}})
Production Primitives
List threads (indexed, metadata-filtered, cursor-paged)
from open_postgres_checkpointer import alist_threads
page = [t async for t in alist_threads(saver, filter={"user_id": "u1"}, limit=20)]
next_page = [
t
async for t in alist_threads(
saver, filter={"user_id": "u1"}, before=page[-1].config, limit=20
)
]
(Sync callers use list_threads(saver, ...).)
Retention, thinning, and idle-thread expiry
from datetime import timedelta
# Thin history: keep the last 10 checkpoints per namespace + each run's final checkpoint
await saver.aprune(["t1", "t2"], keep_last=10)
# Delete threads idle for more than 30 days (safe alongside live runs)
report = await saver.asweep_expired(timedelta(days=30), max_threads=100)
# Remove checkpoints belonging to specific runs, or clone a thread for branching/replay
await saver.adelete_for_runs(["run-123"])
await saver.acopy_thread("t1", "t1-fork")
Optimistic concurrency fence
Every read mints a lightweight generation token carried through LangGraph's configurable dict. If two runs race on the same thread, the stale writer is refused with ThreadConflictError instead of silently overwriting or forking history:
from open_postgres_checkpointer import ThreadConflictError
try:
await graph.ainvoke(inputs, config)
except ThreadConflictError:
# Reload latest state or surface a conflict to the caller
...
How Patch Storage Works
Changed channel values ≥ 1 KiB are compressed as a flat zstd-prefix patch against an earlier full copy (the base) stored in upstream's checkpoint_blobs table. Every base is a full copy — never a patch — so reads apply at most one patch regardless of thread length:
checkpoint_blobs
v1 (base) ──► opc:zstd:msgpack (compressed full copy + zstd checksum)
v2 (patch) ──► opc:zstd-patch:msgpack (small delta against v1; 1 hop to decode)
v3 (patch) ──► opc:zstd-patch:msgpack (small delta against v1; still 1 hop)
vN (new) ──► opc:zstd:msgpack (new base once patch > 25% of base size)
- Wire-skip warm reads: An in-memory LRU
BaseCache(64 MiB default) caches base bytes andZstdDictprefixes so warm reads skip re-fetching the base blob over the wire. - Database-enforced integrity: A
DEFERRABLE INITIALLY DEFERREDforeign key inopc_blob_patchprevents orphaned patches, and zstd content checksums verify every decoded frame. - Off the event loop: All serialization, compression, and decoding run on a dedicated single codec thread per saver.
Benchmarks
Measured before the first release on an uncontended benchmark host with PostgreSQL 16 and 8 pool connections per arm. Disk is bytes above each arm's empty schema after VACUUM, including our side tables and indexes. Ratios are against upstream's AsyncPostgresSaver:
| Workload | Disk vs. upstream | put p50 vs. upstream |
|---|---|---|
| 400-step chat, plain graph | 6.9× smaller | 0.41× |
400-step chat, DeltaChannel graph |
0.95× | 0.65× |
| Agent thread growing to 1 / 3 / 10 MB, plain graph | 4.0× / 5.7× / 12.5× smaller | 0.43× / 0.34× / 0.15× |
Agent thread growing to 1 / 3 / 10 MB, DeltaChannel graph |
1.06× / 0.93× / 0.84× | 1.39× / 1.81× / 1.76× (cold pool) |
| 8 / 32 concurrent threads, plain graph | — | 0.53× / 0.47× (1.7× / 1.6× turns/s) |
8 / 32 concurrent threads, DeltaChannel graph |
— | 0.21× / 0.21× (1.5× / 1.5× turns/s) |
Note on the cold-pool
DeltaChannelcells: Bold cells exceed the acceptance bars (DeltaChanneldisk ≤ 1.05×,putp50 ≤ 1.25×) on a brand-new connection pool because the largerputstatement (which also maintainsopc_thread_headand the listing index) costs more to plan on first execution (analysis). On a warm long-lived pool, the sameDeltaChannelputs measure 0.72×–1.16× upstream (ADR-0030).
Reproduce locally with benchmarks/README.md:
just bench-case smoke # quick setup check
just bench-case four-arm # 400-step chat + concurrent arms
just bench-case large # 1 / 3 / 10 MB agent threads
Safe Rollout & Rollback
- Adopt in place: Open Postgres Checkpointer reads every row upstream wrote. Once a patch is stored on a thread, upstream's saver cannot read that thread and raises loudly rather than returning partial state.
- Zero-downtime rollout: Deploy initially with
full_copies_only=Truewhile upstream replicas are still running, then enable patching once all replicas run this saver (Adopting the saver). - Online rollback:
opc-rehydraterewrites every patch and compressed row back to plain upstream format in resumable, memory-bounded batches while savers keep running:
# Authenticate via PG* environment variables or .pgpass (avoids credentials in process args)
opc-rehydrate --dry-run # estimate row counts and disk needed
opc-rehydrate # or: python -m open_postgres_checkpointer.rehydrate
An explicit libpq connection string argument is also accepted (opc-rehydrate "$DB_URI"). See Rolling back for the full procedure and dropping our side tables.
Supported Versions
| Component | Supported |
|---|---|
| Python | 3.11, 3.12, 3.13, 3.14 (compression.zstd stdlib on 3.14+; backports.zstd before) |
| PostgreSQL | 15, 16 (required weekly matrix); 17, 18 tested weekly |
langgraph-checkpoint |
>=4.3.1, <5 |
langgraph-checkpoint-postgres schema |
3.2.0 (vendored migrations; not a runtime dependency) |
psycopg / psycopg-pool |
>=3.3.6 / >=3.2 |
Documentation
- Why & How It Works — turn-by-turn diagrams, patch design, and optimization breakdown
- Quickstart — installation, async/sync usage, and thread listing
- Adopting the Saver — rolling deploys, storage format, advisory locks, and known limits
- Rolling Back —
opc-rehydrateand removing side tables - Architecture, Compatibility Promise, ADRs, and Design Notes
Development
This project uses uv and just (plus a Dev Container):
just install # sync all dependency groups + install pre-commit hooks
just check # lint, fmt-check, typecheck, and unit tests
just test-int # integration + upstream conformance suite (needs Docker)
just docs # strict MkDocs build
See CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
License & Attribution
Licensed under the Apache License, Version 2.0 — see NOTICE and THIRD_PARTY_NOTICES.md for attribution and vendored upstream schema migrations.
PostgreSQL and Postgres are registered trademarks of the PostgreSQL Community Association of Canada (PGCAC). LangGraph and LangChain are trademarks of LangChain, Inc. Open Postgres Checkpointer is an independent open-source project and is not affiliated with, endorsed by, or sponsored by the PostgreSQL Global Development Group, PGCAC, or LangChain, Inc.
Metadata
Release files for open-postgres-checkpointer 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| open_postgres_checkpointer-1.0.0.tar.gz | 81.7 kB | With provenance | Details for open_postgres_checkpointer-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| open_postgres_checkpointer-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for open_postgres_checkpointer-1.0.0-py3-none-any.whl |
Total release size: 166.0 kB
Release files / open_postgres_checkpointer-1.0.0.tar.gz
| Download URL | open_postgres_checkpointer-1.0.0.tar.gz |
|---|---|
| Size | 81.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f552597f551efc95fd2df0f142c28d106b88e661f02772f5e247fa92917eb7f6
|
|
BLAKE2b-256 checksum How to use checksums |
e4b5315374b9bb3b3d178ce4f9c39f88bed2c502e798da6eb22c0624c49a1248
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logRelease files / open_postgres_checkpointer-1.0.0-py3-none-any.whl
| Download URL | open_postgres_checkpointer-1.0.0-py3-none-any.whl |
|---|---|
| Size | 84.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab4ad35e90aa768c3bb9b431d00636b4ebf5e022e16692fcf345087739d44207
|
|
BLAKE2b-256 checksum How to use checksums |
130540063895280d91a7aaa16197328dc20de697ae69eab8af0dee70b0120ccc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logSecurity for open-postgres-checkpointer 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for open_postgres_checkpointer-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.