pgxpool initialization with max connections and statement timeout

3543
0

Postgres stability depends on respecting its limits. I configure pgxpool with explicit MaxConns and MaxConnLifetime so the service doesn't accidentally open too many connections during bursts. I also set a session statement_timeout in AfterConnect, which is a pragmatic safety net when a query goes bad: the database will cancel it instead of letting it run for minutes and pin a connection. This is not a substitute for indexes and query tuning, but it prevents one slow query from turning into a cascading failure. I like returning a small wrapper that includes a Ping method used by readiness checks and graceful shutdown hooks.