PGBOUNCER(1) | Databases | PGBOUNCER(1) |
pgbouncer - lightweight connection pooler for PostgreSQL
pgbouncer [-d][-R][-v][-u user] <pgbouncer.ini> pgbouncer -V|-h
On Windows computers, the options are:
pgbouncer.exe [-v][-u user] <pgbouncer.ini> pgbouncer.exe -V|-h
Additional options for setting up a Windows service:
pgbouncer.exe --regservice <pgbouncer.ini> pgbouncer.exe --unregservice <pgbouncer.ini>
pgbouncer is a PostgreSQL connection pooler. Any target application can be connected to pgbouncer as if it were a PostgreSQL server, and pgbouncer will create a connection to the actual server, or it will reuse one of its existing connections.
The aim of pgbouncer is to lower the performance impact of opening new connections to PostgreSQL.
In order not to compromise transaction semantics for connection pooling, pgbouncer supports several types of pooling when rotating connections:
The administration interface of pgbouncer consists of some new SHOW commands available when connected to a special 'virtual' database pgbouncer.
Basic setup and usage as following.
[databases] template1 = host=127.0.0.1 port=5432 dbname=template1 [pgbouncer] listen_port = 6543 listen_addr = 127.0.0.1 auth_type = md5 auth_file = users.txt logfile = pgbouncer.log pidfile = pgbouncer.pid admin_users = someuser
"someuser" "same_password_as_in_server"
$ pgbouncer -d pgbouncer.ini
$ psql -p 6543 -U someuser template1
$ psql -p 6543 -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
[...]
pgbouncer=# RELOAD;
The console is available by connecting as normal to the database pgbouncer:
$ psql -p 6543 pgbouncer
Only users listed in configuration parameters admin_users or stats_users are allowed to login to the console. (Except when auth_type=any, then any user is allowed in as a stats_user.)
Additionally, the username pgbouncer is allowed to log in without password, if the login comes via Unix socket and the client has same Unix user UID as the running process.
The SHOW commands output information. Each command is described below.
Shows statistics.
Subset of SHOW STATS showing the total values (total_).
Subset of SHOW STATS showing the average values (avg_).
A new pool entry is made for each couple of (database, user).
Show following internal information, in columns (not rows):
Internal command - shows list of file descriptors in use with internal state attached to them.
When the connected user has user name "pgbouncer", connects through Unix socket and has same 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 machines.
This command also blocks the internal event loop, so it should not be used while PgBouncer is in use.
Show the current configuration settings, one per row, with following columns:
Show host names in DNS cache.
Show DNS zones in cache.
PgBouncer tries to disconnect from all servers, first waiting for all queries to complete. The command will not return before all queries are finished. To be used at the time of database restart.
If database name is given, only that database will be paused.
New client connections to a paused database will wait until RESUME is called.
Reject all new client connections on the given database.
Allow new client connections after a previous DISABLE command.
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.
This command is useful when the server connection setup has changed, for example to perform a gradual switchover to a new server. It is not necessary to run this command when the connection string in pgbouncer.ini has been changed and reloaded (see RELOAD) 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.
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, PAUSE is recommended instead. To close server connections without waiting (for example, in emergency failover rather than gradual switchover scenarios), also consider KILL.
Immediately drop all client and server connections on given database.
New client connections to a killed database will wait until RESUME is called.
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.
New client connections to a suspended database will wait until RESUME is called.
Resume work from previous KILL, PAUSE, or SUSPEND command.
The PgBouncer process will exit.
The PgBouncer process will reload its configuration file and update changeable settings.
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.
Wait until all server connections, either of the specified database or of all databases, have cleared the "close_needed" state (see SHOW SERVERS). This can be called after a RECONNECT or RELOAD to wait until the respective configuration change has been fully activated, for example in switchover scripts.
Changes a configuration setting (see also SHOW CONFIG). For example:
SET log_connections = 1; SET server_check_query = 'select 2';
(Note that this command is run on the PgBouncer admin console and sets PgBouncer settings. A SET command run on another database will be passed to the PostgreSQL backend like any other SQL command.)
From libevent docs:
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. By setting the environment variable EVENT_SHOW_METHOD, libevent displays the kernel notification method that it uses.
pgbouncer(5) - man page of configuration settings descriptions.
https://pgbouncer.github.io/
https://wiki.postgresql.org/wiki/PgBouncer
2018-08-13 | 1.9.0 |