postgres

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres opens PostgreSQL databases with the pure-Go pgx stdlib driver and describes them with the credentials redacted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a *sql.DB that can describe itself for `fletch ax inspect`.

func Open

func Open(dsn string) (*DB, error)

Open returns a database for a URL or key=value DSN. It parses the DSN but does not connect; the first query dials. Errors never contain the DSN's credentials.

func (*DB) Describe

func (d *DB) Describe() data.Description

Describe reports the provider and connection facts with no credentials.

type Pool

type Pool struct {
	*sql.DB
	// contains filtered or unexported fields
}

Pool is a native pgx pool with a *sql.DB view of the same connections. The embedded *sql.DB works with everything in data that takes one.

func OpenPool

func OpenPool(ctx context.Context, dsn string, opts ...PoolOption) (*Pool, error)

OpenPool parses dsn and builds a pgx pool. pgxpool connects lazily, so it does no I/O unless WithMinConns asks for connections. Errors never contain the DSN's credentials.

func (*Pool) Close

func (p *Pool) Close() error

Close closes the *sql.DB views and the primary pool. A replica pool passed to WithReplica belongs to the caller and stays open.

func (*Pool) Describe

func (p *Pool) Describe() data.Description

Describe reports the provider, pool settings, and connection facts with no credentials.

func (*Pool) Pool

func (p *Pool) Pool() *pgxpool.Pool

Pool returns the pgx pool, for pgx-native work such as COPY or batches.

func (*Pool) Replica

func (p *Pool) Replica() *sql.DB

Replica returns a *sql.DB on the read replica set with WithReplica, or the primary's when there is none, so read paths can always call it.

func (*Pool) ReplicaPool

func (p *Pool) ReplicaPool() *pgxpool.Pool

ReplicaPool returns the read replica's pgx pool, or nil.

type PoolOption

type PoolOption func(*poolConfig)

PoolOption configures OpenPool.

func WithAcquireTimeout

func WithAcquireTimeout(d time.Duration) PoolOption

WithAcquireTimeout bounds how long the *sql.DB view waits for a free pool connection.

func WithMaxConnLifetime

func WithMaxConnLifetime(d time.Duration) PoolOption

WithMaxConnLifetime closes connections older than d.

func WithMaxConns

func WithMaxConns(n int32) PoolOption

WithMaxConns caps the pool size (pgx's default is 4 or the CPU count).

func WithMinConns

func WithMinConns(n int32) PoolOption

WithMinConns keeps n connections open.

func WithObserver

func WithObserver(o data.Observer) PoolOption

WithObserver reports every statement on the pool, through pgx's QueryTracer, to o, which may be an obs tracer or metrics recorder.

func WithReplica

func WithReplica(replica *pgxpool.Pool) PoolOption

WithReplica adds a read replica pool. Pool.Replica returns a *sql.DB on it; the caller keeps ownership of the pool.

func WithStatementTimeout

func WithStatementTimeout(d time.Duration) PoolOption

WithStatementTimeout sets the server's statement_timeout on every connection. For one call, give it a context with a deadline: pgx sends Postgres a cancel request when the context ends.

Jump to

Keyboard shortcuts

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