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 ¶
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).
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.