pgbouncer.10000644000000000000000000006765215203352666011652 0ustar rootroot.\" Automatically generated by Pandoc 3.1.8 .\" .TH "PGBOUNCER" "1" "" "1.25.2" "Databases" .SH NAME pgbouncer - lightweight connection pooler for PostgreSQL .SH SYNOPSIS .IP .EX pgbouncer [-d][-R][-v][-u user] pgbouncer -V|-h .EE .PP On Windows, the options are: .IP .EX pgbouncer.exe [-v][-u user] pgbouncer.exe -V|-h .EE .PP Additional options for setting up a Windows service: .IP .EX pgbouncer.exe --regservice pgbouncer.exe --unregservice .EE .SH DESCRIPTION \f[B]pgbouncer\f[R] is a PostgreSQL connection pooler. Any target application can be connected to \f[B]pgbouncer\f[R] as if it were a PostgreSQL server, and \f[B]pgbouncer\f[R] will create a connection to the actual server, or it will reuse one of its existing connections. .PP The aim of \f[B]pgbouncer\f[R] is to lower the performance impact of opening new connections to PostgreSQL. .PP In order not to compromise transaction semantics for connection pooling, \f[B]pgbouncer\f[R] supports several types of pooling when rotating connections: .TP Session pooling Most polite method. When a client connects, a server connection will be assigned to it for the whole duration the client stays connected. When the client disconnects, the server connection will be put back into the pool. This is the default method. .TP Transaction pooling A server connection is assigned to a client only during a transaction. When PgBouncer notices that transaction is over, the server connection will be put back into the pool. .TP Statement pooling Most aggressive method. The server connection will be put back into the pool immediately after a query completes. Multi-statement transactions are disallowed in this mode as they would break. .PP The administration interface of \f[B]pgbouncer\f[R] consists of some new \f[CR]SHOW\f[R] commands available when connected to a special \[lq]virtual\[rq] database \f[B]pgbouncer\f[R]. .SH QUICK-START Basic setup and usage is as follows. .IP "1." 3 Create a pgbouncer.ini file. Details in \f[B]pgbouncer(5)\f[R]. Simple example: .RS 4 .IP .EX [databases] template1 = host=localhost port=5432 dbname=template1 [pgbouncer] listen_port = 6432 listen_addr = localhost auth_type = md5 auth_file = userlist.txt logfile = pgbouncer.log pidfile = pgbouncer.pid admin_users = someuser .EE .RE .IP "2." 3 Create a \f[CR]userlist.txt\f[R] file that contains the users allowed in: .RS 4 .IP .EX \[dq]someuser\[dq] \[dq]same_password_as_in_server\[dq] .EE .RE .IP "3." 3 Launch \f[B]pgbouncer\f[R]: .RS 4 .IP .EX $ pgbouncer -d pgbouncer.ini .EE .RE .IP "4." 3 Have your application (or the \f[B]psql\f[R] client) connect to \f[B]pgbouncer\f[R] instead of directly to the PostgreSQL server: .RS 4 .IP .EX $ psql -p 6432 -U someuser template1 .EE .RE .IP "5." 3 Manage \f[B]pgbouncer\f[R] by connecting to the special administration database \f[B]pgbouncer\f[R] and issuing \f[CR]SHOW HELP;\f[R] to begin: .RS 4 .IP .EX $ psql -p 6432 -U someuser pgbouncer pgbouncer=# SHOW HELP; NOTICE: Console usage DETAIL: SHOW [HELP|CONFIG|DATABASES|FDS|POOLS|CLIENTS|SERVERS|SOCKETS|LISTS|VERSION|...] SET key = arg RELOAD PAUSE SUSPEND RESUME SHUTDOWN [...] .EE .RE .IP "6." 3 If you made changes to the pgbouncer.ini file, you can reload it with: .RS 4 .IP .EX pgbouncer=# RELOAD; .EE .RE .SH COMMAND LINE SWITCHES .TP \f[CR]-d\f[R], \f[CR]--daemon\f[R] Run in the background. Without it, the process will run in the foreground. .RS .PP In daemon mode, setting \f[CR]pidfile\f[R] as well as \f[CR]logfile\f[R] or \f[CR]syslog\f[R] is required. No log messages will be written to stderr after going into the background. .PP Note: Does not work on Windows; \f[B]pgbouncer\f[R] need to run as service there. .RE .TP \f[CR]-R\f[R], \f[CR]--reboot\f[R] \f[B]DEPRECATED: Instead of this option use a rolling restart with multiple pgbouncer processes listening on the same port using so_reuseport instead\f[R] Do an online restart. That means connecting to the running process, loading the open sockets from it, and then using them. If there is no active process, boot normally. Note: Works only if OS supports Unix sockets and the \f[CR]unix_socket_dir\f[R] is not disabled in configuration. Does not work on Windows. Does not work with TLS connections, they are dropped. .TP \f[CR]-u\f[R] \f[I]USERNAME\f[R], \f[CR]--user=\f[R]\f[I]USERNAME\f[R] Switch to the given user on startup. .TP \f[CR]-v\f[R], \f[CR]--verbose\f[R] Increase verbosity. Can be used multiple times. .TP \f[CR]-q\f[R], \f[CR]--quiet\f[R] Be quiet: do not log to stderr. This does not affect logging verbosity, only that stderr is not to be used. For use in init.d scripts. .TP \f[CR]-V\f[R], \f[CR]--version\f[R] Show version. .TP \f[CR]-h\f[R], \f[CR]--help\f[R] Show short help. .TP \f[CR]--regservice\f[R] Win32: Register PgBouncer to run as Windows service. The \f[B]service_name\f[R] configuration parameter value is used as the name to register under. .TP \f[CR]--unregservice\f[R] Win32: Unregister Windows service. .SH ADMIN CONSOLE The console is available by connecting as normal to the database \f[B]pgbouncer\f[R]: .IP .EX $ psql -p 6432 pgbouncer .EE .PP Only users listed in the configuration parameters \f[B]admin_users\f[R] or \f[B]stats_users\f[R] are allowed to log in to the console. (Except when \f[CR]auth_type=any\f[R], then any user is allowed in as a stats_user.) .PP Additionally, the user name \f[B]pgbouncer\f[R] is allowed to log in without password, if the login comes via the Unix socket and the client has same Unix user UID as the running process. .PP The admin console currently only supports the simple query protocol. Some drivers use the extended query protocol for all commands; these drivers will not work for this. .SS Show commands The \f[B]SHOW\f[R] commands output information. Each command is described below. .SS SHOW STATS Shows statistics. In this and related commands, the total figures are since process start, the averages are updated every \f[CR]stats_period\f[R]. .TP database Statistics are presented per database. .TP total_xact_count Total number of SQL transactions pooled by \f[B]pgbouncer\f[R]. .TP total_query_count Total number of SQL commands pooled by \f[B]pgbouncer\f[R]. .TP total_server_assignment_count Total times a server was assigned to a client .TP total_received Total volume in bytes of network traffic received by \f[B]pgbouncer\f[R]. .TP total_sent Total volume in bytes of network traffic sent by \f[B]pgbouncer\f[R]. .TP total_xact_time Total number of microseconds spent by \f[B]pgbouncer\f[R] when connected to PostgreSQL in a transaction, either idle in transaction or executing queries. .TP total_query_time Total number of microseconds spent by \f[B]pgbouncer\f[R] when actively connected to PostgreSQL, executing queries. .TP total_wait_time Time spent by clients waiting for a server, in microseconds. Updated when a client connection is assigned a backend connection. .TP total_client_parse_count Total number of prepared statements created by clients. Only applicable in named prepared statement tracking mode, see \f[CR]max_prepared_statements\f[R]. .TP total_server_parse_count Total number of prepared statements created by \f[B]pgbouncer\f[R] on a server. Only applicable in named prepared statement tracking mode, see \f[CR]max_prepared_statements\f[R]. .TP total_bind_count Total number of prepared statements readied for execution by clients and forwarded to PostgreSQL by \f[B]pgbouncer\f[R]. Only applicable in named prepared statement tracking mode, see \f[CR]max_prepared_statements\f[R]. .TP avg_xact_count Average transactions per second in last stat period. .TP avg_query_count Average queries per second in last stat period. .TP avg_server_assignment_count Average number of times a server as assigned to a client per second in the last stat period. .TP avg_recv Average received (from clients) bytes per second. .TP avg_sent Average sent (to clients) bytes per second. .TP avg_xact_time Average transaction duration, in microseconds. .TP avg_query_time Average query duration, in microseconds. .TP avg_wait_time Time spent by clients waiting for a server, in microseconds (average of the wait times for clients assigned a backend during the current \f[CR]stats_period\f[R]). .TP avg_client_parse_count Average number of prepared statements created by clients. Only applicable in named prepared statement tracking mode, see \f[CR]max_prepared_statements\f[R]. .TP avg_server_parse_count Average number of prepared statements created by \f[B]pgbouncer\f[R] on a server. Only applicable in named prepared statement tracking mode, see \f[CR]max_prepared_statements\f[R]. .TP avg_bind_count Average number of prepared statements readied for execution by clients and forwarded to PostgreSQL by \f[B]pgbouncer\f[R]. Only applicable in named prepared statement tracking mode, see \f[CR]max_prepared_statements\f[R]. .SS SHOW STATS_TOTALS Subset of \f[B]SHOW STATS\f[R] showing the total values (\f[B]total_\f[R]). .SS SHOW STATS_AVERAGES Subset of \f[B]SHOW STATS\f[R] showing the average values (\f[B]avg_\f[R]). .SS SHOW TOTALS Like \f[B]SHOW STATS\f[R] but aggregated across all databases. .SS SHOW SERVERS .TP type S, for server. .TP user User name \f[B]pgbouncer\f[R] uses to connect to server. .TP database Database name. .TP replication If server connection uses replication. Can be \f[B]none\f[R], \f[B]logical\f[R] or \f[B]physical\f[R]. .TP state State of the PgBouncer server connection, one of \f[B]active\f[R], \f[B]idle\f[R], \f[B]used\f[R], \f[B]tested\f[R], \f[B]new\f[R], \f[B]active_cancel\f[R], \f[B]being_canceled\f[R]. .TP addr IP address of PostgreSQL server. .TP port Port of PostgreSQL server. .TP local_addr Connection start address on local machine. .TP local_port Connection start port on local machine. .TP connect_time When the connection was made. .TP request_time When last request was issued. .TP wait Not used for server connections. .TP wait_us Not used for server connections. .TP close_needed 1 if the connection will be closed as soon as possible, because a configuration file reload or DNS update changed the connection information or \f[B]RECONNECT\f[R] was issued. .TP ptr Address of internal object for this connection. .TP link Address of client connection the server is paired with. .TP remote_pid PID of backend server process. In case connection is made over Unix socket and OS supports getting process ID info, its OS PID. Otherwise it\[cq]s extracted from cancel packet the server sent, which should be the PID in case the server is PostgreSQL, but it\[cq]s a random number in case the server it is another PgBouncer. .TP tls A string with TLS connection information, or empty if not using TLS. .TP application_name A string containing the \f[CR]application_name\f[R] set on the linked client connection, or empty if this is not set, or if there is no linked connection. .TP prepared_statements The amount of prepared statements that are prepared on the server. This number is limited by the \f[CR]max_prepared_statements\f[R] setting. .TP id Unique ID for server. .SS SHOW CLIENTS .TP type C, for client. .TP user Client connected user. .TP database Database name. .TP replication If client connection uses replication. Can be \f[B]none\f[R], \f[B]logical\f[R] or \f[B]physical\f[R]. .TP state State of the client connection, one of \f[B]active\f[R] (Client connections that are linked to server connections), \f[B]idle\f[R] (Client connections with no queries waiting to be processed), \f[B]waiting\f[R], \f[B]active_cancel_req\f[R], or \f[B]waiting_cancel_req\f[R]. .TP addr IP address of client. .TP port Source port of client. .TP local_addr Connection end address on local machine. .TP local_port Connection end port on local machine. .TP connect_time Timestamp of connect time. .TP request_time Timestamp of latest client request. .TP wait Current waiting time in seconds. .TP wait_us Microsecond part of the current waiting time. .TP close_needed not used for clients .TP ptr Address of internal object for this connection. .TP link Address of server connection the client is paired with. .TP remote_pid Process ID, in case client connects over Unix socket and OS supports getting it. .TP tls A string with TLS connection information, or empty if not using TLS. .TP application_name A string containing the \f[CR]application_name\f[R] set by the client for this connection, or empty if this was not set. .TP prepared_statements The amount of prepared statements that the client has prepared .TP id Unique ID for client. .SS SHOW POOLS A new pool entry is made for each couple of (database, user). .TP database Database name. .TP user User name. .TP cl_active Client connections that are either linked to server connections or are idle with no queries waiting to be processed. .TP cl_waiting Client connections that have sent queries but have not yet got a server connection. .TP cl_active_cancel_req Client connections that have forwarded query cancellations to the server and are waiting for the server response. .TP cl_waiting_cancel_req Client connections that have not forwarded query cancellations to the server yet. .TP sv_active Server connections that are linked to a client. .TP sv_active_cancel Server connections that are currently forwarding a cancel request. .TP sv_being_canceled Servers that normally could become idle but are waiting to do so until all in-flight cancel requests have completed that were sent to cancel a query on this server. .TP sv_idle Server connections that are unused and immediately usable for client queries. .TP sv_used Server connections that have been idle for more than \f[CR]server_check_delay\f[R], so they need \f[CR]server_check_query\f[R] to run on them before they can be used again. .TP sv_tested Server connections that are currently running either \f[CR]server_reset_query\f[R] or \f[CR]server_check_query\f[R]. .TP sv_login Server connections currently in the process of logging in. .TP maxwait How long the first (oldest) client in the queue has waited, in seconds. If this starts increasing, then the current pool of servers does not handle requests quickly enough. The reason may be either an overloaded server or just too small of a \f[B]pool_size\f[R] setting. .TP maxwait_us Microsecond part of the maximum waiting time. .TP pool_mode The pooling mode in use. .TP load_balance_hosts The load_balance_hosts in use if the pool\[cq]s host contains a comma-separated list. .SS SHOW PEER_POOLS A new peer_pool entry is made for each configured peer. .TP database ID of the configured peer entry. .TP cl_active_cancel_req Client connections that have forwarded query cancellations to the server and are waiting for the server response. .TP cl_waiting_cancel_req Client connections that have not forwarded query cancellations to the server yet. .TP sv_active_cancel Server connections that are currently forwarding a cancel request. .TP sv_login Server connections currently in the process of logging in. .SS SHOW LISTS Show following internal information, in columns (not rows): .TP databases Count of databases. .TP users Count of users. .TP pools Count of pools. .TP free_clients Count of free clients. These are clients that are disconnected, but PgBouncer keeps the memory around that was allocated for them so it can be reused for a future clients to avoid allocations. .TP used_clients Count of used clients. .TP login_clients Count of clients in \f[B]login\f[R] state. .TP free_servers Count of free servers. These are servers that are disconnected, but PgBouncer keeps the memory around that was allocated for them so it can be reused for a future servers to avoid allocations. .TP used_servers Count of used servers. .TP dns_names Count of DNS names in the cache. .TP dns_zones Count of DNS zones in the cache. .TP dns_queries Count of in-flight DNS queries. .TP dns_pending not used .SS SHOW USERS .TP name The user name .TP pool_size The user\[cq]s override pool_size. or NULL if not set. .TP reserve_pool_size The user\[cq]s override reserve_pool_size. or NULL if not set. .TP pool_mode The user\[cq]s override pool_mode, or NULL if not set. .TP max_user_connections The user\[cq]s max_user_connections setting. If this setting is not set for this specific user, then the default value will be displayed. .TP current_connections Current number of server connections that this user has open to all servers. .TP max_user_client_connections The user\[cq]s max_user_client_connections setting. If this setting is not set for this specific user, then the default value will be displayed. .TP current_client_connections Current number of client connections that this user has open to PgBouncer. .SS SHOW DATABASES .TP name Name of configured database entry. .TP host Host PgBouncer connects to. .TP port Port PgBouncer connects to. .TP database Actual database name PgBouncer connects to. .TP force_user When the user is part of the connection string, the connection between PgBouncer and PostgreSQL is forced to the given user, whatever the client user. .TP pool_size Maximum number of server connections. .TP min_pool_size Minimum number of server connections. .TP reserve_pool_size Maximum number of additional connections for this database. .TP server_lifetime The maximum lifetime of a server connection for this database .TP pool_mode The database\[cq]s override pool_mode, or NULL if the default will be used instead. .TP load_balance_hosts The database\[cq]s load_balance_hosts if the host contains a comma-separated list. .TP max_connections Maximum number of allowed server connections for this database, as set by \f[B]max_db_connections\f[R], either globally or per database. .TP current_connections Current number of server connections for this database. .TP max_client_connections Maximum number of allowed client connections for this PgBouncer instance, as set by max_db_client_connections per database. .TP current_client_connections Current number of client connections for this database. .TP paused 1 if this database is currently paused, else 0. .TP disabled 1 if this database is currently disabled, else 0. .SS SHOW PEERS .TP peer_id ID of the configured peer entry. .TP host Host PgBouncer connects to. .TP port Port PgBouncer connects to. .TP pool_size Maximum number of server connections that can be made to this peer .SS SHOW FDS Internal command - shows list of file descriptors in use with internal state attached to them. .PP When the connected user has the user name \[lq]pgbouncer\[rq], connects through the Unix socket and has same the UID as the running process, the actual FDs are passed over the connection. This mechanism is used to do an online restart. Note: This does not work on Windows. .PP This command also blocks the internal event loop, so it should not be used while PgBouncer is in use. .TP fd File descriptor numeric value. .TP task One of \f[B]pooler\f[R], \f[B]client\f[R] or \f[B]server\f[R]. .TP user User of the connection using the FD. .TP database Database of the connection using the FD. .TP addr IP address of the connection using the FD, \f[B]unix\f[R] if a Unix socket is used. .TP port Port used by the connection using the FD. .TP cancel Cancel key for this connection. .TP link fd for corresponding server/client. NULL if idle. .SS SHOW SOCKETS, SHOW ACTIVE_SOCKETS Shows low-level information about sockets or only active sockets. This includes the information shown under \f[B]SHOW CLIENTS\f[R] and \f[B]SHOW SERVERS\f[R] as well as other more low-level information. .SS SHOW CONFIG Show the current configuration settings, one per row, with the following columns: .TP key Configuration variable name .TP value Configuration value .TP default Configuration default value .TP changeable Either \f[B]yes\f[R] or \f[B]no\f[R], shows if the variable can be changed while running. If \f[B]no\f[R], the variable can be changed only at boot time. Use \f[B]SET\f[R] to change a variable at run time. .SS SHOW MEM Shows low-level information about the current sizes of various internal memory allocations. The information presented is subject to change. .SS SHOW DNS_HOSTS Show host names in DNS cache. .TP hostname Host name. .TP ttl How many seconds until next lookup. .TP addrs Comma separated list of addresses. .SS SHOW DNS_ZONES Show DNS zones in cache. .TP zonename Zone name. .TP serial Current serial. .TP count Host names belonging to this zone. .SS SHOW VERSION Show the PgBouncer version string. .SS SHOW STATE Show the PgBouncer state settings. Current states are active, paused and suspended. .SS Process controlling commands .SS PAUSE [db] PgBouncer tries to disconnect from all servers. Disconnecting each server connection waits for that server connection to be released according to the server pool\[cq]s pooling mode (in transaction pooling mode, the transaction must complete, in statement mode, the statement must complete, and in session pooling mode the client must disconnect). The command will not return before all server connections have been disconnected. To be used at the time of database restart. .PP If database name is given, only that database will be paused. .PP New client connections to a paused database will wait until \f[B]RESUME\f[R] is called. .SS DISABLE db Reject all new client connections on the given database. .SS ENABLE db Allow new client connections after a previous \f[B]DISABLE\f[R] command. .SS RECONNECT [db] Close each open server connection for the given database, or all databases, after it is released (according to the pooling mode), even if its lifetime is not up yet. New server connections can be made immediately and will connect as necessary according to the pool size settings. .PP This command is useful when the server connection setup has changed, for example to perform a gradual switchover to a new server. It is \f[I]not\f[R] necessary to run this command when the connection string in pgbouncer.ini has been changed and reloaded (see \f[B]RELOAD\f[R]) or when DNS resolution has changed, because then the equivalent of this command will be run automatically. This command is only necessary if something downstream of PgBouncer routes the connections. .PP After this command is run, there could be an extended period where some server connections go to an old destination and some server connections go to a new destination. This is likely only sensible when switching read-only traffic between read-only replicas, or when switching between nodes of a multimaster replication setup. If all connections need to be switched at the same time, \f[B]PAUSE\f[R] is recommended instead. To close server connections without waiting (for example, in emergency failover rather than gradual switchover scenarios), also consider \f[B]KILL\f[R]. .SS KILL [db] Immediately drop all client and server connections on the given database or all databases, excluding the admin database. .PP New client connections to a killed database will wait until \f[B]RESUME\f[R] is called. .SS KILL_CLIENT id Immediately kill specified client connection along with any server connections for the given client. The client to kill, is identified by the \f[CR]id\f[R] value that can be found using the \f[CR]SHOW CLIENTS\f[R] command. .PP An example command will look something like \f[CR]KILL_CLIENT 1234\f[R]. .SS SUSPEND All socket buffers are flushed and PgBouncer stops listening for data on them. The command will not return before all buffers are empty. To be used at the time of PgBouncer online reboot. .PP New client connections to a suspended database will wait until \f[B]RESUME\f[R] is called. .SS RESUME [db] Resume work from previous \f[B]KILL\f[R], \f[B]PAUSE\f[R], or \f[B]SUSPEND\f[R] command. .SS SHUTDOWN The PgBouncer process will exit. .SS SHUTDOWN WAIT_FOR_SERVERS Stop accepting new connections and shutdown after all servers are released. This is basically the same as issuing \f[B]PAUSE\f[R] and \f[B]SHUTDOWN\f[R], except that this also stops accepting new connections while waiting for the \f[B]PAUSE\f[R] as well as eagerly disconnecting clients that are waiting to receive a server connection. Please note that UNIX sockets will remain open during the shutdown but will only accept connections to the PgBouncer admin console. .SS SHUTDOWN WAIT_FOR_CLIENTS Stop accepting new connections and shutdown the process once all existing clients have disconnected. Please note that UNIX sockets will remain open during the shutdown but will only accept connections to the pgbouncer admin console. This command can be used to do zero-downtime rolling restart of two PgBouncer processes using the following procedure: .IP "1." 3 Have two or more PgBouncer processes running on the same port using \f[CR]so_reuseport\f[R] (configuring peering is recommended, but not required). To achieve zero downtime when restarting we\[cq]ll restart these processes one-by-one, thus leaving the others running to accept connections while one is being restarted. .IP "2." 3 Pick a process to restart first, let\[cq]s call it A. .IP "3." 3 Run \f[CR]SHUTDOWN WAIT_FOR_CLIENTS\f[R] (or send \f[CR]SIGTERM\f[R]) to process A. .IP "4." 3 Cause all clients to reconnect. Possibly by waiting some time until the client side pooler causes reconnects due to its \f[CR]server_idle_timeout\f[R] (or similar config). Or if no client side pooler is used, possibly by restarting the clients. Once all clients have reconnected. Process A will exit automatically, because no clients are connected to it anymore. .IP "5." 3 Start process A again. .IP "6." 3 Repeat step 3, 4 and 5 for each of the remaining processes, one-by-one until you restarted all processes. .SS RELOAD The PgBouncer process will reload its configuration files and update changeable settings. This includes the main configuration file as well as the files specified by the settings \f[CR]auth_file\f[R] and \f[CR]auth_hba_file\f[R]. .PP PgBouncer notices when a configuration file reload changes the connection parameters of a database definition. An existing server connection to the old destination will be closed when the server connection is next released (according to the pooling mode), and new server connections will immediately use the updated connection parameters. .SS WAIT_CLOSE [db] Wait until all server connections, either of the specified database or of all databases, have cleared the \[lq]close_needed\[rq] state (see \f[B]SHOW SERVERS\f[R]). This can be called after a \f[B]RECONNECT\f[R] or \f[B]RELOAD\f[R] to wait until the respective configuration change has been fully activated, for example in switchover scripts. .SS Other commands .SS SET key = arg Changes a configuration setting (see also \f[B]SHOW CONFIG\f[R]). For example: .IP .EX SET log_connections = 1; SET server_check_query = \[aq]select 2\[aq]; .EE .PP (Note that this command is run on the PgBouncer admin console and sets PgBouncer settings. A \f[B]SET\f[R] command run on another database will be passed to the PostgreSQL backend like any other SQL command.) .SS Signals .TP SIGHUP Reload config. Same as issuing the command \f[B]RELOAD\f[R] on the console. .TP SIGTERM Super safe shutdown. Wait for all existing clients to disconnect, but don\[cq]t accept new connections. This is the same as issuing \f[B]SHUTDOWN WAIT_FOR_CLIENTS\f[R] on the console. If this signal is received while there is already a shutdown in progress, then an \[lq]immediate shutdown\[rq] is triggered instead of a \[lq]super safe shutdown\[rq]. In PgBouncer versions earlier than 1.23.0, this signal would cause an \[lq]immediate shutdown\[rq]. .TP SIGINT Safe shutdown. Same as issuing \f[B]SHUTDOWN WAIT_FOR_SERVERS\f[R] on the console. If this signal is received while there is already a shutdown in progress, then an \[lq]immediate shutdown\[rq] is triggered instead of a \[lq]safe shutdown\[rq]. .TP SIGQUIT Immediate shutdown. Same as issuing \f[B]SHUTDOWN\f[R] on the console. .TP SIGUSR1 Same as issuing \f[B]PAUSE\f[R] on the console. .TP SIGUSR2 Same as issuing \f[B]RESUME\f[R] on the console. .SS Libevent settings From the Libevent documentation: .RS .PP It is possible to disable support for epoll, kqueue, devpoll, poll or select by setting the environment variable EVENT_NOEPOLL, EVENT_NOKQUEUE, EVENT_NODEVPOLL, EVENT_NOPOLL or EVENT_NOSELECT, respectively. .PP By setting the environment variable EVENT_SHOW_METHOD, libevent displays the kernel notification method that it uses. .RE .SH SEE ALSO pgbouncer(5) - man page of configuration settings descriptions .PP pgbouncer.50000644000000000000000000017411315203352661011640 0ustar rootroot.\" Automatically generated by Pandoc 3.1.8 .\" .TH "PGBOUNCER.INI" "5" "" "1.25.2" "Databases" .SH NAME pgbouncer.ini - configuration file for pgbouncer .SH DESCRIPTION The configuration file is in \[lq]ini\[rq] format. Section names are between \[lq][\[rq] and \[rq]]\[rq]. Lines starting with \[lq];\[rq] or \[lq]#\[rq] are taken as comments and ignored. The characters \[lq];\[rq] and \[lq]#\[rq] are not recognized as special when they appear later in the line. .SH GENERIC SETTINGS .SS logfile Specifies the log file. For daemonization (\f[CR]-d\f[R]), either this or \f[CR]syslog\f[R] need to be set. .PP The log file is kept open, so after rotation, \f[CR]kill -HUP\f[R] or on console \f[CR]RELOAD;\f[R] should be done. On Windows, the service must be stopped and started. .PP Note that setting \f[CR]logfile\f[R] does not by itself turn off logging to stderr. Use the command-line option \f[CR]-q\f[R] or \f[CR]-d\f[R] for that. .PP Default: not set .SS pidfile Specifies the PID file. Without \f[CR]pidfile\f[R] set, daemonization (\f[CR]-d\f[R]) is not allowed. .PP Default: not set .SS listen_addr Specifies a list (comma-separated) of addresses where to listen for TCP connections. You may also use \f[CR]*\f[R] meaning \[lq]listen on all addresses\[rq]. When not set, only Unix socket connections are accepted. .PP Addresses can be specified numerically (IPv4/IPv6) or by name. .PP Default: not set .SS listen_port Which port to listen on. Applies to both TCP and Unix sockets. .PP Default: 6432 .SS unix_socket_dir Specifies the location for Unix sockets. Applies to both the listening socket and to server connections. If set to an empty string, Unix sockets are disabled. A value that starts with \f[CR]\[at]\f[R] specifies that a Unix socket in the abstract namespace should be created (currently supported on Linux and Windows). .PP For online reboot (\f[CR]-R\f[R]) to work, a Unix socket needs to be configured, and it needs to be in the file-system namespace. .PP Default: \f[CR]/tmp\f[R] (empty on Windows) .SS unix_socket_mode File system mode for Unix socket. Ignored for sockets in the abstract namespace. Not supported on Windows. .PP Default: 0777 .SS unix_socket_group Group name to use for Unix socket. Ignored for sockets in the abstract namespace. Not supported on Windows. .PP Default: not set .SS user If set, specifies the Unix user to change to after startup. Works only if PgBouncer is started as root or if it\[cq]s already running as the given user. Not supported on Windows. .PP Default: not set .SS pool_mode Specifies when a server connection can be reused by other clients. .TP session Server is released back to pool after client disconnects. Default. .TP transaction Server is released back to pool after transaction finishes. .TP statement Server is released back to pool after query finishes. Transactions spanning multiple statements are disallowed in this mode. .SS max_client_conn Maximum number of client connections allowed. .PP When this setting is increased, then the file descriptor limits in the operating system might also have to be increased. Note that the number of file descriptors potentially used is more than \f[CR]max_client_conn\f[R]. If each user connects under its own user name to the server, the theoretical maximum used is: .IP .EX max_client_conn + (max pool_size * total databases * total users) .EE .PP If a database user is specified in the connection string (all users connect under the same user name), the theoretical maximum is: .IP .EX max_client_conn + (max pool_size * total databases) .EE .PP The theoretical maximum should never be reached, unless somebody deliberately crafts a special load for it. Still, it means you should set the number of file descriptors to a safely high number. .PP Search for \f[CR]ulimit\f[R] in your favorite shell man page. Note: \f[CR]ulimit\f[R] does not apply in a Windows environment. .PP Default: 100 .SS default_pool_size The maximum number of server connections to allow per user/database pair. Can be overridden by \f[CR]pool_size\f[R] in the per-database and per-user configuration; this is the default used if no specific \f[CR]pool_size\f[R] is specified for a given database or user. .PP Default: 20 .SS min_pool_size Add more server connections to pool if below this number. Improves behavior when the normal load suddenly comes back after a period of total inactivity. The value is effectively capped at the pool size. .PP Only enforced for pools where at least one of the following is true: .IP \[bu] 2 the entry in the \f[CR][database]\f[R] section for the pool has a value set for the \f[CR]user\f[R] key (aka forced user) .IP \[bu] 2 there is at least one client connected to the pool .PP Default: 0 (disabled) .SS reserve_pool_size How many additional connections to allow to a pool (see \f[CR]reserve_pool_timeout\f[R]). 0 disables. .PP Default: 0 (disabled) .SS reserve_pool_timeout If a client has not been serviced in this time, use additional connections from the reserve pool. 0 disables. [seconds] .PP Default: 5.0 .SS max_db_connections Do not allow more than this many server connections per database (regardless of user). This considers the PgBouncer database that the client has connected to, not the PostgreSQL database of the outgoing connection. .PP This can also be set per database in the \f[CR][databases]\f[R] section. .PP Note that when you hit the limit, closing a client connection to one pool will not immediately allow a server connection to be established for another pool, because the server connection for the first pool is still open. Once the server connection closes (due to idle timeout), a new server connection will immediately be opened for the waiting pool. .PP Default: 0 (unlimited) .SS max_db_client_connections Do not allow more than this many client connections to PgBouncer per database (regardless of user). This considers the PgBouncer database that the client has connected to, not the PostgreSQL database of the outgoing connection. .PP This should be set at a number greater than or equal to max_db_connections. The difference between the two numbers can be thought of as how many connections to a given database can be in the queue while waiting for active connections to finish. .PP This can also be set per database in the \f[CR][databases]\f[R] section. .PP Default: 0 (unlimited) .SS max_user_connections Do not allow more than this many server connections per user (regardless of database). This considers the PgBouncer user that is associated with a pool, which is either the user specified for the server connection or in absence of that the user the client has connected as. .PP This can also be set per user in the \f[CR][users]\f[R] section. .PP Note that when you hit the limit, closing a client connection to one pool will not immediately allow a server connection to be established for another pool, because the server connection for the first pool is still open. Once the server connection closes (due to idle timeout), a new server connection will immediately be opened for the waiting pool. .PP Default: 0 (unlimited) .SS max_user_client_connections Do not allow more than this many client connections per user (regardless of database). This value should be set to a number higher than max_user_connections. This difference between max_user_connections and max_user_client_connections can be conceptualized as the number the max size of the queue for the user. .PP This can also be set per user in the \f[CR][users]\f[R] section. .PP Default: 0 (unlimited) .SS server_round_robin By default, PgBouncer reuses server connections in LIFO (last-in, first-out) manner, so that few connections get the most load. This gives best performance if you have a single server serving a database. But if there is a round-robin system behind a database address (TCP, DNS, or host list), then it is better if PgBouncer also uses connections in that manner, thus achieving uniform load. .PP Default: 0 .SS track_extra_parameters By default, PgBouncer tracks \f[CR]client_encoding\f[R], \f[CR]datestyle\f[R], \f[CR]timezone\f[R], \f[CR]standard_conforming_strings\f[R] and \f[CR]application_name\f[R] parameters per client. To allow other parameters to be tracked, they can be specified here, so that PgBouncer knows that they should be maintained in the client variable cache and restored in the server whenever the client becomes active. .PP If you need to specify multiple values, use a comma-separated list (e.g. \f[CR]default_transaction_read_only, IntervalStyle\f[R]) .PP Note: Most parameters cannot be tracked this way. The only parameters that can be tracked are ones that Postgres reports to the client. Postgres has an official list of parameters that it reports to the client (https://www.postgresql.org/docs/15/protocol-flow.html#PROTOCOL-ASYNC). Postgres extensions can change this list though, they can add parameters themselves that they also report, and they can start reporting already existing parameters that Postgres does not report. Notably Citus 12.0+ causes Postgres to also report \f[CR]search_path\f[R]. .PP The Postgres protocol allows specifying parameters settings, both directly as a parameter in the startup packet, or inside the \f[CR]options\f[R] startup packet (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS). Parameters specified using both of these methods are supported by \f[CR]track_extra_parameters\f[R]. However, it\[cq]s not possible to include \f[CR]options\f[R] itself in \f[CR]track_extra_parameters\f[R], only the parameters contained in \f[CR]options\f[R]. .PP Default: IntervalStyle .SS ignore_startup_parameters By default, PgBouncer allows only parameters it can keep track of in startup packets: \f[CR]client_encoding\f[R], \f[CR]datestyle\f[R], \f[CR]timezone\f[R] and \f[CR]standard_conforming_strings\f[R]. All others parameters will raise an error. To allow others parameters, they can be specified here, so that PgBouncer knows that they are handled by the admin and it can ignore them. .PP If you need to specify multiple values, use a comma-separated list (e.g. \f[CR]options,extra_float_digits\f[R]) .PP The Postgres protocol allows specifying parameters settings, both directly as a parameter in the startup packet, or inside the \f[CR]options\f[R] startup packet (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS). Parameters specified using both of these methods are supported by \f[CR]ignore_startup_parameters\f[R]. It\[cq]s even possible to include \f[CR]options\f[R] itself in \f[CR]track_extra_parameters\f[R], which results in any unknown parameters contained inside \f[CR]options\f[R] to be ignored. .PP Default: empty .SS peer_id The peer id used to identify this PgBouncer process in a group of PgBouncer processes that are peered together. The \f[CR]peer_id\f[R] value should be unique within a group of peered PgBouncer processes. When set to 0 PgBouncer peering is disabled. See the docs for the \f[CR][peers]\f[R] section for more information. The maximum value that can be used for the \f[CR]peer_id\f[R] is 16383. .PP Default: 0 .SS disable_pqexec Disable the Simple Query protocol (PQexec). Unlike the Extended Query protocol, Simple Query allows multiple queries in one packet, which allows some classes of SQL-injection attacks. Disabling it can improve security. Obviously, this means only clients that exclusively use the Extended Query protocol will stay working. .PP Default: 0 .SS application_name_add_host Add the client host address and port to the application name setting set on connection start. This helps in identifying the source of bad queries etc. This logic applies only at the start of a connection. If \f[CR]application_name\f[R] is later changed with \f[CR]SET\f[R], PgBouncer does not change it again. .PP Default: 0 .SS conffile Show location of current config file. Changing it will make PgBouncer use another config file for next \f[CR]RELOAD\f[R] / \f[CR]SIGHUP\f[R]. .PP Default: file from command line .SS service_name Used on win32 service registration. .PP Default: \f[CR]pgbouncer\f[R] .SS job_name Alias for \f[CR]service_name\f[R]. .SS stats_period Sets how often the averages shown in various \f[CR]SHOW\f[R] commands are updated and how often aggregated statistics are written to the log (but see \f[CR]log_stats\f[R]). [seconds] .PP Default: 60 .SS max_prepared_statements When this is set to a non-zero value PgBouncer tracks protocol-level named prepared statements related commands sent by the client in transaction and statement pooling mode. PgBouncer makes sure that any statement prepared by a client is available on the backing server connection. Even when the statement was originally prepared on another server connection. .PP PgBouncer internally examines all the queries that are sent by clients as a prepared statement, and gives each unique query string an internal name with the format \f[CR]PGBOUNCER_{unique_id}\f[R]. If the same query string is prepared multiple times (possibly by different clients), then these queries share the same internal name. PgBouncer only prepares the statement on the actual PostgreSQL server using the internal name (so not the name provided by the client). PgBouncer keeps track of the name that the client gave to each prepared statement. It then rewrites each command that uses a prepared statement to by replacing the client side name with the internal name (e.g. replacing \f[CR]my_prepared_statement\f[R] with \f[CR]PGBOUNCER_123\f[R]) before forwarding that command to the server. More importantly, if the prepared statement that the client wants to execute is not yet prepared on the server (e.g.\ because a different server is now assigned to the client than when the client prepared the statement), then PgBouncer transparently prepares the statement before executing it. .PP Note: This tracking and rewriting of prepared statement commands does not work for SQL-level prepared statement commands, so \f[CR]PREPARE\f[R], \f[CR]EXECUTE\f[R] and \f[CR]DEALLOCATE\f[R] are forwarded straight to Postgres. The exception to this rule are the \f[CR]DEALLOCATE ALL\f[R] and \f[CR]DISCARD ALL\f[R] commands, these do work as expected and will clear the prepared statements that PgBouncer tracked for the client that sends this command. .PP The actual value of this setting controls the number of prepared statements kept active in an LRU cache on a single server connection. When the setting is set to 0 prepared statement support for transaction and statement pooling is disabled. To get the best performance you should try to make sure that this setting is larger than the amount of commonly used prepared statements in your application. Keep in mind that the higher this value, the larger the memory footprint of each PgBouncer connection will be on your PostgreSQL server, because it will keep more queries prepared on those connections. It also increases the memory footprint of PgBouncer itself, because it now needs to keep track of query strings. .PP The impact on PgBouncer memory usage is not that big though: - Each unique query is stored once in a global query cache. - Each client connection keeps a buffer that it uses to rewrite packets. This is, at most, 4 times the size of \f[CR]pkt_buf\f[R]. This limit is often not reached though, it only happens when the queries in your prepared statements are between 2 and 4 times the size of \f[CR]pkt_buf\f[R]. .PP So if you consider the following as an example scenario: - There are 1000 active clients - The clients prepare 200 unique queries - The average size of a query is 5kB - \f[CR]pkt_buf\f[R] parameter is set to the default of 4096 (4kB) .PP Then, PgBouncer needs at most the following amount of memory to handle these prepared statements: .PP 200 x 5kB + 1000 x 4 x 4kB = \[ti]17MB of memory. .PP Tracking prepared statements does not only come with a memory cost, but also with increased CPU usage, because PgBouncer needs to inspect and rewrite the queries. Multiple PgBouncer instances can listen on the same port to use more than one core for processing, see the documentation for the \f[CR]so_reuseport\f[R] option for details. .PP But of course there are also performance benefits to prepared statements. Just as when connecting to PostgreSQL directly, by preparing a query that is executed many times, it reduces the total amount of parsing and planning that needs to be done. The way that PgBouncer tracks prepared statements is especially beneficial to performance when multiple clients prepare the same queries. Because client connections automatically reuse a prepared statement on a server connection, even if it was prepared by another client. As an example, if you have a \f[CR]pool_size\f[R] of 20 and you have 100 clients that all prepare the exact same query, then the query is prepared (and thus parsed) only 20 times on the PostgreSQL server. .PP The reuse of prepared statements has one downside. If the return or argument types of a prepared statement changes across executions then PostgreSQL currently throws an error such as: .IP .EX ERROR: cached plan must not change result type .EE .PP You can avoid such errors by not having multiple clients that use the exact same query string in a prepared statement, but expecting different argument or result types. One of the most common ways of running into this issue is during a DDL migration where you add a new column or change a column type on an existing table. In those cases you can run \f[CR]RECONNECT\f[R] on the PgBouncer admin console after doing the migration to force a re-prepare of the query and make the error go away. .PP Default: 200 .SS scram_iterations The number of computational iterations to be performed when encrypting a password using SCRAM-SHA-256. A higher number of iterations provides additional protection against brute-force attacks on stored passwords, but makes authentication slower. .PP Default: 4096 .SH AUTHENTICATION SETTINGS PgBouncer handles its own client authentication and has its own database of users. These settings control this. .SS auth_type How to authenticate users. .TP cert Client must connect over TLS connection with a valid client certificate. The user name is then taken from the CommonName field from the certificate. .TP md5 Use MD5-based password check. This is the default authentication method. \f[CR]auth_file\f[R] may contain both MD5-encrypted and plain-text passwords. If \f[CR]md5\f[R] is configured and a user has a SCRAM secret, then SCRAM authentication is used automatically instead. .TP scram-sha-256 Use password check with SCRAM-SHA-256. \f[CR]auth_file\f[R] has to contain SCRAM secrets or plain-text passwords. .TP plain The clear-text password is sent over the wire. Deprecated. .TP trust No authentication is done. The user name must still exist in \f[CR]auth_file\f[R]. .TP any Like the \f[CR]trust\f[R] method, but the user name given is ignored. Requires that all databases are configured to log in as a specific user. Additionally, the console database allows any user to log in as admin. .TP hba The actual authentication type is loaded from \f[CR]auth_hba_file\f[R]. This allows different authentication methods for different access paths, for example: connections over Unix socket use the \f[CR]peer\f[R] authentication method, connections over TCP must use TLS. .TP ldap Users are authenticated against an LDAP server, like in PostgreSQL (see for details). The LDAP connection options are configured using the setting \f[CR]auth_ldap_options\f[R], or alternatively in the \f[CR]auth_hba_file\f[R]. .TP pam PAM is used to authenticate users, \f[CR]auth_file\f[R] is ignored. This method is not compatible with databases using the \f[CR]auth_user\f[R] option. The service name reported to PAM is \[lq]pgbouncer\[rq]. \f[CR]pam\f[R] is not supported in the HBA configuration file. .SS auth_hba_file HBA configuration file to use when \f[CR]auth_type\f[R] is \f[CR]hba\f[R]. See section HBA file format below about details. .PP Default: not set .SS auth_ident_file Identity map file to use when \f[CR]auth_type\f[R] is \f[CR]hba\f[R] and a user map will be defined. See section Ident map file format below about details. .PP Default: not set .SS auth_file The name of the file to load user names and passwords from. See section Authentication file format below about details. .PP Most authentication types (see above) require that either \f[CR]auth_file\f[R] or \f[CR]auth_user\f[R] be set; otherwise there would be no users defined. .PP Default: not set .SS auth_user If \f[CR]auth_user\f[R] is set, then any user not specified in \f[CR]auth_file\f[R] will be queried through the \f[CR]auth_query\f[R] query from \f[CR]pg_authid\f[R] in the database, using \f[CR]auth_user\f[R]. The password of \f[CR]auth_user\f[R] will be taken from \f[CR]auth_file\f[R]. (If the \f[CR]auth_user\f[R] does not require a password then it does not need to be defined in \f[CR]auth_file\f[R].) .PP Direct access to \f[CR]pg_authid\f[R] requires admin rights. It\[cq]s preferable to use a non-superuser that calls a SECURITY DEFINER function instead. .PP Default: not set .SS auth_query Query to load user\[cq]s password from database. .PP Direct access to \f[CR]pg_authid\f[R] requires admin rights. It\[cq]s preferable to use a non-superuser that calls a SECURITY DEFINER function instead. .PP Note that the query is run inside the target database. So if a function is used, it needs to be installed into each database. .PP Default: \f[CR]SELECT rolname, CASE WHEN rolvaliduntil < now() THEN NULL ELSE rolpassword END FROM pg_authid WHERE rolname=$1 AND rolcanlogin\f[R] .SS auth_dbname Database name in the \f[CR][database]\f[R] section to be used for authentication purposes. This option can be either global or overridden in the connection string if this parameter is specified. .SS auth_ldap_options LDAP connection options to use if \f[CR]auth_type\f[R] is \f[CR]ldap\f[R]. (Not used if authentication is configured via \f[CR]auth_hba_file\f[R].) Example: .IP .EX auth_ldap_options = ldapurl=\[dq]ldap://127.0.0.1:12345/dc=example,dc=net?uid?sub\[dq] .EE .SH LOG SETTINGS .SS syslog Toggles syslog on/off. On Windows, the event log is used instead. .PP Default: 0 .SS syslog_ident Under what name to send logs to syslog. .PP Default: \f[CR]pgbouncer\f[R] (program name) .SS syslog_facility Under what facility to send logs to syslog. Possibilities: \f[CR]auth\f[R], \f[CR]authpriv\f[R], \f[CR]daemon\f[R], \f[CR]user\f[R], \f[CR]local0-7\f[R]. .PP Default: \f[CR]daemon\f[R] .SS log_connections Log successful logins. .PP Default: 1 .SS log_disconnections Log disconnections with reasons. .PP Default: 1 .SS log_pooler_errors Log error messages the pooler sends to clients. .PP Default: 1 .SS log_stats Write aggregated statistics into the log, every \f[CR]stats_period\f[R]. This can be disabled if external monitoring tools are used to grab the same data from \f[CR]SHOW\f[R] commands. .PP Default: 1 .SS verbose Increase verbosity. Mirrors the \[lq]-v\[rq] switch on the command line. For example, using \[lq]-v -v\[rq] on the command line is the same as \f[CR]verbose=2\f[R]. 3 is the highest currently-supported verbosity. .PP Default: 0 .SH CONSOLE ACCESS CONTROL .SS admin_users Comma-separated list of database users that are allowed to connect and run all commands on the console. Ignored when \f[CR]auth_type\f[R] is \f[CR]any\f[R], in which case any user name is allowed in as admin. .PP Default: empty .SS stats_users Comma-separated list of database users that are allowed to connect and run read-only queries on the console. That means all \f[CR]SHOW\f[R] commands except \f[CR]SHOW FDS\f[R]. .PP Default: empty .SH CONNECTION SANITY CHECKS, TIMEOUTS .SS server_reset_query Query sent to server on connection release, before making it available to other clients. At that moment no transaction is in progress, so the value should not include \f[CR]ABORT\f[R] or \f[CR]ROLLBACK\f[R]. .PP The query is supposed to clean any changes made to the database session so that the next client gets the connection in a well-defined state. The default is \f[CR]DISCARD ALL\f[R], which cleans everything, but that leaves the next client no pre-cached state. It can be made lighter, e.g.\ \f[CR]DEALLOCATE ALL\f[R] to just drop prepared statements, if the application does not break when some state is kept around. .PP When transaction pooling is used, the \f[CR]server_reset_query\f[R] is not used, because in that mode, clients must not use any session-based features, since each transaction ends up in a different connection and thus gets a different session state. .PP Default: \f[CR]DISCARD ALL\f[R] .SS server_reset_query_always Whether \f[CR]server_reset_query\f[R] should be run in all pooling modes. When this setting is off (default), the \f[CR]server_reset_query\f[R] will be run only in pools that are in sessions-pooling mode. Connections in transaction-pooling mode should not have any need for a reset query. .PP This setting is for working around broken setups that run applications that use session features over a transaction-pooled PgBouncer. It changes non-deterministic breakage to deterministic breakage: Clients always lose their state after each transaction. .PP Default: 0 .SS server_check_delay How long to keep released connections available for immediate re-use, without running \f[CR]server_check_query\f[R] on it. If 0 then the check is always run. .PP Default: 30.0 .SS server_check_query Simple do-nothing query to check if the server connection is alive. .PP If an empty string, then sanity checking is disabled. .PP If \f[CR]\f[R] then send empty query as sanity check. .PP Default: \f[CR]\f[R] .SS server_fast_close Disconnect a server in session pooling mode immediately or after the end of the current transaction if it is in \[lq]close_needed\[rq] mode (set by \f[CR]RECONNECT\f[R], \f[CR]RELOAD\f[R] that changes connection settings, or DNS change), rather than waiting for the session end. In statement or transaction pooling mode, this has no effect since that is the default behavior there. .PP If because of this setting a server connection is closed before the end of the client session, the client connection is also closed. This ensures that the client notices that the session has been interrupted. .PP This setting makes connection configuration changes take effect sooner if session pooling and long-running sessions are used. The downside is that client sessions are liable to be interrupted by a configuration change, so client applications will need logic to reconnect and reestablish session state. But note that no transactions will be lost, because running transactions are not interrupted, only idle sessions. .PP Default: 0 .SS server_lifetime The pooler will close an unused (not currently linked to any client connection) server connection that has been connected longer than this. Setting it to 0 means the connection is to be used only once, then closed. [seconds] .PP This can also be set per database in the \f[CR][databases]\f[R] section. .PP Default: 3600.0 .SS server_idle_timeout If a server connection has been idle more than this many seconds it will be closed. If 0 then this timeout is disabled. [seconds] .PP Default: 600.0 .SS server_connect_timeout If connection and login don\[cq]t finish in this amount of time, the connection will be closed. [seconds] .PP Default: 15.0 .SS server_login_retry If login to the server failed, because of failure to connect or from authentication, the pooler waits this much before retrying to connect. During the waiting interval, new clients trying to connect to the failing server will get an error immediately without another connection attempt. [seconds] .PP The purpose of this behavior is that clients don\[cq]t unnecessarily queue up waiting for a server connection to become available if the server is not working. However, it also means that if a server is momentarily failing, for example during a restart or if the configuration was erroneous, then it will take at least this long until the pooler will consider connecting to it again. Planned events such as restarts should normally be managed using the \f[CR]PAUSE\f[R] command to avoid this. .PP Default: 15.0 .SS client_login_timeout If a client connects but does not manage to log in in this amount of time, it will be disconnected. Mainly needed to avoid dead connections stalling \f[CR]SUSPEND\f[R] and thus online restart. [seconds] .PP Default: 60.0 .SS autodb_idle_timeout If the automatically created (via \[lq]*\[lq]) database pools have been unused this many seconds, they are freed. The negative aspect of that is that their statistics are also forgotten. [seconds] .PP Default: 3600.0 .SS dns_max_ttl How long DNS lookups can be cached. The actual DNS TTL is ignored. [seconds] .PP Default: 15.0 .SS dns_nxdomain_ttl How long DNS errors and NXDOMAIN DNS lookups can be cached. [seconds] .PP Default: 15.0 .SS dns_zone_check_period Period to check if a zone serial has changed. .PP PgBouncer can collect DNS zones from host names (everything after first dot) and then periodically check if the zone serial changes. If it notices changes, all host names under that zone are looked up again. If any host IP changes, its connections are invalidated. .PP Works only with c-ares backend (\f[CR]configure\f[R] option \f[CR]--with-cares\f[R]). .PP Default: 0.0 (disabled) .SS resolv_conf The location of a custom \f[CR]resolv.conf\f[R] file. This is to allow specifying custom DNS servers and perhaps other name resolution options, independent of the global operating system configuration. .PP Requires evdns (>= 2.0.3) or c-ares (>= 1.15.0) backend. .PP The parsing of the file is done by the DNS backend library, not PgBouncer, so see the library\[cq]s documentation for details on allowed syntax and directives. .PP Default: empty (use operating system defaults) .SS query_wait_notify Time that a client will be queued for before PgBouncer sends a notification message that they are being queued. [seconds] .PP A value of 0 disables this notification message. .PP Default: 5 .SH TLS SETTINGS If the contents of any of the cert or key files are changed without changing the actual setting filename in the config, the new file contents will be used for new connections after a RELOAD. Existing connections won\[cq]t be closed though. If it\[cq]s necessary for security reasons that all connections start using the new files ASAP, it\[cq]s advised to run RECONNECT after the RELOAD. .PP Changing any TLS settings will trigger a RECONNECT automatically for security reasons. .SS client_tls_sslmode TLS mode to use for connections from clients. TLS connections are disabled by default. When enabled, \f[CR]client_tls_key_file\f[R] and \f[CR]client_tls_cert_file\f[R] must be also configured to set up the key and certificate PgBouncer uses to accept client connections. The most common certificate file format usable by PgBouncer is PEM. .TP disable Plain TCP. If client requests TLS, it\[cq]s ignored. Default. .TP allow If client requests TLS, it is used. If not, plain TCP is used. If the client presents a client certificate, it is not validated. .TP prefer Same as \f[CR]allow\f[R]. .TP require Client must use TLS. If not, the client connection is rejected. If the client presents a client certificate, it is not validated. .TP verify-ca Client must use TLS with valid client certificate. .TP verify-full Same as \f[CR]verify-ca\f[R]. .SS client_tls_key_file Private key for PgBouncer to accept client connections. .PP Default: not set .SS client_tls_cert_file Certificate for private key. Clients can validate it. .PP Default: not set .SS client_tls_ca_file Root certificate file to validate client certificates. .PP Default: not set .SS client_tls_protocols Which TLS protocol versions are allowed. Allowed values: \f[CR]tlsv1.0\f[R], \f[CR]tlsv1.1\f[R], \f[CR]tlsv1.2\f[R], \f[CR]tlsv1.3\f[R]. Shortcuts: \f[CR]all\f[R] (tlsv1.0,tlsv1.1,tlsv1.2,tlsv1.3), \f[CR]secure\f[R] (tlsv1.2,tlsv1.3). .PP Default: \f[CR]secure\f[R] .SS client_tls_ciphers Allowed TLS ciphers, in OpenSSL syntax. Shortcuts: .IP \[bu] 2 \f[CR]default\f[R]/\f[CR]secure\f[R]/\f[CR]fast\f[R]/\f[CR]normal\f[R] (these all use system wide OpenSSL defaults) .IP \[bu] 2 \f[CR]all\f[R] (enables all ciphers, not recommended) .PP Only connections using TLS version 1.2 and lower are affected. For version 1.3 see \f[CR]client_tls13_ciphers\f[R] below. .PP Default: \f[CR]default\f[R] .SS client_tls13_ciphers Allowed TLS v1.3 ciphers. When empty it will use the value of \f[CR]client_tls_ciphers\f[R]. Allowed values: .IP \[bu] 2 TLS_AES_256_GCM_SHA384 .IP \[bu] 2 TLS_CHACHA20_POLY1305_SHA256 .IP \[bu] 2 TLS_AES_128_GCM_SHA256 .IP \[bu] 2 TLS_AES_128_CCM_8_SHA256 .IP \[bu] 2 TLS_AES_128_CCM_SHA256 .PP Only connections using TLS version 1.3 and higher are affected. For version 1.2 and lower see \f[CR]client_tls_ciphers\f[R]. .PP Default: \f[CR]\f[R] .SS client_tls_ecdhcurve Elliptic Curve name to use for ECDH key exchanges. .PP Allowed values: \f[CR]none\f[R] (DH is disabled), \f[CR]auto\f[R] (256-bit ECDH), curve name .PP Default: \f[CR]auto\f[R] .SS client_tls_dheparams DHE key exchange type. .PP Allowed values: \f[CR]none\f[R] (DH is disabled), \f[CR]auto\f[R] (2048-bit DH), \f[CR]legacy\f[R] (1024-bit DH) .PP Default: \f[CR]auto\f[R] .SS server_tls_sslmode TLS mode to use for connections to PostgreSQL servers. The default mode is \f[CR]prefer\f[R]. .TP disable Plain TCP. TLS is not even requested from the server. .TP allow FIXME: if server rejects plain, try TLS? .TP prefer TLS connection is always requested first from PostgreSQL. If refused, the connection will be established over plain TCP. Server certificate is not validated. Default .TP require Connection must go over TLS. If server rejects it, plain TCP is not attempted. Server certificate is not validated. .TP verify-ca Connection must go over TLS and server certificate must be valid according to \f[CR]server_tls_ca_file\f[R]. Server host name is not checked against certificate. .TP verify-full Connection must go over TLS and server certificate must be valid according to \f[CR]server_tls_ca_file\f[R]. Server host name must match certificate information. .SS server_tls_ca_file Root certificate file to validate PostgreSQL server certificates. .PP Default: not set .SS server_tls_key_file Private key for PgBouncer to authenticate against PostgreSQL server. .PP Default: not set .SS server_tls_cert_file Certificate for private key. PostgreSQL server can validate it. .PP Default: not set .SS server_tls_protocols Which TLS protocol versions are allowed. Allowed values: \f[CR]tlsv1.0\f[R], \f[CR]tlsv1.1\f[R], \f[CR]tlsv1.2\f[R], \f[CR]tlsv1.3\f[R]. Shortcuts: \f[CR]all\f[R] (tlsv1.0,tlsv1.1,tlsv1.2,tlsv1.3), \f[CR]secure\f[R] (tlsv1.2,tlsv1.3), \f[CR]legacy\f[R] (all). .PP Default: \f[CR]secure\f[R] .SS server_tls_ciphers Allowed TLS ciphers, in OpenSSL syntax. Shortcuts: .IP \[bu] 2 \f[CR]default\f[R]/\f[CR]secure\f[R]/\f[CR]fast\f[R]/\f[CR]normal\f[R] (these all use system wide OpenSSL defaults) .IP \[bu] 2 \f[CR]all\f[R] (enables all ciphers, not recommended) .PP Only connections using TLS version 1.2 and lower are affected. For version 1.3 see \f[CR]server_tls13_ciphers\f[R] below. .PP Default: \f[CR]default\f[R] .SS server_tls13_ciphers Allowed TLS v1.3 ciphers. When empty it will use the value of \f[CR]server_tls_ciphers\f[R]. Allowed values: .IP \[bu] 2 TLS_AES_256_GCM_SHA384 .IP \[bu] 2 TLS_CHACHA20_POLY1305_SHA256 .IP \[bu] 2 TLS_AES_128_GCM_SHA256 .IP \[bu] 2 TLS_AES_128_CCM_8_SHA256 .IP \[bu] 2 TLS_AES_128_CCM_SHA256 .PP Only connections using TLS version 1.3 and higher are affected. For version 1.2 and lower see \f[CR]client_tls_ciphers\f[R]. .PP Default: \f[CR]\f[R] .SH DANGEROUS TIMEOUTS Setting the following timeouts can cause unexpected errors. .SS query_timeout Queries running longer than that are canceled. This should be used only with a slightly smaller server-side \f[CR]statement_timeout\f[R], to apply only for network problems. [seconds] .PP Default: 0.0 (disabled) .SS query_wait_timeout Maximum time queries are allowed to spend waiting for execution. If the query is not assigned to a server during that time, the client is disconnected. 0 disables. If this is disabled, clients will be queued indefinitely. [seconds] .PP This setting is used to prevent unresponsive servers from grabbing up connections. It also helps when the server is down or rejects connections for any reason. .PP Default: 120.0 .SS cancel_wait_timeout Maximum time cancellation requests are allowed to spend waiting for execution. If the cancel request is not assigned to a server during that time, the client is disconnected. 0 disables. If this is disabled, cancel requests will be queued indefinitely. [seconds] .PP This setting is used to prevent a client locking up when a cancel cannot be forwarded due to the server being down. .PP Default: 10.0 .SS client_idle_timeout Client connections idling longer than this many seconds are closed. This should be larger than the client-side connection lifetime settings, and only used for network problems. [seconds] .PP Default: 0.0 (disabled) .SS idle_transaction_timeout If a client has been in \[lq]idle in transaction\[rq] state longer, it will be disconnected. [seconds] .PP Default: 0.0 (disabled) .SS transaction_timeout If a client has been in \[lq]in transaction\[rq] state longer, it will be disconnected. [seconds] .PP Default: 0.0 (disabled) .SS suspend_timeout How long to wait for buffer flush during \f[CR]SUSPEND\f[R] or reboot (\f[CR]-R\f[R]). A connection is dropped if the flush does not succeed. [seconds] .PP Default: 10 .SH LOW-LEVEL NETWORK SETTINGS .SS pkt_buf Internal buffer size for packets. Affects size of TCP packets sent and general memory usage. Actual libpq packets can be larger than this, so no need to set it large. .PP Default: 4096 .SS max_packet_size Maximum size for PostgreSQL packets that PgBouncer allows through. One packet is either one query or one result set row. The full result set can be larger. .PP Default: 2147483647 .SS listen_backlog Backlog argument for listen(2). Determines how many new unanswered connection attempts are kept in the queue. When the queue is full, further new connections are dropped. .PP Default: 128 .SS sbuf_loopcnt How many times to process data on one connection, before proceeding. Without this limit, one connection with a big result set can stall PgBouncer for a long time. One loop processes one \f[CR]pkt_buf\f[R] amount of data. 0 means no limit. .PP Default: 5 .SS so_reuseport Specifies whether to set the socket option \f[CR]SO_REUSEPORT\f[R] on TCP listening sockets. On some operating systems, this allows running multiple PgBouncer instances on the same host listening on the same port and having the kernel distribute the connections automatically. This option is a way to get PgBouncer to use more CPU cores. (PgBouncer is single-threaded and uses one CPU core per instance.) .PP The behavior in detail depends on the operating system kernel. As of this writing, this setting has the desired effect on (sufficiently recent versions of) Linux, DragonFlyBSD, and FreeBSD. (On FreeBSD, it applies the socket option \f[CR]SO_REUSEPORT_LB\f[R] instead.) Some other operating systems support the socket option but it won\[cq]t have the desired effect: It will allow multiple processes to bind to the same port but only one of them will get the connections. See your operating system\[cq]s setsockopt() documentation for details. .PP On systems that don\[cq]t support the socket option at all, turning this setting on will result in an error. .PP Each PgBouncer instance on the same host needs different settings for at least \f[CR]unix_socket_dir\f[R] and \f[CR]pidfile\f[R], as well as \f[CR]logfile\f[R] if that is used. Also note that if you make use of this option, you can no longer connect to a specific PgBouncer instance via TCP/IP, which might have implications for monitoring and metrics collection. .PP To make sure query cancellations keep working, you should set up PgBouncer peering between the different PgBouncer processes. For details look at docs for the \f[CR]peer_id\f[R] configuration option and the \f[CR]peers\f[R] configuration section. There\[cq]s also an example that uses peering and so_reuseport in the example section of these docs. .PP Default: 0 .SS tcp_defer_accept Sets the \f[CR]TCP_DEFER_ACCEPT\f[R] socket option; see \f[CR]man 7 tcp\f[R] for details. (This is a Boolean option: 1 means enabled. The actual value set if enabled is currently hardcoded to 45 seconds.) .PP This is currently only supported on Linux. .PP Default: 1 on Linux, otherwise 0 .SS tcp_socket_buffer Default: not set .SS tcp_keepalive Turns on basic keepalive with OS defaults. .PP On Linux, the system defaults are tcp_keepidle=7200, tcp_keepintvl=75, tcp_keepcnt=9. They are probably similar on other operating systems. .PP Default: 1 .SS tcp_keepcnt Default: not set .SS tcp_keepidle Default: not set .SS tcp_keepintvl Default: not set .SS tcp_user_timeout Sets the \f[CR]TCP_USER_TIMEOUT\f[R] socket option. This specifies the maximum amount of time in milliseconds that transmitted data may remain unacknowledged before the TCP connection is forcibly closed. If set to 0, then operating system\[cq]s default is used. .PP This is currently only supported on Linux. .PP Default: 0 .SH SECTION [DATABASES] The section \f[CR][databases]\f[R] defines the names of the databases that clients of PgBouncer can connect to and specifies where those connections will be routed. The section contains key=value lines like .IP .EX dbname = connection string .EE .PP where the key will be taken as a database name and the value as a connection string, consisting of key=value pairs of connection parameters, described below (similar to libpq, but the actual libpq is not used and the set of available features is different). Example: .IP .EX foodb = host=host1.example.com port=5432 bardb = host=localhost dbname=bazdb .EE .PP The database name can contain characters \f[CR]_0-9A-Za-z\f[R] without quoting. Names that contain other characters need to be quoted with standard SQL identifier quoting: double quotes, with \[lq]\[rq] for a single instance of a double quote. .PP The database name \[lq]pgbouncer\[rq] is reserved for the admin console and cannot be used as a key here. .PP \[lq]*\[rq] acts as a fallback database: If the exact name does not exist, its value is taken as connection string for the requested database. For example, if there is an entry (and no other overriding entries) .IP .EX * = host=foo .EE .PP then a connection to PgBouncer specifying a database \[lq]bar\[rq] will effectively behave as if an entry .IP .EX bar = host=foo dbname=bar .EE .PP exists (taking advantage of the default for \f[CR]dbname\f[R] being the client-side database name; see below). .PP Such automatically created database entries are cleaned up if they stay idle longer than the time specified by the \f[CR]autodb_idle_timeout\f[R] parameter. .SS dbname Destination database name. .PP Default: same as client-side database name .SS host Host name or IP address to connect to. Host names are resolved at connection time, the result is cached per \f[CR]dns_max_ttl\f[R] parameter. When a host name\[cq]s resolution changes, existing server connections are automatically closed when they are released (according to the pooling mode), and new server connections immediately use the new resolution. If DNS returns several results, they are used in a round-robin manner. .PP If the value begins with \f[CR]/\f[R], then a Unix socket in the file-system namespace is used. If the value begins with \f[CR]\[at]\f[R], then a Unix socket in the abstract namespace is used. .PP A comma-separated list of host names or addresses can be specified. In that case, connections are made in a round-robin manner. (If a host list contains host names that in turn resolve via DNS to multiple addresses, the round-robin systems operate independently. This is an implementation dependency that is subject to change.) Note that in a list, all hosts must be available at all times: There are no mechanisms to skip unreachable hosts or to select only available hosts from a list or similar. (This is different from what a host list in libpq means.) Also note that this only affects how the destinations of new connections are chosen. See also the setting \f[CR]server_round_robin\f[R] for how clients are assigned to already established server connections. .PP Examples: .IP .EX host=localhost host=127.0.0.1 host=2001:0db8:85a3:0000:0000:8a2e:0370:7334 host=/var/run/postgresql host=192.168.0.1,192.168.0.2,192.168.0.3 .EE .PP Default: not set, meaning to use a Unix socket .SS port Default: 5432 .SS user If \f[CR]user=\f[R] is set, all connections to the destination database will be done with the specified user, meaning that there will be only one pool for this database. .PP Otherwise, PgBouncer logs into the destination database with the client user name, meaning that there will be one pool per user. .SS password If no password is specified here, the password from the \f[CR]auth_file\f[R] will be used for the user specified above. Dynamic forms of password discovery such as \f[CR]auth_query\f[R] are not currently supported. .SS auth_user Override of the global \f[CR]auth_user\f[R] setting, if specified. .SS auth_query Override of the global \f[CR]auth_query\f[R] setting, if specified. The entire SQL statement needs to be enclosed in single quotes. .SS auth_dbname Override of the global \f[CR]auth_dbname\f[R] setting, if specified. .SS pool_size Set the maximum size of pools for this database. If not set, the \f[CR]default_pool_size\f[R] is used. .SS min_pool_size Set the minimum pool size for this database. If not set, the global \f[CR]min_pool_size\f[R] is used. .PP Only enforced if at least one of the following is true: .IP \[bu] 2 this entry in the \f[CR][database]\f[R] section has a value set for the \f[CR]user\f[R] key (aka forced user) .IP \[bu] 2 there is at least one client connected to the pool .SS reserve_pool_size Set additional connections for this database. If not set, the global \f[CR]reserve_pool_size\f[R] is used. For backwards compatibility reasons \f[CR]reserve_pool\f[R] is an alias for this option. .SS connect_query Query to be executed after a connection is established, but before allowing the connection to be used by any clients. If the query raises errors, they are logged but ignored otherwise. .SS pool_mode Set the pool mode specific to this database. If not set, the default \f[CR]pool_mode\f[R] is used. .SS load_balance_hosts When a comma-separated list is specified in \f[CR]host\f[R], \f[CR]load_balance_hosts\f[R] controls which entry is chosen for a new connection. .PP Note: This setting currently only controls the load balancing behaviour when providing multiple hosts in the connection string, but not when a single host its DNS record references multiple IP addresses. This is a missing feature, so in a future release this setting might start to to control both methods of load balancing. .TP round-robin A new connection attempt chooses the next host entry in the list. .TP disable A new connection continues using the same host entry until a connection fails, after which the next host entry is chosen. .PP It is recommended to set \f[CR]server_login_retry\f[R] lower than the default to ensure fast retries when multiple hosts are available. .PP Default: \f[CR]round-robin\f[R] .SS max_db_connections Configure a database-wide maximum of server connections (i.e.\ all pools within the database will not have more than this many server connections). .SS max_db_client_connections Configure a database-wide client connection maximum. Should be used in conjunction with max_client_conn to limit the number of connections that PgBouncer is allowed to accept. .SS server_lifetime Configure the server_lifetime per database. If not set the database will fall back to the instance wide configured value for \f[CR]server_lifetime\f[R] .SS client_encoding Ask specific \f[CR]client_encoding\f[R] from server. .SS datestyle Ask specific \f[CR]datestyle\f[R] from server. .SS timezone Ask specific \f[CR]timezone\f[R] from server. .SH SECTION [USERS] This section contains key=value lines like .IP .EX user1 = settings .EE .PP where the key will be taken as a user name and the value as a list of key=value pairs of configuration settings specific for this user. Example: .IP .EX user1 = pool_mode=session .EE .PP Only a few settings are available here. .PP Note that when \f[CR]auth_file\f[R] is configured, if a user is defined in this section but not listed in \f[CR]auth_file\f[R], PgBouncer will attempt to use \f[CR]auth_query\f[R] to find a password for that user if \f[CR]auth_user\f[R] is set. If \f[CR]auth_user\f[R] is not set, PgBouncer will pretend the user exists and fail to return \[lq]no such user\[rq] messages to the client, but neither will it accept any provided password. .SS pool_size Set the maximum size of pools for all connections from this user. If not set, the database or \f[CR]default_pool_size\f[R] is used. .SS reserve_pool_size Set the number of additional connections to allow to a pool for this user. If not set, the database configuration or the global \f[CR]reserve_pool_size\f[R] is used. .SS pool_mode Set the pool mode to be used for all connections from this user. If not set, the database or default \f[CR]pool_mode\f[R] is used. .SS max_user_connections Configure a maximum for the user of server connections (i.e.\ all pools with the user will not have more than this many server connections). .SS query_timeout Set the maximum number of seconds that a user query can run for. If set this timeout overrides the server level query_timeout described above. .SS idle_transaction_timeout Set the maximum number of seconds that a user can have an idle transaction open. If set this timeout overrides the server level idle_transaction_timeout described above. .SS transaction_timeout Set the maximum number of seconds that a user can have a transaction open. If set this timeout overrides the server level transaction_timeout described above. .SS client_idle_timeout Set the maximum amount of time in seconds that a client is allowed to idly connect to the PgBouncer instance. If set this timeout overrides the server level client_idle_timeout described above. .PP Please note that this is a potentially dangerous timeout. .SS max_user_client_connections Configure a maximum for the user of client connections. This is the user equivalent of the max_client_conn setting. .SH SECTION [PEERS] The section \f[CR][peers]\f[R] defines the peers that PgBouncer can forward cancellation requests to and where those cancellation requests will be routed. .PP PgBouncer processes can be peered together in a group by defining a \f[CR]peer_id\f[R] value and a \f[CR][peers]\f[R] section in the configs of all the PgBouncer processes. These PgBouncer processes can then forward cancellations requests to the process that it originated from. This is needed to make cancellations work when multiple PgBouncer processes (possibly on different servers) are behind the same TCP load balancer. Cancellation requests are sent over different TCP connections than the query they are cancelling, so a TCP load balancer might send the cancellation request connection to a different process than the one that it was meant for. By peering them these cancellation requests eventually end up at the right process. A more in-depth explanation is provided in this recording of a conference talk (https://www.youtube.com/watch?v=X-nCHcZ6vQU). .PP The section contains key=value lines like .IP .EX peer_id = connection string .EE .PP Where the key will be taken as a \f[CR]peer_id\f[R] and the value as a connection string, consisting of key=value pairs of connection parameters, described below (similar to libpq, but the actual libpq is not used and the set of available features is different). Example: .IP .EX 1 = host=host1.example.com 2 = host=/tmp/pgbouncer-2 port=5555 .EE .PP Note 1: For peering to work, the \f[CR]peer_id\f[R] of each PgBouncer process in the group must be unique within the peered group. And the \f[CR][peers]\f[R] section should contain entries for each of those peer ids. An example can be found in the examples section of these docs. It \f[B]is\f[R] allowed, but not necessary, for the \f[CR][peers]\f[R] section to contain the \f[CR]peer_id\f[R] of the PgBouncer that the config is for. Such an entry will be ignored, but it is allowed to config management easy. Because it allows using the exact same \f[CR][peers]\f[R] section for multiple configs. .PP Note 2: Cross-version peering is supported as long as all peers are on the same side of the v1.21.0 version boundary. In v1.21.0 some breaking changes were made in how we encode the cancellation tokens that made them incompatible with the ones created by earlier versions. .SS host Host name or IP address to connect to. Host names are resolved at connection time, the result is cached per \f[CR]dns_max_ttl\f[R] parameter. If DNS returns several results, they are used in a round-robin manner. But in general it\[cq]s not recommended to use a hostname that resolves to multiple IPs, because then the cancel request might still be forwarded to the wrong node and it would need to be forwarded again (which is only allowed up to three times). .PP If the value begins with \f[CR]/\f[R], then a Unix socket in the file-system namespace is used. If the value begins with \f[CR]\[at]\f[R], then a Unix socket in the abstract namespace is used. .PP Examples: .IP .EX host=localhost host=127.0.0.1 host=2001:0db8:85a3:0000:0000:8a2e:0370:7334 host=/var/run/pgbouncer-1 .EE .SS port Default: 6432 .SS pool_size Set the maximum number of cancel requests that can be in flight to the peer at the same time. It\[cq]s quite normal for cancel requests to arrive in bursts, e.g. when the backing Postgres server slow or down. So it\[cq]s important for \f[CR]pool_size\f[R] to not be so low that it cannot handle these bursts. .PP If not set, the \f[CR]default_pool_size\f[R] is used. .SH INCLUDE DIRECTIVE The PgBouncer configuration file can contain include directives, which specify another configuration file to read and process. This allows splitting the configuration file into physically separate parts. The include directives look like this: .IP .EX %include filename .EE .PP If the file name is not an absolute path, it is taken as relative to the current working directory. .SH AUTHENTICATION FILE FORMAT This section describes the format of the file specified by the \f[CR]auth_file\f[R] setting. It is a text file in the following format: .IP .EX \[dq]username1\[dq] \[dq]password\[dq] ... \[dq]username2\[dq] \[dq]md5abcdef012342345\[dq] ... \[dq]username2\[dq] \[dq]SCRAM-SHA-256$:$:\[dq] .EE .PP There should be at least 2 fields, surrounded by double quotes. The first field is the user name and the second is either a plain-text, a MD5-hashed password, or a SCRAM secret. PgBouncer ignores the rest of the line. Double quotes in a field value can be escaped by writing two double quotes. .PP PostgreSQL MD5-hashed password format: .IP .EX \[dq]md5\[dq] + md5(password + username) .EE .PP So user \f[CR]admin\f[R] with password \f[CR]1234\f[R] will have MD5-hashed password \f[CR]md545f2603610af569b6155c45067268c6b\f[R]. .PP PostgreSQL SCRAM secret format: .IP .EX SCRAM-SHA-256$:$: .EE .PP See the PostgreSQL documentation and RFC 5803 for details on this. .PP The passwords or secrets stored in the authentication file serve two purposes. First, they are used to verify the passwords of incoming client connections, if a password-based authentication method is configured. Second, they are used as the passwords for outgoing connections to the backend server, if the backend server requires password-based authentication (unless the password is specified directly in the database\[cq]s connection string). .SS Limitations If the password is stored in plain text, it can be used for any password-based authentication used in the backend server; plain text, MD5 or SCRAM (see for details). .PP MD5-hashed passwords can be used if backend server uses MD5 authentication (or specific users have MD5-hashed passwords). .PP SCRAM secrets can only be used for logging into a server if the client authentication also uses SCRAM, the PgBouncer database definition does not specify a user name, and the SCRAM secrets are identical in PgBouncer and the PostgreSQL server (same salt and iterations, not merely the same password). This is due to an inherent security property of SCRAM: The stored SCRAM secret cannot by itself be used for deriving login credentials. .PP The authentication file can be written by hand, but it\[cq]s also useful to generate it from some other list of users and passwords. See \f[CR]./etc/mkauth.py\f[R] for a sample script to generate the authentication file from the \f[CR]pg_authid\f[R] system table. Alternatively, use \f[CR]auth_query\f[R] instead of \f[CR]auth_file\f[R] to avoid having to maintain a separate authentication file. .SS Note on managed servers If the backend server is configured to use SCRAM password authentication PgBouncer cannot successfully authenticate if it does not know either a) user password in plain text or b) corresponding SCRAM secret. .PP Some cloud providers (i.e.\ AWS RDS) prohibit access to PostgreSQL sensitive system tables for fetching passwords. Even for the most privileged user (i.e.\ member of rds_superuser) the \f[CR]select * from pg_authid\f[R]; returns the \f[CR]ERROR: permission denied for table pg_authid.\f[R] That is a known behaviour (blog (https://aws.amazon.com/blogs/database/best-practices-for-migrating-postgresql-databases-to-amazon-rds-and-amazon-aurora/)). .PP Therefore, fetching an existing SCRAM secret once it has been stored in a managed server is impossible which makes it hard to configure PgBouncer to use the same SCRAM secret. Nevertheless, SCRAM secret can still be configured and used on both sides using the following trick: .PP Generate SCRAM secret for arbitrary password with a tool that is capable of printing out the secret. For example \f[CR]psql --echo-hidden\f[R] and the command \f[CR]\[rs]password\f[R] prints out the SCRAM secret to the console before sending it over to the server. .IP .EX $ psql --echo-hidden postgres=# \[rs]password Enter new password for user \[dq]\[dq]: Enter it again: ********* QUERY ********** ALTER USER PASSWORD \[aq]SCRAM-SHA-256$:$:\[aq] ************************** .EE .PP Note down the SCRAM secret from the QUERY and set it in PgBouncer\[cq]s \f[CR]userlist.txt\f[R]. .PP If you used a tool other than \f[CR]psql --echo-hidden\f[R] then you need to set the SCRAM secret also in the server (you can use \f[CR]alter role password \[aq]\[aq]\f[R] for that). .SH HBA FILE FORMAT The location of the HBA file is specified by the setting \f[CR]auth_hba_file\f[R]. It is only used if \f[CR]auth_type\f[R] is set to \f[CR]hba\f[R]. .PP The file follows the format of the PostgreSQL \f[CR]pg_hba.conf\f[R] file (see ). .IP \[bu] 2 Supported record types: \f[CR]local\f[R], \f[CR]host\f[R], \f[CR]hostssl\f[R], \f[CR]hostnossl\f[R]. .IP \[bu] 2 Database field: Supports \f[CR]all\f[R], \f[CR]replication\f[R], \f[CR]sameuser\f[R], \f[CR]\[at]file\f[R], multiple names. Not supported: \f[CR]samerole\f[R], \f[CR]samegroup\f[R]. .IP \[bu] 2 User name field: Supports \f[CR]all\f[R], \f[CR]\[at]file\f[R], multiple names. Not supported: \f[CR]+groupname\f[R]. .IP \[bu] 2 Address field: Supports \f[CR]all\f[R], IPv4, IPv6. Not supported: \f[CR]samehost\f[R], \f[CR]samenet\f[R], DNS names, domain prefixes. .IP \[bu] 2 Auth-method field: Only methods supported by PgBouncer\[cq]s \f[CR]auth_type\f[R] are supported, plus \f[CR]peer\f[R] and \f[CR]reject\f[R], but except \f[CR]any\f[R] and \f[CR]pam\f[R], which only work globally. .IP \[bu] 2 User name map (\f[CR]map=\f[R]) parameter is supported when \f[CR]auth_type\f[R] is \f[CR]cert\f[R] or \f[CR]peer\f[R]. .SH IDENT MAP FILE FORMAT The location of the ident map file is specified by the setting \f[CR]auth_ident_file\f[R]. It is only loaded if \f[CR]auth_type\f[R] is set to \f[CR]hba\f[R]. .PP The file format is a simplified variation of the PostgreSQL ident map file (see ). .IP \[bu] 2 Supported lines are only of the form \f[CR]map-name system-username database-username\f[R]. .IP \[bu] 2 There is no support for including file/directory. .IP \[bu] 2 System-username field: Not supported: regular expressions. .IP \[bu] 2 Database-username field: Supports \f[CR]all\f[R] or a single Postgres user name. Not supported: \f[CR]+groupname\f[R], regular expressions. .SH EXAMPLES Small example configuration: .IP .EX [databases] template1 = host=localhost dbname=template1 auth_user=someuser [pgbouncer] pool_mode = session listen_port = 6432 listen_addr = localhost auth_type = md5 auth_file = users.txt logfile = pgbouncer.log pidfile = pgbouncer.pid admin_users = someuser stats_users = stat_collector .EE .PP Database examples: .IP .EX [databases] ; foodb over Unix socket foodb = ; redirect bardb to bazdb on localhost bardb = host=localhost dbname=bazdb ; access to destination database will go with single user forcedb = host=localhost port=300 user=baz password=foo client_encoding=UNICODE datestyle=ISO .EE .PP Example of a secure function for \f[CR]auth_query\f[R]: .IP .EX CREATE OR REPLACE FUNCTION pgbouncer.user_lookup(in i_username text, out uname text, out phash text) RETURNS record AS $$ BEGIN SELECT rolname, CASE WHEN rolvaliduntil < now() THEN NULL ELSE rolpassword END FROM pg_authid WHERE rolname=i_username AND rolcanlogin INTO uname, phash; RETURN; END; $$ LANGUAGE plpgsql SECURITY DEFINER -- Set a secure search_path: trusted schema(s), then \[aq]pg_temp\[aq]. SET search_path = pg_catalog, pg_temp; REVOKE ALL ON FUNCTION pgbouncer.user_lookup(text) FROM public, pgbouncer; GRANT EXECUTE ON FUNCTION pgbouncer.user_lookup(text) TO pgbouncer; .EE .PP Example configs for 2 peered PgBouncer processes to create a multi-core PgBouncer setup using \f[CR]so_reuseport\f[R]. The config for the first process: .IP .EX [databases] postgres = host=localhost dbname=postgres [peers] 1 = host=/tmp/pgbouncer1 2 = host=/tmp/pgbouncer2 [pgbouncer] listen_addr=127.0.0.1 auth_file=auth_file.conf so_reuseport=1 unix_socket_dir=/tmp/pgbouncer1 peer_id=1 .EE .PP The config for the second process: .IP .EX [databases] postgres = host=localhost dbname=postgres [peers] 1 = host=/tmp/pgbouncer1 2 = host=/tmp/pgbouncer2 [pgbouncer] listen_addr=127.0.0.1 auth_file=auth_file.conf so_reuseport=1 ; only unix_socket_dir and peer_id are different unix_socket_dir=/tmp/pgbouncer2 peer_id=2 .EE .SH SEE ALSO pgbouncer(1) - man page for general usage, console commands .PP