Documentation
¶
Overview ¶
Package pgengine runs real PostgreSQL servers in containers for emulators of managed PostgreSQL services: a named data volume, a published loopback port, SQL access as an engine-private superuser, and stop/start that keep data.
Index ¶
- Constants
- Variables
- func Ident(name string) string
- func Literal(v string) string
- type Config
- type Engine
- type Runtime
- type Server
- func (s *Server) Close(ctx context.Context, purge bool)
- func (s *Server) CreateDatabase(ctx context.Context, name, owner, charset, collation string) error
- func (s *Server) Databases(ctx context.Context) ([]string, error)
- func (s *Server) DropDatabase(ctx context.Context, name string) error
- func (s *Server) DropRole(ctx context.Context, user string) error
- func (s *Server) Endpoint() (string, int)
- func (s *Server) EnsureAdmin(ctx context.Context, user, password string) error
- func (s *Server) Exec(ctx context.Context, db, stmt string) error
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type Spec
Constants ¶
const (
// Superuser is the engine-private role; emulators keep its password to themselves.
Superuser = "gsroot"
)
Variables ¶
ErrRuntimeUnavailable is returned when no container runtime is configured.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Runtime Runtime
Volumes container.VolumeRuntime
Ports *portalloc.Allocator
Logger *slog.Logger
Prefix string
StartTimeout time.Duration
}
Config configures an Engine. Prefix names containers and volumes ("<prefix>-...").
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine launches PostgreSQL servers.
func (*Engine) RemoveVolume ¶
RemoveVolume deletes the data volume of server id.
func (*Engine) VolumeName ¶
VolumeName is the data volume of server id.
type Runtime ¶
type Runtime interface {
CreateAndStart(ctx context.Context, spec container.Spec) (string, error)
StopAndRemove(ctx context.Context, containerID string) error
StopContainer(ctx context.Context, containerID string) error
StartContainer(ctx context.Context, containerID string) error
}
Runtime is the slice of the container runtime the engine uses.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is one running PostgreSQL container.
func (*Server) Close ¶
Close removes the container and releases its port; purge also deletes the data volume.
func (*Server) CreateDatabase ¶
CreateDatabase creates a database owned by owner; an existing one is left alone.
func (*Server) DropDatabase ¶
DropDatabase drops a database, disconnecting its sessions; a missing one is not an error.
func (*Server) EnsureAdmin ¶
EnsureAdmin creates or updates a login role that can create databases and roles and owns what it creates.
func (*Server) Exec ¶
Exec runs one statement as the superuser in database db ("" for the default). Callers quote identifiers and literals with Ident and Literal.
type Spec ¶
type Spec struct {
// ID names the container and, when Persist is set, the data volume.
ID string
// Image is the container image, e.g. postgres:16.
Image string
// Password is the superuser password applied on first initialisation; it must match an existing volume.
Password string
Persist bool
Fresh bool
}
Spec describes one server.