Connection pooling helps manage many database requests efficiently by reusing a few connections. PgBouncer is a tool that does this for PostgreSQL databases.
Connection pooling with PgBouncer in Supabase
[databases] mydb = host=localhost port=5432 dbname=mydb user=myuser password=mypass [pgbouncer] listen_addr = * listen_port = 6432 auth_type = md5 auth_file = /etc/pgbouncer/userlist.txt pool_mode = session max_client_conn = 100 default_pool_size = 20
The [databases] section defines which databases PgBouncer will connect to.
The [pgbouncer] section sets how PgBouncer listens and manages connections.
[databases]
mydb = host=localhost port=5432 dbname=mydb user=myuser password=mypass
[pgbouncer]
pool_mode = session[databases]
mydb = host=localhost port=5432 dbname=mydb user=myuser password=mypass
[pgbouncer]
pool_mode = transaction[databases]
mydb = host=localhost port=5432 dbname=mydb user=myuser password=mypass
[pgbouncer]
pool_mode = statementThis is a complete PgBouncer configuration for a Supabase PostgreSQL database. It uses transaction pooling to efficiently manage connections. It listens on all network interfaces on port 6432 and logs connections and disconnections.
[databases] supabase = host=db.supabase.co port=5432 dbname=supabase user=supabase_user password=secret_password [pgbouncer] listen_addr = 0.0.0.0 listen_port = 6432 auth_type = md5 auth_file = /etc/pgbouncer/userlist.txt pool_mode = transaction max_client_conn = 100 default_pool_size = 20 log_connections = 1 log_disconnections = 1
Always secure your PgBouncer auth_file with proper permissions to protect passwords.
Choose pool_mode based on your app's query patterns for best performance.
Monitor PgBouncer logs to understand connection usage and troubleshoot issues.
PgBouncer helps reuse database connections to improve app speed and reduce load.
Configure PgBouncer with your database details and choose a pooling mode.
Use transaction pooling for most apps to balance performance and compatibility.