PgBouncer Administration Console.

Synopsis

  1. psql -p <port> pgbouncer

Description

The PgBouncer Administration Console is available via psql. Connect to the PgBouncer <port> and the virtual database named pgbouncer to log in to the console.

Users listed in the pgbouncer.ini configuration parameters admin_users and stats_users have privileges to log in to the PgBouncer Administration Console. When auth_type=any, then any user is allowed in as a stats_user.

Additionally, the user name pgbouncer is allowed to log in without password when the login comes via the Unix socket and the client has same Unix user UID as the running process.

You can control connections between PgBouncer and Greenplum Database from the console. You can also set PgBouncer configuration parameters.

Options

-p <port>

The PgBouncer port number.

Command Syntax

  1. pgbouncer=# SHOW help;
  2. NOTICE: Console usage
  3. DETAIL:
  4. SHOW HELP|CONFIG|USERS|DATABASES|POOLS|CLIENTS|SERVERS|VERSION
  5. SHOW FDS|SOCKETS|ACTIVE_SOCKETS|LISTS|MEM
  6. SHOW DNS_HOSTS|DNS_ZONES
  7. SHOW STATS|STATS_TOTALS|STATS_AVERAGES
  8. SHOW TOTALS
  9. SET key = arg
  10. RELOAD
  11. PAUSE [<db>]
  12. RESUME [<db>]
  13. DISABLE <db>
  14. ENABLE <db>
  15. RECONNECT [<db>]
  16. KILL <db>
  17. SUSPEND
  18. SHUTDOWN

Administration Commands

The following PgBouncer administration commands control the running pgbouncer process.

PAUSE [<db>]

If no database is specified, PgBouncer tries to disconnect from all servers, first waiting for all queries to complete. The command will not return before all queries are finished. This command is to be used to prepare to restart the database.

If a database name is specified, PgBouncer pauses only that database.

New client connections to a paused database will wait until a RESUME command is invoked.

DISABLE <db>

Reject all new client connections on the database.

ENABLE <db>

Allow new client connections after a previous DISABLE command.

RECONNECT

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.

KILL <db>

Immediately drop all client and server connections to the named database.

New client connections to a killed database will wait until RESUME is called.

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 when rebooting PgBouncer online.

New client connections to a suspended database will wait until RESUME is called.

RESUME [<db>]

Resume work from a previous KILL, PAUSE, or SUSPEND command.

SHUTDOWN

The PgBouncer process will exit. To exit from the psql command line session, enter \q.

RELOAD

The PgBouncer process reloads the current configuration file and updates the 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_CLOSE [<db>]

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.

SET key = value

Changes the specified configuration setting. See the SHOW CONFIG; command.

(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.)

SHOW Command

The SHOW <category> command displays different types of PgBouncer information. You can specify one of the following categories:

CLIENTS

ColumnDescription
typeC, for client.
userClient connected user.
databaseDatabase name.
stateState of the client connection, one of active or waiting.
addrIP address of client.
portPort client is connected to.
local_addrConnection end address on local machine.
local_portConnection end port on local machine.
connect_timeTimestamp of connect time.
request_timeTimestamp of latest client request.
waitCurrent Time waiting in seconds.
wait_usMicrosecond part of the current waiting time.
ptrAddress of internal object for this connection. Used as unique ID.
linkAddress of server connection the client is paired with.
remote_pidProcess ID, if client connects with Unix socket and the OS supports getting it.
tlsA string with TLS connection information, or empty if not using TLS.

CONFIG

Show the current PgBouncer configuration settings, one per row, with the following columns:

ColumnDescription
keyConfiguration variable name
valueConfiguration value
defaultConfiguration default value
changeableEither yes or no. Shows whether the variable can be changed while running. If no, the variable can be changed only at boot time. Use SET to change a variable at run time.

DATABASES

ColumnDescription
nameName of configured database entry.
hostHost pgbouncer connects to.
portPort pgbouncer connects to.
databaseActual database name pgbouncer connects to.
force_userWhen user is part of the connection string, the connection between pgbouncer and the database server is forced to the given user, whatever the client user.
pool_sizeMaximum number of server connections.
min_pool_sizeMinimum number of server connections.
reserve_poolThe maximum number of additional connections for this database.
pool_modeThe database’s override pool_mode or NULL if the default will be used instead.
max_connectionsMaximum number of allowed connections for this database, as set by max_db_connections, either globally or per-database.
current_connectionsThe current number of connections for this database.
pausedPaused/unpaused state of the database. 1 if this database is currently paused, else 0.
disabledEnabled/disabled state of the database. 1 if this database is currently disabled, else 0.

DNS_HOSTS

Show host names in DNS cache.

ColumnDescription
hostnameHost name
ttlHow many seconds until next lookup.
addrsComma-separated list of addresses.

DNS_ZONES

Show DNS zones in cache.

ColumnDescription
zonenameZone name
serialCurrent DNS serial number
countHostnames belonging to this zone

FDS

SHOW FDS is an internal command used for an online restart, for example when upgrading to a new PgBouncer version. It displays a list of file descriptors in use with the internal state attached to them. This command blocks the internal event loop, so it should not be used while PgBouncer is in use.

When the connected user has username “pgbouncer”, connects through a Unix socket, and has the same UID as the running process, the actual file descriptors are passed over the connection. This mechanism is used to do an online restart.

ColumnDescription
fdFile descriptor numeric value.
taskOne of pooler, client, or server.
userUser of the connection using the file descriptor.
databaseDatabase of the connection using the file descriptor.
addrIP address of the connection using the file descriptor, unix if a Unix socket is used.
portPort used by the connection using the file descriptor.
cancelCancel key for this connection.
linkFile descriptor for corresponding server/client. NULL if idle.

LISTS

Shows the following PgBouncer internal information, in columns (not rows):

ItemDescription
databasesCount of databases.
usersCount of users.
poolsCount of pools.
free_clientsCount of free clients.
used_clientsCount of used clients.
login_clientsCount of clients in login state.
free_serversCount of free servers.
used_serversCount of used servers.
dns_namesCount of DNS names in the cache.
dns_zonesCount of DNS zones in the cache.
dns_queriesCount of in-flight DNS queries.
dns_pendingnot used

MEM

Shows low-level information about the current sizes of various internal memory allocations. The information presented is subject to change.

POOLS

A new pool entry is made for each pair of (database, user).

ColumnDescription
databaseDatabase name.
userUser name.
cl_activeClient connections that are linked to server connection and can process queries.
cl_waitingClient connections that have sent queries but have not yet got a server connection.
cl_cancel_reqClient connections that have not yet forwarded query cancellations to the server.
sv_activeServer connections that are linked to client.
sv_idleServer connections that are unused and immediately usable for client queries.
sv_usedServer connections that have been idle more than server_check_delay. The server_check_query query must be run on them before they can be used again.
sv_testedServer connections that are currently running either server_reset_query or server_check_query.
sv_loginServer connections currently in the process of logging in.
maxwaitHow long the first (oldest) client in the queue has waited, in seconds. If this begins to increase, the current pool of servers does not handle requests quickly enough. The cause may be either an overloaded server or the pool_size setting is too small.
maxwait_usMicrosecond part of the maximum waiting time.
pool_modeThe pooling mode in use.

SERVERS

ColumnDescription
typeS, for server.
userUser name that pgbouncer uses to connect to server.
databaseDatabase name.
stateState of the pgbouncer server connection, one of active, idle, used, tested, or new.
addrIP address of the Greenplum or PostgreSQL server.
portPort of the Greenplum or PostgreSQL server.
local_addrConnection start address on local machine.
local_portConnection start port on local machine.
connect_timeWhen the connection was made.
request_timeWhen the last request was issued.
waitCurrent waiting time in seconds.
wait_usMicrosecond part of the current waiting time.
close_needed1 if the connection will be closed as soon as possible, because a configuration file reload or DNS update changed the connection information or RECONNECT was issued.
ptrAddress of the internal object for this connection. Used as unique ID.
linkAddress of the client connection the server is paired with.
remote_pidPid of backend server process. If the connection is made over Unix socket and the OS supports getting process ID info, it is the OS pid. Otherwise it is extracted from the cancel packet the server sent, which should be PID in case server is PostgreSQL, but it is a random number in case server is another PgBouncer.
tlsA string with TLS connection information, or empty if not using TLS.

SOCKETS, ACTIVE_SOCKETS

Shows low-level information about sockets or only active sockets. This includes the information shown under SHOW CLIENTS and SHOW SERVERS as well as other more low-level information.

STATS

Shows statistics. In this and related commands, the total figures are since process start, the averages are updated every stats_period.

ColumnDescription
databaseStatistics are presented per database.
total_xact_countTotal number of SQL transactions pooled by PgBouncer.
total_query_countTotal number of SQL queries pooled by PgBouncer.
total_receivedTotal volume in bytes of network traffic received by pgbouncer.
total_sentTotal volume in bytes of network traffic sent by pgbouncer.
total_xact_timeTotal number of microseconds spent by PgBouncer when connected to Greenplum Database in a transaction, either idle in transaction or executing queries.
total_query_timeTotal number of microseconds spent by pgbouncer when actively connected to the database server.
total_wait_timeTime spent (in microseconds) by clients waiting for a server.
avg_xact_countAverage number of transactions per second in the last stat period.
avg_query_countAverage queries per second in the last stats period.
avg_recvAverage received (from clients) bytes per second.
avg_sentAverage sent (to clients) bytes per second.
avg_xact_timeAverage transaction duration in microseconds.
avg_query_timeAverage query duration in microseconds.
avg_wait_timeTime spent by clients waiting for a server in microseconds (average per second).

STATS_AVERAGES

Subset of SHOW STATS showing the average values for selected statistics (avg_)

STATS_TOTALS

Subset of SHOW STATS showing the total values for selected statistics (total_)

TOTALS

Like SHOW STATS but aggregated across all databases.

USERS

ColumnDescription
nameThe user name
pool_modeThe user’s override pool_mode, or NULL if the default will be used instead.

VERSION

Display PgBouncer version information.

Signals

SIGHUP : Reload config. Same as issuing the command RELOAD on the console.

SIGINT : Safe shutdown. Same as issuing PAUSE and SHUTDOWN on the console.

SIGTERM : Immediate shutdown. Same as issuing SHUTDOWN on the console.

SIGUSR1 : Same as issuing PAUSE on the console.

SIGUSR2 : Same as issuing RESUME on the console.

Libevent Settings

From the Libevent documentation:

  1. It is possible to disable support for epoll, kqueue, devpoll, poll or select by
  2. setting the environment variable EVENT_NOEPOLL, EVENT_NOKQUEUE, EVENT_NODEVPOLL,
  3. EVENT_NOPOLL or EVENT_NOSELECT, respectively.
  4. By setting the environment variable EVENT_SHOW_METHOD, libevent displays the
  5. kernel notification method that it uses.

See Also

pgbouncer, pgbouncer.ini