Configuring Connection Settings

1. Setting max_connections

max_connections = 200       # requires restart
# Prefer a pooler (PgBouncer) over very high values.

2. Setting superuser_reserved_connections

superuser_reserved_connections = 5

3. Setting statement_timeout

SET statement_timeout = '30s';
ALTER ROLE reporting SET statement_timeout = '2min';

4. Setting idle_in_transaction_session_timeout

ALTER SYSTEM SET idle_in_transaction_session_timeout = '5min';
-- Prevents long-held locks & bloat from forgotten BEGINs

5. Setting tcp_keepalives_idle

tcp_keepalives_idle     = 60      # seconds before first keepalive

6. Setting tcp_keepalives_interval

tcp_keepalives_interval = 10      # between keepalives

7. Setting tcp_keepalives_count

tcp_keepalives_count    = 6       # missed packets before drop

8. Using Connection Pooling

PoolerMode
PgBouncersession / transaction / statement
Odysseymulti-threaded, transaction pooling
PG 14+ built-inNone — still use external pooler

9. Configuring listen_addresses

listen_addresses = '*'            # all; or '10.0.0.5,localhost'

10. Setting port

port = 5432

11. Setting unix_socket_directories

unix_socket_directories = '/var/run/postgresql'
unix_socket_permissions = 0770