StepflowStepflow

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-postgres

Usage

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

OptionTypeDescription
connectionStringstringFull PostgreSQL connection URL
hoststringDatabase host
portnumberDatabase port
databasestringDatabase name
userstringDatabase user
passwordstringDatabase password
schemastringPostgreSQL schema to use (default: stepflow)
poolSizenumberMaximum number of clients in the pool (default: 20)

Features

  • ACID Compliance: Ensures workflow state is always consistent.
  • Real-time Updates: Uses PostgreSQL LISTEN/NOTIFY to stream execution updates to clients.
  • Advisory Locks: Uses pg_advisory_lock for 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

On this page