table of contents
other sections
PGBOUNCER(1) | PGBOUNCER(1) |
NAME¶
pgbouncer - Lightweight connection pooler for PostgreSQL.SYNOPSIS¶
pgbouncer [-d][-R][-v][-u user] <pgbouncer.ini> pgbouncer -V|-h
pgbouncer.exe [-v][-u user] <pgbouncer.ini> pgbouncer.exe -V|-h
pgbouncer.exe -regservice <pgbouncer.ini> pgbouncer.exe -unregservice <pgbouncer.ini>
DESCRIPTION¶
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.Most polite method. When 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.
Transaction pooling
A server connection is assigned to client only
during a transaction. When PgBouncer notices that transaction is over, the
server connection will be put back into the pool.
Statement pooling
Most aggressive method. The server connection
will be put back into pool immediately after a query completes.
Multi-statement transactions are disallowed in this mode as they would
break.
QUICK-START¶
Basic setup and usage as following. 1.Create a pgbouncer.ini file. Details in
pgbouncer(5). Simple example:
[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
2.Create a users.txt file:
"someuser" "same_password_as_in_server"
3.Launch pgbouncer:
$ pgbouncer -d pgbouncer.ini
4.Have your application (or the psql client)
connect to pgbouncer instead of directly to PostgreSQL server.
$ psql -p 6543 -U someuser template1
5.Manage pgbouncer by connecting to the
special administration database pgbouncer and issuing show help; to begin:
$ 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
6.If you made changes to the pgbouncer.ini
file, you can reload it with:
pgbouncer=# RELOAD;
COMMAND LINE SWITCHES¶
-dRun in background. Without it the process will
run in foreground. Note: Does not work on Windows, pgbouncer need to run as
service there.
-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 unix_socket_dir is not disabled in config. Does not work
on Windows machines.
-u user
Switch to the given user on startup.
-v
Increase verbosity. Can be used multiple
times.
-q
Be quiet - do not log to stdout. Note this
does not affect logging verbosity, only that stdout is not to be used. For use
in init.d scripts.
-V
Show version.
-h
Show short help.
-regservice
Win32: Register pgbouncer to run as Windows
service. The service_name config parameter value is used as name to register
under.
-unregservice
Win32: Unregister Windows service.
ADMIN CONSOLE¶
The console is available by connecting as normal to the database pgbouncer$ psql -p 6543 pgbouncer
SHOW COMMANDS¶
The SHOW commands output information. Each command is described below.Statistics are presented per database.
total_requests
Total number of SQL requests pooled by
pgbouncer.
total_received
Total volume in bytes of network traffic
received by pgbouncer.
total_sent
Total volume in bytes of network traffic sent
by pgbouncer.
total_query_time
Total number of microseconds spent by
pgbouncer when actively connected to PostgreSQL.
avg_req
Average requests per second in last stat
period.
avg_recv
Average received (from clients) bytes per
second.
avg_sent
Average sent (to clients) bytes per
second.
avg_query
Average query duration in microseconds.
type
S, for server.
user
Username pgbouncer uses to connect to
server.
database
Database name.
state
State of the pgbouncer server connection, one
of active, used or idle.
addr
IP address of PostgreSQL server.
port
Port of PostgreSQL server.
local_addr
Connection start address on local
machine.
local_port
Connection start port on local machine.
connect_time
When the connection was made.
request_time
When last request was issued.
ptr
Address of internal object for this
connection. Used as unique ID.
link
Address of client connection the server is
paired with.
type
C, for client.
user
Client connected user.
database
Database name.
state
State of the client connection, one of active,
used, waiting or idle.
addr
IP address of client.
port
Port client is connected to.
local_addr
Connection end address on local machine.
local_port
Connection end port on local machine.
connect_time
Timestamp of connect time.
request_time
Timestamp of latest client request.
ptr
Address of internal object for this
connection. Used as unique ID.
link
Address of server connection the client is
paired with.
Database name.
user
Username.
cl_active
Count of currently active client
connections.
cl_waiting
Count of currently waiting client
connections.
sv_active
Count of currently active server
connections.
sv_idle
Count of currently idle server
connections.
sv_used
Count of currently used server
connections.
sv_tested
Count of currently tested server
connections.
sv_login
Count of server connections currently logged
in to PostgreSQL.
maxwait
How long the first (oldest) client in queue
has waited, in seconds. If this starts increasing, then the current pool of
servers does not handle requests quick enough. Reason may be either overloaded
server or just too small of a pool_size setting.
Count of databases.
users
Count of users.
pools
Count of pools.
free_clients
Count of free clients.
used_clients
Count of used clients.
login_clients
Count of clients in login state.
free_servers
Count of free servers.
used_servers
Count of used servers.
name
Name of configured database entry.
host
Host pgbouncer connects to.
port
Port pgbouncer connects to.
database
Actual database name pgbouncer connects
to.
force_user
When user is part of the connection string,
the connection between pgbouncer and PostgreSQL is forced to the given user,
whatever the client user.
pool_size
Maximum number of server connections.
File descriptor numeric value.
task
One of pooler, client or server.
user
User of the connection using the FD.
database
Database of the connection using the FD.
addr
IP address of the connection using the FD,
unix if a unix socket is used.
port
Port used by the connection using the
FD.
cancel
Cancel key for this connection.
link
fd for corresponding server/client. NULL if
idle.
Configuration variable name
value
Configuration value
changeable
Either yes or no, shows if the variable can be
changed while running. If no, the variable can be changed only
boot-time.
Host name.
ttl
How meny seconds until next lookup.
addrs
Comma separated list of addresses.
Zone name.
serial
Current serial.
count
Hostnames belonging to this zone.
PROCESS CONTROLLING COMMANDS¶
PAUSE [db];SIGNALS¶
SIGHUPReload config. Same as issuing command RELOAD;
on console.
SIGINT
Safe shutdown. Same as issuing PAUSE; and
SHUTDOWN; on console.
SIGTERM
Immediate shutdown. Same as issuing SHUTDOWN;
on console.
LIBEVENT SETTINGS¶
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.
SEE ALSO¶
pgbouncer(5) - manpage of configuration settings descriptions.05/24/2015 |