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

postgres

package
v0.0.0-...-f11e895 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidTextRepresentation = "22P02"
	CheckViolation            = "23514"
	UniqueViolation           = "23505"
	RaiseException            = "P0001"
	ForeignKeyViolation       = "23503"

	// MaxPoolConnections is per process (pgx default is 5). The pool used to
	// be 20, which matched the entire platform role CONNECTION LIMIT, so a
	// 3-node controller (web×2 + worker×2 + scheduler omni×3) tried to open
	// 140 connections and setDeploymentDone failed with SQLSTATE 53300.
	// Tenant plugin isolation is a separate CONNECTION LIMIT on the plugin
	// appliance, not this pool.
	MaxPoolConnections = 5
)

Variables

This section is empty.

Functions

func IsPostgresCode

func IsPostgresCode(err error, code string) bool

func IsTransientLeaderDialErr

func IsTransientLeaderDialErr(err error) bool

IsTransientLeaderDialErr reports whether err is retryable connectivity while discoverd DNS or sirenia-managed postgres is restarting (dead connections, NXDOMAIN, abrupt EOF from the remote, etc.).

func IsUniquenessError

func IsUniquenessError(err error, constraint string) bool

func ResetOnMigration

func ResetOnMigration(db *DB, log log15.Logger, doneCh chan struct{})

Types

type Conf

type Conf struct {
	Discoverd *discoverd.Client
	Service   string
	User      string
	Password  string
	Database  string

	// SingletonCluster is set by Wait from discoverd service meta when the
	// cluster runs in Sirenia singleton mode (typical single-host Flynn). It is
	// informational; leader host selection uses discoverd whenever leader.* DNS
	// is unavailable (not only for singleton clusters) so the controller can
	// reach Postgres while discoverd DNS catches up.
	SingletonCluster bool
}

type DB

type DB struct {
	*pgx.ConnPool
	// contains filtered or unexported fields
}

func New

func New(connPool *pgx.ConnPool, conf *Conf) *DB

func Open

func Open(conf *Conf, afterConn func(*pgx.Conn) error) (*DB, error)

func Wait

func Wait(conf *Conf, afterConn func(*pgx.Conn) error) *DB

func (*DB) Begin

func (db *DB) Begin() (*DBTx, error)

func (*DB) DialHost

func (db *DB) DialHost() string

DialHost returns the pg host this pool opens connections to (set at Open).

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) error

func (*DB) ExecRetry

func (db *DB) ExecRetry(query string, args ...interface{}) error

func (*DB) Listen

func (db *DB) Listen(channel string, log log15.Logger) (*Listener, error)

Listen creates a listener for the given channel, returning the listener and the first connection error (nil on successful connection).

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) Scanner

type DBTx

type DBTx struct{ *pgx.Tx }

func (*DBTx) Exec

func (tx *DBTx) Exec(query string, args ...interface{}) error

func (*DBTx) QueryRow

func (tx *DBTx) QueryRow(query string, args ...interface{}) Scanner

type Listener

type Listener struct {
	Notify chan *pgx.Notification
	Err    error
	// contains filtered or unexported fields
}

func (*Listener) Close

func (l *Listener) Close() (err error)

type Migration

type Migration struct {
	ID    int
	Steps []Step
}

type Migrations

type Migrations []Migration

func NewMigrations

func NewMigrations() *Migrations

func (*Migrations) Add

func (m *Migrations) Add(id int, stmts ...string)

func (*Migrations) AddSteps

func (m *Migrations) AddSteps(id int, steps ...Step)

func (Migrations) Migrate

func (m Migrations) Migrate(db *DB) error

type Scanner

type Scanner interface {
	Scan(...interface{}) error
}

type Step

type Step func(*DBTx) error

Jump to

Keyboard shortcuts

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