Documentation
¶
Overview ¶
Package postgres opens a pool tuned for Lambda, to Postgres (Connect) or to Aurora DSQL (ConnectDSQL).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPort = errors.New("invalid postgres port")
ErrInvalidPort is returned when WithHost carries a port that is not a TCP port.
Functions ¶
func Connect ¶
Connect opens a pgxpool from a connection string, in URL (postgres://user:pass@host:5432/db?sslmode=require) or keyword/value form.
Unless the connection string sets them (pool_max_conns, pool_max_conn_*), the pool is sized and recycled for Lambda: one connection per invocation the execution environment can run at once, connections recycled before Aurora drops idle ones. Every connection scans timestamptz as UTC and, while the context carries a deadline, caps its statements to the time left. Every query is traced with OpenTelemetry, through the global tracer provider.
func ConnectDSQL ¶
ConnectDSQL opens a pgxpool to an Aurora DSQL cluster through the AWS connector (github.com/awslabs/aurora-dsql-connectors/go/pgx), as the database user admin. DSQL has no password: the connector signs a fresh IAM token for every new connection, so a connection opened after the previous token expired still gets in, and it verifies the server certificate against the endpoint.
The pool is sized for Lambda as Connect sizes it, one connection per invocation the execution environment can run at once, and recycled with the connector's own lifetimes, below the hour after which DSQL closes a connection. Every connection scans timestamptz as UTC and every query is traced, as with Connect.
The statements are not capped server side: DSQL rejects statement_timeout and limits every transaction to 5 minutes on its own. A query still running when the context's deadline passes fails on the client at that deadline, as pgx does by default.
Types ¶
type DSQL ¶
type DSQL struct {
// Endpoint is the cluster endpoint, <cluster id>.dsql.<region>.on.aws.
Endpoint string
// Region is the region of the cluster. Empty, the connector reads it from
// the endpoint, then from AWS_REGION and AWS_DEFAULT_REGION.
Region string
// Credentials sign the IAM tokens. Nil, the connector loads the default
// AWS credential chain.
Credentials aws.CredentialsProvider
}
DSQL is the Aurora DSQL cluster ConnectDSQL connects to.
type Option ¶
type Option func(*options)
Option tunes Connect and ConnectDSQL.
func WithHost ¶
WithHost connects to an overridden host/port while keeping everything else, e.g. to reach the database through a tunnel on localhost. With Connect the credentials and database name of the connection string stay; with ConnectDSQL the IAM token and the TLS verification stay those of the cluster endpoint. Empty values keep the original ones.