New Tool Radar

AI Agents & Automation

How to Use a Postgres Checkpointer for a LangGraph Graph in Production

Swap a LangGraph MemorySaver checkpointer for a Postgres checkpointer so graph state survives restarts and works across workers.

Schematic diagram with three steps: Create the checkpoint tables, Swap the checkpointer, then Test a restart.

MemorySaver is fine for local development, but its checkpoints vanish when the process restarts, which breaks any approval wait of hours. For production, LangGraph offers a Postgres checkpointer that stores the same checkpoints in a database, so state survives restarts and works across workers.

Before you start

You need a LangGraph graph already working with MemorySaver and a Postgres database the app can reach. Keep the database credentials private and do not put them in the graph code.

Create the checkpoint tables and swap the checkpointer

Install the Postgres checkpoint package and create a PostgresSaver from your connection string, then call its setup method, which creates the checkpoints, checkpoint_writes and checkpoint_blobs tables. Compile the graph with the Postgres checkpointer instead of MemorySaver, without changing any graph code.

Test that state survives a restart

Start a run with a thread_id, pause it at an interrupt, then restart the app process and resume the same thread. Check the resumed run continues from the saved state. If it starts over, the checkpointer is not connected to the same database.

Worked example: Checkpointer swap for a fictional shop agent

Maple Shop is a fictional online shop. Its refund graph moves from MemorySaver to Postgres. The table compares the two.

Checkpointer Survives restart? Works across workers?
MemorySaver No No
PostgresSaver Yes Yes

Expected result (UNTESTED): the refund run pauses, the app restarts, and the same thread resumes and completes the refund once. We checked the LangGraph human-in-the-loop guide, which shows the PostgresSaver swap and the setup call, but we did not run the swap on this machine.

Limits

A Postgres checkpointer needs a database to manage and back up, and every state update becomes a database write. For a single-process prototype, SQLite is a lighter persistent option. Keep the connection string out of version control.

Sources

See all