Skip to Content
ReferenceStoragePostgreSQL Storage

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 PostgresStore({ connectionString: process.env.DATABASE_URL, });

Parameters

connectionString:

string
PostgreSQL connection string (e.g., postgresql://user:pass@host:5432/dbname)

schema?:

string
The name of the schema you want the storage to use. Will use the default schema if not provided.

Additional Notes

Schema Management

The storage implementation handles schema creation and updates automatically. It creates the following tables:

  • threads: Stores conversation threads
  • messages: Stores individual messages
  • metadata: Stores additional metadata for threads and messages