postgres

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 26 Imported by: 0

README

PostgreSQL backend

PostgreSQL stores histories, pending events, timers and activity tasks for workers sharing one database. See backend operations for durability, retention and storage isolation.

Connections and migrations

NewPostgresBackend opens and owns a pgx-backed SQL connection and applies embedded migrations by default. Its convenience connection string uses sslmode=disable. For a remote database requiring TLS or other connection policy, configure a *sql.DB in the host application and pass it to NewPostgresBackendWithDB.

NewPostgresBackendWithDB leaves connection ownership with the caller and disables migrations by default. Enable them explicitly with WithApplyMigrations(true) when the application owns migration startup. Close does not close a caller-owned connection. WithPostgresOptions configures connections opened by the convenience constructor.

Constructors can panic when initialization or automatic migration fails. Keep credentials outside source and apply migrations before accepting work. Back up the database before schema upgrades.

Maintaining the backend

Embedded migrations live in db/migrations, with paired .up.sql and .down.sql files. Follow the existing sequence and preserve published migrations. Test schema changes against real PostgreSQL using the production constructor and migration path.

Run make test-postgres for backend contracts and make test-recovery for independent worker process recovery. Both use isolated PostgreSQL with -race; neither needs a production database. See testing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresBackend

func NewPostgresBackend(host string, port int, user, password, database string, opts ...option) *postgresBackend

func NewPostgresBackendWithDB

func NewPostgresBackendWithDB(db *sql.DB, opts ...option) *postgresBackend

NewPostgresBackendWithDB creates a new Postgres backend using an existing database connection. When using this constructor, the backend will not close the database connection when Close() is called. Migrations can still be applied using WithApplyMigrations(true) as Postgres does not require special connection settings for migrations.

func WithApplyMigrations

func WithApplyMigrations(applyMigrations bool) option

WithApplyMigrations automatically applies database migrations on startup.

func WithBackendOptions

func WithBackendOptions(opts ...backend.BackendOption) option

WithBackendOptions allows to pass generic backend options.

func WithPostgresOptions

func WithPostgresOptions(f func(db *sql.DB)) option

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL