PostgreSQL Storage
The PostgreSQL storage implementation provides a production-ready storage solution using PostgreSQL databases.
Installation
npm install @mastra/pg
Usage
import { PostgresStore } from "@mastra/pg";
const storage = new PostgresStorage({
connectionString: process.env.DATABASE_URL,
});
Parameters
connectionString:
string
PostgreSQL connection string (e.g., postgresql://user:pass@host:5432/dbname)
Additional Notes
Schema Management
The storage implementation handles schema creation and updates automatically. It creates the following tables:
threads
: Stores conversation threadsmessages
: Stores individual messagesmetadata
: Stores additional metadata for threads and messages