PostgreSQL State Backend Now Available
Vercel's Chat SDK has added a new PostgreSQL adapter for state management, joining existing Redis and ioredis options. Teams already running PostgreSQL in production can now use it as their sole state backend, simplifying infrastructure and reducing operational overhead.
Key Capabilities
The new PostgreSQL adapter supports:
- Subscription persistence for maintaining chat state across sessions
- Distributed locks for coordinating state across multiple instances
- Key-value caching with TTL (time-to-live) support
- Automatic schema creation on first connection
- Namespaced state via configurable key prefixes
Getting Started
The adapter integrates seamlessly into existing Chat SDK configurations:
import { Chat } from "chat";
import { createPostgresState } from "@chat-adapter/state-pg";
const bot = new Chat({
userName: "mybot",
adapters: { /* ... */ },
state: createPostgresState(),
});
Implementation Details
The adapter is built on the popular pg (node-postgres) package and uses raw SQL queries for direct database access. It handles table creation automatically during the initial connection, reducing setup friction. The implementation was contributed by the community member @bai through PR #154.
For complete documentation and configuration options, see the PostgreSQL adapter docs.