postgres

package
v0.0.0-...-4391913 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 13 Imported by: 0 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 a pool tuned for Lambda, to Postgres (Connect) or to Aurora DSQL (ConnectDSQL).

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPort = errors.New("invalid postgres port")

ErrInvalidPort is returned when WithHost carries a port that is not a TCP port.

Functions

func Connect

func Connect(ctx context.Context, connString string, opts ...Option) (*pgxpool.Pool, error)

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

func ConnectDSQL(ctx context.Context, cluster DSQL, opts ...Option) (*pgxpool.Pool, error)

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

func WithHost(host, port string) Option

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.

Jump to

Keyboard shortcuts

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