Documentation
¶
Overview ¶
Package postgres opens PostgreSQL databases with the pure-Go pgx stdlib driver and describes them with the credentials redacted.
Index ¶
- type DB
- type Pool
- type PoolOption
- func WithAcquireTimeout(d time.Duration) PoolOption
- func WithMaxConnLifetime(d time.Duration) PoolOption
- func WithMaxConns(n int32) PoolOption
- func WithMinConns(n int32) PoolOption
- func WithObserver(o data.Observer) PoolOption
- func WithReplica(replica *pgxpool.Pool) PoolOption
- func WithStatementTimeout(d time.Duration) PoolOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a *sql.DB that can describe itself for `fletch ax inspect`.
func Open ¶
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 ¶
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 ¶
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 ¶
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) Replica ¶
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 ¶
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 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.