embeddedpg

package
v0.0.0-...-acbe8ed Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package embeddedpg owns the full lifecycle of embedded-PostgreSQL instances used by tests: it creates and owns the data directory, marks it with an owner PID so a startup sweep can tell live suites from orphans, starts postgres, and spawns a detached watchdog process that reaps postgres if this process dies without cleaning up (e.g. SIGKILL).

Every test suite that boots an embedded PostgreSQL should go through Start/Stop here instead of creating its own data directory — a single unified directory-naming scheme and marker format is what makes the startup sweep (sweep.go) able to reliably distinguish live instances from orphans left behind by a killed process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance is a running embedded-PostgreSQL instance owned by this package.

func Start

func Start(opts *Options) (*Instance, error)

Start creates a fresh, self-owned data directory, runs the startup sweep (once per process), starts a new embedded-PostgreSQL instance in it, and spawns a parent-death watchdog. Callers must call Stop on the returned Instance when done (normally via t.Cleanup).

func (*Instance) DSN

func (i *Instance) DSN() string

DSN returns the PostgreSQL connection string for this instance.

func (*Instance) DataDir

func (i *Instance) DataDir() string

DataDir returns the data directory owned by this instance.

func (*Instance) Stop

func (i *Instance) Stop() error

Stop stops postgres, stops the watchdog (best-effort — a stray watchdog is harmless since it no-ops once the data dir and PIDs are gone, but killing it directly avoids a lingering `sh` per test run), and removes the data directory.

type Options

type Options struct {
	// Suite names the caller (e.g. "scenario", "notifier") — becomes part
	// of the data-directory name, purely for human debugging.
	Suite string

	// Port is the TCP port postgres listens on. Zero lets embedded-postgres
	// pick its own default.
	Port uint32

	// Database, Username, Password are the initial database/role created by
	// postgres on first start. Empty values fall back to sane test defaults.
	Database string
	Username string
	Password string

	// StartParameters are extra postgresql.conf-style settings, e.g.
	// {"shared_buffers": "256kB"}.
	StartParameters map[string]string
}

Options configures a new embedded-PostgreSQL instance.

Jump to

Keyboard shortcuts

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