LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraph-checkpoint-postgresindexPostgresSaver
Class●Since v0.0

PostgresSaver

Copy
class PostgresSaver

Bases

BaseCheckpointSaver

Used in Docs

  • Short-term memory

Constructors

Properties

Methods

View source on GitHub

Example

constructor
constructor
property
isSetup: boolean
property
serde: SerializerProtocol
method
_dumpBlobs
method
_dumpCheckpoint
method
_dumpMetadata
method
_dumpWrites
method
_loadBlobs
method
_loadCheckpoint
method
_loadMetadata
method
_loadWrites
method
_searchWhere
method
deleteThread→ Promise<void>
method
end→ Promise<void>
method
get→ Promise<Checkpoint<string, string> | undefined>
method
getDeltaChannelHistory→ Promise<Record<string, DeltaChannelHistory>>
method
getNextVersion→ number
method
getTuple→ Promise<CheckpointTuple | undefined>
method
list→ AsyncGenerator<CheckpointTuple>
method
put→ Promise<RunnableConfig<Record<string, any>>>
method
putWrites→ Promise<void>
method
setup→ Promise<void>
method
toJSON→ string
method
fromConnString→ PostgresSaver

LangGraph checkpointer that uses a Postgres instance as the backing store. Uses the node-postgres package internally to connect to a Postgres instance.

Delete all checkpoints and writes associated with a specific thread ID.

Walk the parent chain returning per-channel writes + seed, used to reconstruct DeltaChannel state from checkpoint_writes.

For each requested channel, walks ancestors of the checkpoint identified by config (following parentConfig) and accumulates the pending writes for that channel. The walk terminates per-channel at the nearest ancestor whose channel_values[ch] is populated; that value is returned as seed. If the walk reaches the root without finding a stored value, seed is omitted from that channel's entry — the consumer treats the absence as "start empty".

Walks the parent chain (not list({ before })): for forked threads, only on-path ancestors contribute.

The default implementation walks getTuple + parentConfig once for all channels — each ancestor visited once, not once per channel. Savers with direct storage access (e.g. MemorySaver) override for performance; the return contract is fixed here.

Generate the next version ID for a channel.

Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions, as long as they are monotonically increasing.

Get a checkpoint tuple from the database. This method retrieves a checkpoint tuple from the Postgres database based on the provided config. If the config's configurable field contains a "checkpoint_id" key, the checkpoint with the matching thread_id and namespace is retrieved. Otherwise, the latest checkpoint for the given thread_id is retrieved.

List checkpoints from the database.

This method retrieves a list of checkpoint tuples from the Postgres database based on the provided config. The checkpoints are ordered by checkpoint ID in descending order (newest first).

Save a checkpoint to the database.

This method saves a checkpoint to the Postgres database. The checkpoint is associated with the provided config and its parent config (if any).

Store intermediate writes linked to a checkpoint.

This method saves intermediate writes associated with a checkpoint to the Postgres database.

Set up the checkpoint database asynchronously.

This method creates the necessary tables in the Postgres database if they don't already exist and runs database migrations. It MUST be called directly by the user the first time checkpointer is used.

Prevent JSON.stringify from traversing backend clients (e.g. pg Pool timers) when a checkpointer is present in runnable configurable.

Creates a new instance of PostgresSaver from a connection string.

Copy
import { ChatOpenAI } from "@langchain/openai";
import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const checkpointer = PostgresSaver.fromConnString(
  "postgresql://user:password@localhost:5432/db",
  // optional configuration object
  {
    schema: "custom_schema" // defaults to "public"
  }
);

// NOTE: you need to call .setup() the first time you're using your checkpointer
await checkpointer.setup();

const graph = createReactAgent({
  tools: [getWeather],
  llm: new ChatOpenAI({
    model: "gpt-4o-mini",
  }),
  checkpointSaver: checkpointer,
});
const config = { configurable: { thread_id: "1" } };

await graph.invoke({
  messages: [{
    role: "user",
    content: "what's the weather in sf"
  }],
}, config);