Agent memory on PostgreSQL and Redis: how to run it in production
Long-term memory in PostgreSQL and short-term memory in Redis or Valkey, run in OSStend's cloud, your cloud account or your data center.
45 minutes with an engineer: we review your workload and sketch the design.
Agent memory is the state an agent keeps between steps and between sessions. Short-term memory holds the current conversation and fits an in-memory store such as Redis or Valkey. Long-term memory holds facts, summaries and checkpoints and fits PostgreSQL, with pgvector for recall by meaning.
- PostgreSQL
- MySQL
- MongoDB
- Redis
- Valkey
- OpenSearch
- Kafka
- RabbitMQ
- AWS
- Google Cloud
- Azure
- Kubernetes
- OpenShift
- Prometheus
- Grafana
- Datadog
- Dynatrace
- Splunk
What goes wrong when agent memory reaches production
In a demo, memory is a Python list. In production it must survive restarts, serve many users at once, forget on request and stay inside your data boundary, and each of those is a data-engineering problem.
- State is lost on restart.
- In-process memory disappears when the process does, so long-running agents need a durable checkpoint store.
- Memory grows without a limit.
- Every conversation adds facts, summaries and embeddings, so retention and pruning need a policy.
- One user's memory reaching another.
- Memory must be scoped per user or tenant, in the data model and in the vector index.
- Personal data.
- Memory holds what users said and what the agent inferred. Erasure requests and retention limits apply to it.
- Latency in the loop.
- An agent reads memory many times per task, so slow lookups slow every step.
The memory pattern: short-term in memory, long-term in PostgreSQL
Split memory by lifetime. Redis or Valkey holds session state that expires, and PostgreSQL holds what must last: checkpoints, facts and vectors for recall by meaning. The split keeps hot reads fast and durable data in a database with backups.
| Layer | What it holds | Engine | Why this engine |
|---|---|---|---|
| Short-term memory | Current conversation, scratch state, session context | Redis or Valkey | In-memory reads and keys that expire on their own |
| Checkpoints | Graph or workflow state saved at each step | PostgreSQL | Durable, transactional, restorable. LangGraph has a Postgres checkpoint saver |
| Long-term facts | User preferences, extracted facts, summaries | PostgreSQL | Relational tables with constraints and per-user scoping |
| Semantic recall | Embeddings of memories, searched by meaning | PostgreSQL with pgvector | Vectors beside the memory rows, same backup and access model |
| Repeat-question cache | Stored answers to similar questions | Redis or Valkey | See semantic caching |
Sources: LangGraph Postgres checkpointer, Mem0 pgvector, Letta self-hosting, checked 30 Oct 2026.
Common frameworks already target this layout. LangGraph's documentation provides a Postgres implementation of its checkpoint saver for durable, long-running agents. Mem0 lists pgvector among its supported vector stores. Letta's self-hosting guide says a Postgres database you connect yourself must have the pgvector extension installed. For what the model sees on each turn, and how memory feeds it, see context engineering. To let an agent query the same PostgreSQL safely, see the Postgres MCP server guide.
Sizing and tuning agent memory
Memory grows with the number of users, sessions and stored memories. Size the vector part like any pgvector workload, and set expiry and retention for the rest.
| Memory type | What drives growth | Lever |
|---|---|---|
| Checkpoints | Steps per run × runs × state size | Retention window on old checkpoints; prune completed threads on a schedule |
| Long-term facts | Users × facts per user | Per-user caps, summarisation, and deduplication of near-identical facts |
| Memory vectors | Memories × dimensions (4 × dimensions + 8 bytes each in `vector`) | `halfvec`, index choice and recall settings; see pgvector |
| Short-term sessions | Active sessions × context size | Key expiry (TTL) and a memory limit with an eviction policy |
| Multi-tenant isolation | Tenants sharing one index | List partitioning or separate tables, as the pgvector docs suggest |
Source: pgvector README, checked 30 Oct 2026. Retention figures are a policy decision for each organisation.
Retention and privacy for agent memory
Treat agent memory as personal data. Scope every row to a user or tenant, give it a retention period, and make deletion a tested path that reaches the vector index, the checkpoints and the backups.
- ✓Store a user or tenant identifier on every memory row and filter on it in every query.
- ✓Delete from the table and from derived data together: the memory row, its embedding and any summary built from it.
- ✓Set a retention window per memory type and enforce it with a scheduled job.
- ✓Keep the store inside your own environment so identity, keys and audit logs are yours. See deployment options.
- ✓Decide how long deleted data may remain in backups, and document it.
Pitfalls documented by the engines and frameworks
Most memory incidents come from scoping and growth rather than from the database itself. These items come from the engine and framework documentation.
- A shared approximate index across tenants
- lets one tenant's vectors affect another's recall and speed. Partition or use separate tables.
- Filtered recall.
- A user filter on an approximate index applies after the scan and can return fewer rows. Use iterative scans or partitioning.
- Unbounded checkpoints.
- A checkpoint saved at every step accumulates quickly for long runs. Retention has to be designed in.
- Cache and memory confusion.
- A cache may be evicted at any time. Anything the agent must remember belongs in the durable store.
What OSStend runs, where it runs and who it is not for
OSStend designs, moves and runs PostgreSQL and Redis or Valkey in its own cloud, in your cloud account or co-managed in your data center, so agent memory stays in your environment.
Contact us if
- ✓Agent memory holds customer data that must stay in your cloud account or data center.
- ✓You already run PostgreSQL or Redis and want memory in the same estate.
- ✓You use LangGraph, Mem0, Letta or a custom framework that can use Postgres.
Not a fit if
- ✕You want a hosted memory API and have no data-residency requirement.
- ✕The agent is a prototype with no retention or privacy requirements yet.
- ✕You need a managed agent framework. OSStend runs the data layer, not the agent.
FAQ
What is agent memory?
Agent memory is the state an AI agent keeps beyond a single model call. Short-term memory covers the current conversation, and long-term memory covers facts, summaries and past runs, often searched by meaning with embeddings.
Can PostgreSQL be used for agent memory?
Yes. LangGraph provides a Postgres checkpoint saver, Mem0 supports pgvector as a vector store, and Letta's self-hosted server uses Postgres with the pgvector extension. PostgreSQL gives durable storage, transactions and point-in-time recovery for memory.
Is agentic memory the same as agent memory?
The two terms are used interchangeably. Both mean the state an AI agent keeps beyond a single model call: short-term memory for the current conversation, and long-term memory for facts, summaries and past runs.
What is a LangGraph checkpointer?
A checkpointer saves a LangGraph agent's state at each step so a run can resume, be inspected or continue a conversation later. The Postgres implementation stores those checkpoints in PostgreSQL tables.
Where does Redis fit in agent memory?
Redis or Valkey suits short-term memory such as session context, because keys can expire automatically and reads come from memory. It also hosts a semantic cache. Durable memory belongs in a database with backups.
How is user data removed from agent memory?
Deletion has to reach every copy: the memory rows, their embeddings, any summaries and the backups, according to a stated retention period. Scoping every row to a user or tenant makes that deletion a query rather than a search.
Related pages
- Redis or ValkeyManaged Redis or Valkey, your choice of engineManaged Redis or Valkey: you choose the engine, with persistence, eviction and configuration set for your workload, run 24/7 in your cloud or data center.
- PostgreSQLManaged PostgreSQL service and Postgres hostingManaged PostgreSQL service, compared: how to choose between RDS, Aiven, Crunchy Bridge, Neon and a tailored cluster run 24/7 in your cloud or ours.
- AI data · PostgreSQLpgvector in production: indexes and sizingpgvector in production: HNSW against IVFFlat, memory sizing, recall against latency, filtering, replicas and pgvectorscale, with links to the pgvector docs.
- AI data · Fast recallSemantic cache for LLM apps with Redis or ValkeySemantic cache with Redis or Valkey: how a similarity-matched cache cuts repeat model calls, how to set thresholds and eviction, and the cost maths.
- GuideContext engineering for AI agents: the data layerContext engineering for AI agents: what it is, how it differs from prompt engineering, and which data stores hold memory, retrieval and fresh context. Dated.
- AI data · Agent accessPostgres MCP server: safe agent accessPostgres MCP server guide: read-only roles, row-level security, query limits and audit, so an AI agent can use production data without broad access.
Talk to an engineer about agent memory
Bring the agent framework, expected users and retention rules. An engineer will help you design the memory layer and decide where it should run.
- ✓A design sketch for your workload, not a plan menu
- ✓A zero-downtime cutover path for what you run today
- ✓A price for that design, after the review