.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "PGBOUNCER" "1" "" "1.21.0" "Databases" .hy .SH NAME .PP pgbouncer - lightweight connection pooler for PostgreSQL .SH SYNOPSIS .IP .nf \f[C] pgbouncer [-d][-R][-v][-u user] pgbouncer -V|-h \f[R] .fi .PP On Windows, the options are: .IP .nf \f[C] pgbouncer.exe [-v][-u user] pgbouncer.exe -V|-h \f[R] .fi .PP Additional options for setting up a Windows service: .IP .nf \f[C] pgbouncer.exe --regservice pgbouncer.exe --unregservice \f[R] .fi .SH DESCRIPTION .PP \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[C]SHOW\f[R] commands available when connected to a special \[lq]virtual\[rq] database \f[B]pgbouncer\f[R]. .SH QUICK-START .PP 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 .nf \f[C] [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 \f[R] .fi .RE .IP "2." 3 Create a \f[C]userlist.txt\f[R] file that contains the users allowed in: .RS 4 .IP .nf \f[C] \[dq]someuser\[dq] \[dq]same_password_as_in_server\[dq] \f[R] .fi .RE .IP "3." 3 Launch \f[B]pgbouncer\f[R]: .RS 4 .IP .nf \f[C] $ pgbouncer -d pgbouncer.ini \f[R] .fi .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 .nf \f[C] $ psql -p 6432 -U someuser template1 \f[R] .fi .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[C]SHOW HELP;\f[R] to begin: .RS 4 .IP .nf \f[C] $ 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 [...] \f[R] .fi .RE .IP "6." 3 If you made changes to the pgbouncer.ini file, you can reload it with: .RS 4 .IP .nf \f[C] pgbouncer=# RELOAD; \f[R] .fi .RE .SH COMMAND LINE SWITCHES .TP \f[B]\f[CB]-d\f[B]\f[R], \f[B]\f[CB]--daemon\f[B]\f[R] Run in the background. Without it, the process will run in the foreground. .RS .PP In daemon mode, setting \f[C]pidfile\f[R] as well as \f[C]logfile\f[R] or \f[C]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[B]\f[CB]-R\f[B]\f[R], \f[B]\f[CB]--reboot\f[B]\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[C]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[B]\f[CB]-u\f[B]\f[R] \f[I]USERNAME\f[R], \f[B]\f[CB]--user=\f[B]\f[R]\f[I]USERNAME\f[R] Switch to the given user on startup. .TP \f[B]\f[CB]-v\f[B]\f[R], \f[B]\f[CB]--verbose\f[B]\f[R] Increase verbosity. Can be used multiple times. .TP \f[B]\f[CB]-q\f[B]\f[R], \f[B]\f[CB]--quiet\f[B]\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[B]\f[CB]-V\f[B]\f[R], \f[B]\f[CB]--version\f[B]\f[R] Show version. .TP \f[B]\f[CB]-h\f[B]\f[R], \f[B]\f[CB]--help\f[B]\f[R] Show short help. .TP \f[B]\f[CB]--regservice\f[B]\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[B]\f[CB]--unregservice\f[B]\f[R] Win32: Unregister Windows service. .SH ADMIN CONSOLE .PP The console is available by connecting as normal to the database \f[B]pgbouncer\f[R]: .IP .nf \f[C] $ psql -p 6432 pgbouncer \f[R] .fi .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[C]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 .PP The \f[B]SHOW\f[R] commands output information. Each command is described below. .SS SHOW STATS .PP Shows statistics. In this and related commands, the total figures are since process start, the averages are updated every \f[C]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 queries pooled by \f[B]pgbouncer\f[R]. .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 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_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 Average time spent by clients waiting for a server that were assigned a backend connection within the current \f[C]stats_period\f[R], in microseconds (averaged per second within that period). .SS SHOW STATS_TOTALS .PP Subset of \f[B]SHOW STATS\f[R] showing the total values (\f[B]total_\f[R]). .SS SHOW STATS_AVERAGES .PP Subset of \f[B]SHOW STATS\f[R] showing the average values (\f[B]avg_\f[R]). .SS SHOW TOTALS .PP 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 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. Used as unique ID. .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[C]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[C]max_prepared_statements\f[R] setting. .SS SHOW CLIENTS .TP type C, for client. .TP user Client connected user. .TP database Database name. .TP state State of the client connection, one of \f[B]active\f[R], \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. Used as unique ID. .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[C]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 .SS SHOW POOLS .PP 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[C]server_check_delay\f[R], so they need \f[C]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[C]server_reset_query\f[R] or \f[C]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. .SS SHOW PEER_POOLS .PP 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 .PP 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. .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. .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_mode The user\[cq]s override pool_mode, or NULL if the default will be used instead. .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 Maximum number of additional connections for this database. .TP pool_mode The database\[cq]s override pool_mode, or NULL if the default will be used instead. .TP max_connections Maximum number of allowed 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 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 .PP 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 .PP 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 .PP 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 .PP Shows low-level information about the current sizes of various internal memory allocations. The information presented is subject to change. .SS SHOW DNS_HOSTS .PP 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 .PP Show DNS zones in cache. .TP zonename Zone name. .TP serial Current serial. .TP count Host names belonging to this zone. .SS SHOW VERSION .PP Show the PgBouncer version string. .SS SHOW STATE .PP Show the PgBouncer state settings. Current states are active, paused and suspended. .SS Process controlling commands .SS PAUSE [db] .PP 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 .PP Reject all new client connections on the given database. .SS ENABLE db .PP Allow new client connections after a previous \f[B]DISABLE\f[R] command. .SS RECONNECT [db] .PP 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 .PP Immediately drop all client and server connections on given database. .PP New client connections to a killed database will wait until \f[B]RESUME\f[R] is called. .SS SUSPEND .PP 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] .PP Resume work from previous \f[B]KILL\f[R], \f[B]PAUSE\f[R], or \f[B]SUSPEND\f[R] command. .SS SHUTDOWN .PP The PgBouncer process will exit. .SS RELOAD .PP 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[C]auth_file\f[R] and \f[C]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] .PP 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 .PP Changes a configuration setting (see also \f[B]SHOW CONFIG\f[R]). For example: .IP .nf \f[C] SET log_connections = 1; SET server_check_query = \[aq]select 2\[aq]; \f[R] .fi .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 SIGINT Safe shutdown. Same as issuing \f[B]PAUSE\f[R] and \f[B]SHUTDOWN\f[R] on the console. .TP SIGTERM 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 .PP 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 .PP pgbouncer(5) - man page of configuration settings descriptions .PP