PostgreSQL Storage
Production-ready storage adapter with ACID guarantees
PostgreSQL Storage
The @stepflowjs/storage-postgres adapter provides a robust, production-ready storage backend using PostgreSQL. It leverages PostgreSQL's ACID guarantees, advisory locks for leader election, and LISTEN/NOTIFY for real-time updates.
Installation
pnpm add @stepflowjs/storage-postgresUsage
import { Stepflow } from "@stepflowjs/core";
import { PostgresStorageAdapter } from "@stepflowjs/storage-postgres";
const stepflow = new Stepflow({
storage: new PostgresStorageAdapter({
connectionString: process.env.DATABASE_URL,
// Optional: specify a custom schema (defaults to "stepflow")
schema: "my_app_workflows",
// Optional: pool size (defaults to 20)
poolSize: 30,
}),
});Configuration Options
| Option | Type | Description |
|---|---|---|
connectionString | string | Full PostgreSQL connection URL |
host | string | Database host |
port | number | Database port |
database | string | Database name |
user | string | Database user |
password | string | Database password |
schema | string | PostgreSQL schema to use (default: stepflow) |
poolSize | number | Maximum number of clients in the pool (default: 20) |
Features
- ACID Compliance: Ensures workflow state is always consistent.
- Real-time Updates: Uses PostgreSQL
LISTEN/NOTIFYto stream execution updates to clients. - Advisory Locks: Uses
pg_advisory_lockfor efficient leader election and distributed locking. - Automatic Migrations: Automatically creates the necessary tables and indexes on startup.
Environment Variables
Commonly used with environment variables:
DATABASE_URL=postgres://user:password@localhost:5432/dbname