Documentation
¶
Overview ¶
Package pgxutil centralizes pgx connection configuration so that every Postgres connection (source metadata, sink pool, pgvector pool, state store) is built consistently and is safe to use behind a transaction/statement pooling proxy such as PgBouncer.
PgBouncer in transaction or statement pooling mode multiplexes client sessions onto a small set of backend connections. Server-side prepared statements and the extended query protocol (pgx's default) break in that environment with errors like
ERROR: prepared statement "stmtcache_xxx" already exists
because a cached statement created on one backend may be executed on a different one. To avoid this we switch pgx to the simple/exec query mode and disable the statement and description caches whenever the connection targets a pooler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultPooler = NewPooler()
DefaultPooler is the global connection pooler used by sources and sinks to share backend connections.
Functions ¶
func ApplyPoolerSafety ¶
func ApplyPoolerSafety(cfg *pgx.ConnConfig)
ApplyPoolerSafety configures a pgx connection config for use behind a transaction/statement pooling proxy by disabling the extended protocol's server-side prepared-statement and description caches.
func IsPooledConnString ¶
IsPooledConnString reports whether connString declares that it targets a transaction/statement pooling proxy (e.g. PgBouncer) via the custom "pgbouncer=true" or "pool_mode=transaction|statement" markers.
func ParseConfig ¶
func ParseConfig(connString string) (*pgx.ConnConfig, bool, error)
ParseConfig parses connString into a pgx connection config, transparently stripping the custom pooler markers and applying pooler-safe settings when they are present. The second return value reports whether the connection was detected to target a pooler.
Types ¶
type Pooler ¶
type Pooler struct {
// contains filtered or unexported fields
}
Pooler caches and reuses pgxpool.Pool instances based on connection strings. It ensures that multiple workflow nodes targeting the same database share the same underlying connection pool, reducing the load on the database or proxy.