SQLStreams

the messaging platform that is just Postgres

You last visited on 9999-99-99 Show what's new since then

Postgres pool

Edit this page
Posted: 2026-09-09 · Report this thread
brandon Site Admin brandon profile Posts: 677

sqlstreams.NewPostgresPool builds a *pgxpool.Pool from the parts of a Postgres URL, in the order the URL writes them: postgres://user:password@host:port/database. It does not dial; NewClient is what pings the pool, so a wrong password surfaces there, not here.

pool, err := sqlstreams.NewPostgresPool(ctx, "app_user", os.Getenv("PGPASSWORD"), "localhost", "app_db",
	&sqlstreams.PostgresConnectionConfig{MaxConns: 20})
if err != nil {
	return err
}
defer pool.Close()

The password goes inline, "" meaning no password, which is real on a trust or peer auth setup. A password holding @ or # and an IPv6 host survive: the DSN is built through net/url.

Config

PostgresConnectionConfig

fielddefaultwhat it decides
Port5432the port
MaxConnspgx’s own, max(4, numCPU)the pool’s size when > 0; raise it for high worker counts
ConnectTimeoutpgx’s own (none)mirrors pgconn.Config.ConnectTimeout
TLSConfigpgx’s own negotiation (sslmode=prefer)mirrors pgconn.Config.TLSConfig; the package never sets sslmode itself

Schema is not here. It was never a connection fact and sits on ClientConfig.

Gotchas

  • A caller holding a DSN skips this entirely: pgxpool.New(ctx, dsn) and hand the result to NewClient, which takes any *pgxpool.Pool. That is the path for a DATABASE_URL deployment and for an application whose pool exists before SQLStreams enters it.
  • Whichever way the pool is built, you close it. defer pool.Close() is the only shutdown this layer needs.
  • Taking a pool commits the public API to pgx. A team on database/sql runs one pool: build the pgxpool, hand it to SQLStreams, and derive the *sql.DB view with pgx’s own stdlib.OpenDBFromPool(pool), which shares the pool and leaves closing to you. The derivation runs only that direction, so a team that will not import pgx runs a second pool beside SQLStreams’s.
  • A pool you built can carry its own search_path, on the DSN as ?search_path=myapp or in an AfterConnect hook. SQLStreams does not care: every statement it runs names its schema outright.