A connection pooler sits between the app and Postgres. It shares a small number of server connections between many clients. This guide tells you which Autumn features work behind each pooler mode.

Pooler modes

ModeA client keeps one server session forExamples
SessionThe full client connectionPgBouncer pool_mode = session
TransactionOne transactionPgBouncer pool_mode = transaction, Supavisor port 6543, the Neon -pooler host
Proxy with pinningOne transaction, until the client sets session state, then the full connectionAWS RDS Proxy

Session mode works with every Autumn feature. Transaction mode does not keep session state between transactions. The table below shows what that breaks.

Compatibility matrix

Autumn featureSession modeTransaction modeRDS Proxy
Repository reads and writes, Db, transactionsWorksWorksWorks
Transaction advisory locks (scheduler tick table, counter cache, positions)WorksWorksWorks
Session advisory locks: Lock (distributed locks), migration lock, ISR coordinator, autumn-search Postgres backendWorksBroken. The unlock can run on a different server session, so the lock leaks.Works, but pins the connection
database.statement_timeout (a SET on each checkout)WorksBroken. The SET applies to a different session, or to another client.Works, but pins every connection
Prepared statements (diesel-async caches them)WorksWorks only with PgBouncer 1.21 or later and max_prepared_statements above 0Works. Some forms pin the connection.
LISTEN (shard directory invalidation)WorksBroken. Notifications do not arrive.Pins the connection

Pinning keeps one server connection for one client. This removes the pooling benefit for that client.

  1. Use session mode when you can. Then you need no other change.

  2. Run autumn migrate with a direct URL, not the pooler URL. The migration lock is a session advisory lock. For the same reason, set database.auto_migrate = false when database.url is a pooler URL.

  3. In transaction mode, do not set database.statement_timeout. Set the timeout on the database role:

    Sql
    ALTER ROLE app SET statement_timeout = '5s';
    
  4. In transaction mode, do not use Lock on the pooled URL. Do not use a shard directory listener on it.

  5. With PgBouncer in transaction mode, set max_prepared_statements (for example 200) in pgbouncer.ini.

Boot warning

At boot, Autumn examines database.url, database.primary_url, database.replica_url, and the primary_url and replica_url of each [[database.shards]] entry. When a URL looks like a pooler, the app logs a warning that names the key, for example database.shards[1].primary_url. These URL parts start the warning:

URL partPooler
pgbouncer=true in the queryPgBouncer
Port 6432PgBouncer
Host *.proxy-*.rds.amazonaws.comRDS Proxy
Host *.pooler.supabase.com on port 6543Supavisor (transaction mode)
Host *-pooler.*.neon.techthe Neon pooler

The check is a heuristic. It cannot find the pool mode. When your pooler is in session mode, or the warning is wrong, turn it off:

TOML
[database]
warn_on_pooler = false

The environment variable is AUTUMN_DATABASE__WARN_ON_POOLER=false.