Documentation
¶
Overview ¶
Package postgres is the server's PostgreSQL: the connection pool, the check that the server is a supported version, and the schema migrations embedded in the binary.
Index ¶
- Constants
- func Canary(ctx context.Context, pool *pgxpool.Pool, fresh string, now time.Time) (string, error)
- func CheckServerVersion(num int) error
- func Migrations() fs.FS
- func NewTransactor(pool *pgxpool.Pool) *pgxtx.Transactor
- func Open(ctx context.Context, cfg *pgxpool.Config) (*pgxpool.Pool, error)
- func PoolConfig(databaseURL string, maxConns int) (cfg *pgxpool.Config, overrode bool, err error)
- func SchemaVersions(ctx context.Context, pool *pgxpool.Pool, migrations fs.FS) (database, binary int64, err error)
- func ServerVersionNum(ctx context.Context, pool *pgxpool.Pool) (int, error)
- func SidePool(pool *pgxpool.Pool, maxConns int32) (*pgxpool.Pool, error)
- type Listeners
- type MigrationReport
- type PoolCollector
Constants ¶
const DefaultMaxConns = 10
DefaultMaxConns is the pool size when neither the configuration nor pool_max_conns in DATABASE_URL sets one: enough for a replica's requests and workers on a small container, a known number on a large node.
const MinServerVersionNum = 160000
MinServerVersionNum is the oldest supported PostgreSQL, as server_version_num reports it: 16. Migrations and queries may use anything it offers and nothing newer.
Variables ¶
This section is empty.
Functions ¶
func Canary ¶
Canary returns the instance's canary, storing fresh as the canary at now when the instance has none yet. Replicas starting together all read the one canary the first of them stored.
func CheckServerVersion ¶
CheckServerVersion refuses a server older than MinServerVersionNum, naming both versions, so an unsupported database is found at start rather than at the first query that needs a newer feature.
func Migrations ¶
Migrations returns the migration set embedded in the binary.
func NewTransactor ¶
func NewTransactor(pool *pgxpool.Pool) *pgxtx.Transactor
NewTransactor returns the transactor of the server's pool. A deadlock or serialization failure comes back as unavailable, worth retrying by the client: the server does not retry it, because a unit of work fixes its lock order instead, and a retry would hide an order that is wrong.
func Open ¶
Open creates a pool. It does not wait for PostgreSQL to be reachable: the first query does, and readiness reports it.
func PoolConfig ¶
PoolConfig is the pool configuration of databaseURL with maxConns connections. maxConns 0 keeps pool_max_conns of the URL, or DefaultMaxConns when the URL has none. overrode reports a maxConns that replaced the URL's own pool_max_conns, for the caller to log: an existing URL is never overridden silently.
func SchemaVersions ¶
func SchemaVersions(ctx context.Context, pool *pgxpool.Pool, migrations fs.FS) (database, binary int64, err error)
SchemaVersions returns the version of the schema in the database, the last migration applied (0 when none ever was), and the version of migrations, its latest migration (0 for an empty set).
func ServerVersionNum ¶
ServerVersionNum reads the server's server_version_num, such as 170004.
Types ¶
type Listeners ¶
type Listeners struct {
// contains filtered or unexported fields
}
Listeners run the replica's notification listeners on the database of a pool, each on a connection of its own, and report each one's state as flagnetic_listener_up{channel}. A listener that is down leaves readiness alone: the replica still serves, and what depends on notifications stops trusting itself instead.
func NewListeners ¶
func NewListeners(ctx context.Context, pool *pgxpool.Pool, log *slog.Logger, reg prometheus.Registerer) *Listeners
NewListeners registers the listener gauge on reg. Listeners run on ctx, the replica's own context, until Stop.
func (*Listeners) Restart ¶
Restart ends every listener, waiting at most bound for each to close, and starts them again on new connections, as a database failover makes them do; it reports whether they all closed in time.
type MigrationReport ¶
type MigrationReport struct {
// Applied is the number of migrations this call applied.
Applied int
// Version is the schema's version afterwards: the last migration applied,
// by this call or an earlier one.
Version int64
}
MigrationReport says what Migrate did.
func Migrate ¶
Migrate applies every pending migration of migrations to the schema that pool's search_path points at. Replicas that start together serialise on a PostgreSQL session advisory lock, so each migration is applied exactly once; the lock belongs to the session, so it is released even when a migration fails half way. An empty migration set is valid and applies nothing.
type PoolCollector ¶
type PoolCollector struct {
// contains filtered or unexported fields
}
PoolCollector exports a pool's statistics, so a saturated pool shows before requests start timing out: acquired close to max, and acquire waits growing.
func NewPoolCollector ¶
func NewPoolCollector(pool *pgxpool.Pool) *PoolCollector
NewPoolCollector returns a collector of pool's statistics.
func (*PoolCollector) Collect ¶
func (c *PoolCollector) Collect(ch chan<- prometheus.Metric)
Collect sends the pool's statistics now.
func (*PoolCollector) Describe ¶
func (c *PoolCollector) Describe(ch chan<- *prometheus.Desc)
Describe sends the descriptions of the pool metrics.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package access is the PostgreSQL repository of the access context: members, API tokens and sessions.
|
Package access is the PostgreSQL repository of the access context: members, API tokens and sessions. |
|
Package delivery is the PostgreSQL repository of the delivery context: for now, the ruleset version of each environment.
|
Package delivery is the PostgreSQL repository of the delivery context: for now, the ruleset version of each environment. |
|
Package events is the PostgreSQL repository of the events context: the raw events SDKs post and the tables that keep them apart from retries.
|
Package events is the PostgreSQL repository of the events context: the raw events SDKs post and the tables that keep them apart from retries. |
|
Package experiments is the PostgreSQL repository of the experiments context.
|
Package experiments is the PostgreSQL repository of the experiments context. |
|
Package flags is the PostgreSQL repository of the flags context: flags, their configuration in each environment, and segments.
|
Package flags is the PostgreSQL repository of the flags context: flags, their configuration in each environment, and segments. |
|
Package governance is the PostgreSQL repository of the governance context: the audit log.
|
Package governance is the PostgreSQL repository of the governance context: the audit log. |
|
Package projectrow records, for the life of a transaction, the projects whose row it locked FOR UPDATE, the lock every write of a project takes so that the project's writes run one at a time.
|
Package projectrow records, for the life of a transaction, the projects whose row it locked FOR UPDATE, the lock every write of a project takes so that the project's writes run one at a time. |
|
Package workspace is the PostgreSQL repository of the workspace context: projects, their environments, unit types and attributes.
|
Package workspace is the PostgreSQL repository of the workspace context: projects, their environments, unit types and attributes. |