Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package
v1.33.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package postgres is Harbor's V1 Postgres-backed StateStore driver.

It is the multi-node production target for the §9 persistence triad: the third leg, alongside the in-memory reference and the SQLite driver. Harbor inherits `internal/state/conformancetest.Run` verbatim — the suite IS the gate; this driver ships zero new conformance scenarios.

The driver uses `pgx/v5/stdlib` so the rest of Harbor sees a `database/sql.DB`. Parametric queries everywhere; no string concatenation into SQL (AGENTS.md §9). Advisory locks serialise the migration runner so multi-replica boots are race-free.

Internal model:

  • One row per (tenant, user, session, run, kind). The composite primary key is the identity quadruple plus Kind. RunID may be empty (session-scoped state); the column is NOT NULL but accepts the empty string.
  • `bytes` is BYTEA — opaque payload, no JSONB constraint.
  • `event_id` carries a UNIQUE secondary index for LoadByEventID and to defend against duplicate-id leaks under contention.
  • Save is a transactional UPSERT (`INSERT ... ON CONFLICT DO UPDATE`) prefaced by an idempotency probe on `event_id`. When a slot already holds a different EventID, the previous EventID row is implicitly evicted because the slot's row is updated in place.
  • `Close(ctx)` flips an atomic flag BEFORE calling `db.Close()` so subsequent calls fast-fail with `ErrStoreClosed` even while in-flight queries are draining.

Per AGENTS.md §5, the driver is safe for concurrent reuse across N goroutines. The conformance suite's `Concurrent_SaveLoad_NoRace` + the local `concurrent_test.go` enforce this under -race.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New constructs a Postgres-backed state.StateStore against cfg.DSN. Production callers go through state.Open; tests may call New directly to skip the registry.

Errors:

  • empty cfg.DSN
  • sql.Open / migration apply failure
  • advisory-lock acquisition failure (extremely unusual; would indicate severe DB load or operator misconfiguration)

func NewWithDB added in v1.29.1

func NewWithDB(cfg config.StateConfig, db *sql.DB) (state.StateStore, error)

NewWithDB constructs a Postgres StateStore over a runtime-owned pool. The returned store borrows db and never closes it; the runtime pool manager owns the physical connection lifecycle.

Types

This section is empty.

Jump to

Keyboard shortcuts

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