1PGBOUNCER(1)                       Databases                      PGBOUNCER(1)
2
3
4

NAME

6       pgbouncer - lightweight connection pooler for PostgreSQL
7

SYNOPSIS

9          pgbouncer [-d][-R][-v][-u user] <pgbouncer.ini>
10          pgbouncer -V|-h
11
12       On Windows computers, the options are:
13
14          pgbouncer.exe [-v][-u user] <pgbouncer.ini>
15          pgbouncer.exe -V|-h
16
17       Additional options for setting up a Windows service:
18
19          pgbouncer.exe --regservice   <pgbouncer.ini>
20          pgbouncer.exe --unregservice <pgbouncer.ini>
21

DESCRIPTION

23       pgbouncer is a PostgreSQL connection pooler. Any target application can
24       be connected to pgbouncer as  if  it  were  a  PostgreSQL  server,  and
25       pgbouncer will create a connection to the actual server, or it will re‐
26       use one of its existing connections.
27
28       The aim of pgbouncer is to lower the performance impact of opening  new
29       connections to PostgreSQL.
30
31       In  order  not to compromise transaction semantics for connection pool‐
32       ing, pgbouncer supports several types of pooling when rotating  connec‐
33       tions:
34
35       Session pooling
36              Most  polite  method.  When client connects, a server connection
37              will be assigned to it for the whole duration the  client  stays
38              connected.  When  the  client disconnects, the server connection
39              will be put back into the pool.  This is the default method.
40
41       Transaction pooling
42              A server connection is assigned to client only during a transac‐
43              tion.   When  PgBouncer  notices  that  transaction is over, the
44              server connection will be put back into the pool.
45
46       Statement pooling
47              Most aggressive method. The server connection will be  put  back
48              into  pool  immediately after a query completes. Multi-statement
49              transactions are disallowed in this mode as they would break.
50
51       The administration interface of pgbouncer consists  of  some  new  SHOW
52       commands  available  when  connected  to  a  special 'virtual' database
53       pgbouncer.
54

QUICK-START

56       Basic setup and usage as following.
57
58       1. Create a pgbouncer.ini file.  Details in pgbouncer(5).  Simple exam‐
59          ple:
60
61             [databases]
62             template1 = host=127.0.0.1 port=5432 dbname=template1
63
64             [pgbouncer]
65             listen_port = 6543
66             listen_addr = 127.0.0.1
67             auth_type = md5
68             auth_file = users.txt
69             logfile = pgbouncer.log
70             pidfile = pgbouncer.pid
71             admin_users = someuser
72
73       2. Create users.txt file that contains users allowed in:
74
75             "someuser" "same_password_as_in_server"
76
77       3. Launch pgbouncer:
78
79             $ pgbouncer -d pgbouncer.ini
80
81       4. Have  your  application  (or  the  psql client) connect to pgbouncer
82          instead of directly to PostgreSQL server:
83
84             $ psql -p 6543 -U someuser template1
85
86       5. Manage pgbouncer by connecting to the special  administration  data‐
87          base pgbouncer and issuing show help; to begin:
88
89             $ psql -p 6543 -U someuser pgbouncer
90             pgbouncer=# show help;
91             NOTICE:  Console usage
92             DETAIL:
93               SHOW [HELP|CONFIG|DATABASES|FDS|POOLS|CLIENTS|SERVERS|SOCKETS|LISTS|VERSION]
94               SET key = arg
95               RELOAD
96               PAUSE
97               SUSPEND
98               RESUME
99               SHUTDOWN
100
101       6. If  you  made  changes  to the pgbouncer.ini file, you can reload it
102          with:
103
104             pgbouncer=# RELOAD;
105

COMMAND LINE SWITCHES

107       -d     Run in background. Without it the  process  will  run  in  fore‐
108              ground.   Note:  Does not work on Windows, pgbouncer need to run
109              as service there.
110
111       -R     Do an online restart.  That  means  connecting  to  the  running
112              process,  loading the open sockets from it, and then using them.
113              If there is no active process, boot normally.  Note: Works  only
114              if  OS supports Unix sockets and the unix_socket_dir is not dis‐
115              abled in config.  Does not work on Windows machines.   Does  not
116              work with TLS connections, they are dropped.
117
118       -u user
119              Switch to the given user on startup.
120
121       -v     Increase verbosity.  Can be used multiple times.
122
123       -q     Be quiet - do not log to stdout.  Note this does not affect log‐
124              ging verbosity, only that stdout is not to be used.  For use  in
125              init.d scripts.
126
127       -V     Show version.
128
129       -h     Show short help.
130
131       --regservice
132              Win32:  Register  pgbouncer to run as Windows service.  The ser‐
133              vice_name config parameter value is used  as  name  to  register
134              under.
135
136       --unregservice
137              Win32: Unregister Windows service.
138

ADMIN CONSOLE

140       The  console  is  available  by  connecting  as  normal to the database
141       pgbouncer:
142
143          $ psql -p 6543 pgbouncer
144
145       Only  users  listed  in   configuration   parameters   admin_users   or
146       stats_users  are  allowed  to  login  to  the  console.   (Except  when
147       auth_type=any, then any user is allowed in as a stats_user.)
148
149       Additionally, the username pgbouncer is allowed to log in without pass‐
150       word,  if  the login comes via Unix socket and the client has same Unix
151       user UID as the running process.
152
153   Show commands
154       The SHOW commands output information. Each command is described below.
155
156   SHOW STATS;
157       Shows statistics.
158
159       database
160              Statistics are presented per database.
161
162       total_xact_count
163              Total number of SQL transactions pooled by pgbouncer.
164
165       total_query_count
166              Total number of SQL queries pooled by pgbouncer.
167
168       total_received
169              Total volume in bytes of network traffic received by pgbouncer.
170
171       total_sent
172              Total volume in bytes of network traffic sent by pgbouncer.
173
174       total_xact_time
175              Total number of microseconds spent by pgbouncer  when  connected
176              to  PostgreSQL  in  a transaction, either idle in transaction or
177              executing queries.
178
179       total_query_time
180              Total number of microseconds spent by  pgbouncer  when  actively
181              connected to PostgreSQL, executing queries.
182
183       total_wait_time
184              Time spent by clients waiting for a server in microseconds.
185
186       avg_xact_count
187              Average transactions per second in last stat period.
188
189       avg_query_count
190              Average queries per second in last stat period.
191
192       avg_recv
193              Average received (from clients) bytes per second.
194
195       avg_sent
196              Average sent (to clients) bytes per second.
197
198       avg_xact_time
199              Average transaction duration in microseconds.
200
201       avg_query_time
202              Average query duration in microseconds.
203
204       avg_wait_time
205              Time  spent  by  clients  waiting  for  a server in microseconds
206              (average per second).
207
208   SHOW STATS_TOTALS;
209       Subset of SHOW STATS showing the total values (total_).
210
211   SHOW STATS_AVERAGES;
212       Subset of SHOW STATS showing the average values (avg_).
213
214   SHOW SERVERS;
215       type   S, for server.
216
217       user   User name pgbouncer uses to connect to server.
218
219       database
220              Database name.
221
222       state  State of the pgbouncer server connection, one of active, used or
223              idle.
224
225       addr   IP address of PostgreSQL server.
226
227       port   Port of PostgreSQL server.
228
229       local_addr
230              Connection start address on local machine.
231
232       local_port
233              Connection start port on local machine.
234
235       connect_time
236              When the connection was made.
237
238       request_time
239              When last request was issued.
240
241       ptr    Address  of internal object for this connection.  Used as unique
242              ID.
243
244       link   Address of client connection the server is paired with.
245
246       remote_pid
247              PID of backend server process.  In case connection is made  over
248              Unix socket and OS supports getting process ID info, its OS PID.
249              Otherwise it's extracted from cancel packet server  sent,  which
250              should  be  PID  in case server is PostgreSQL, but it's a random
251              number in case server it is another PgBouncer.
252
253   SHOW CLIENTS;
254       type   C, for client.
255
256       user   Client connected user.
257
258       database
259              Database name.
260
261       state  State of the client connection, one of active, used, waiting  or
262              idle.
263
264       addr   IP address of client.
265
266       port   Port client is connected to.
267
268       local_addr
269              Connection end address on local machine.
270
271       local_port
272              Connection end port on local machine.
273
274       connect_time
275              Timestamp of connect time.
276
277       request_time
278              Timestamp of latest client request.
279
280       ptr    Address  of internal object for this connection.  Used as unique
281              ID.
282
283       link   Address of server connection the client is paired with.
284
285       remote_pid
286              Process ID, in case client connects over Unix socket and OS sup‐
287              ports getting it.
288
289   SHOW POOLS;
290       A new pool entry is made for each couple of (database, user).
291
292       database
293              Database name.
294
295       user   User name.
296
297       cl_active
298              Client  connections that are linked to server connection and can
299              process queries.
300
301       cl_waiting
302              Client connections have sent queries but  have  not  yet  got  a
303              server connection.
304
305       sv_active
306              Server connections that linked to client.
307
308       sv_idle
309              Server connections that unused and immediately usable for client
310              queries.
311
312       sv_used
313              Server   connections   that   have   been   idle    more    than
314              server_check_delay,  so  they needs server_check_query to run on
315              it before it can be used.
316
317       sv_tested
318              Server   connections   that   are   currently   running   either
319              server_reset_query or server_check_query.
320
321       sv_login
322              Server connections currently in logging in process.
323
324       maxwait
325              How  long the first (oldest) client in queue has waited, in sec‐
326              onds.  If this starts  increasing,  then  the  current  pool  of
327              servers  does  not  handle requests quick enough.  Reason may be
328              either overloaded server or just too small of a  pool_size  set‐
329              ting.
330
331       pool_mode
332              The pooling mode in use.
333
334   SHOW LISTS;
335       Show following internal information, in columns (not rows):
336
337       databases
338              Count of databases.
339
340       users  Count of users.
341
342       pools  Count of pools.
343
344       free_clients
345              Count of free clients.
346
347       used_clients
348              Count of used clients.
349
350       login_clients
351              Count of clients in login state.
352
353       free_servers
354              Count of free servers.
355
356       used_servers
357              Count of used servers.
358
359   SHOW USERS;
360       name   The user name
361
362       pool_mode
363              The  user's  override  pool_mode, or NULL if the default will be
364              used instead.
365
366   SHOW DATABASES;
367       name   Name of configured database entry.
368
369       host   Host pgbouncer connects to.
370
371       port   Port pgbouncer connects to.
372
373       database
374              Actual database name pgbouncer connects to.
375
376       force_user
377              When user is part  of  the  connection  string,  the  connection
378              between  pgbouncer  and  PostgreSQL is forced to the given user,
379              whatever the client user.
380
381       pool_size
382              Maximum number of server connections.
383
384       pool_mode
385              The database's override pool_mode, or NULL if the  default  will
386              be used instead.
387
388   SHOW FDS;
389       Internal  command - shows list of file descriptors in use with internal
390       state attached to them.
391
392       When the connected user has user  name  "pgbouncer",  connects  through
393       Unix socket and has same UID as the running process, the actual FDs are
394       passed over the connection.  This mechanism is used  to  do  an  online
395       restart.  Note: This does not work on Windows machines.
396
397       This  command  also blocks the internal event loop, so it should not be
398       used while PgBouncer is in use.
399
400       fd     File descriptor numeric value.
401
402       task   One of pooler, client or server.
403
404       user   User of the connection using the FD.
405
406       database
407              Database of the connection using the FD.
408
409       addr   IP address of the connection using the FD, unix if a Unix socket
410              is used.
411
412       port   Port used by the connection using the FD.
413
414       cancel Cancel key for this connection.
415
416       link   fd for corresponding server/client.  NULL if idle.
417
418   SHOW CONFIG;
419       Show  the  current  configuration settings, one per row, with following
420       columns:
421
422       key    Configuration variable name
423
424       value  Configuration value
425
426       changeable
427              Either yes or no, shows if the variable  can  be  changed  while
428              running.  If no, the variable can be changed only boot-time.
429
430   SHOW DNS_HOSTS;
431       Show host names in DNS cache.
432
433       hostname
434              Host name.
435
436       ttl    How many seconds until next lookup.
437
438       addrs  Comma separated list of addresses.
439
440   SHOW DNS_ZONES
441       Show DNS zones in cache.
442
443       zonename
444              Zone name.
445
446       serial Current serial.
447
448       count  Host names belonging to this zone.
449
450   Process controlling commands
451   PAUSE [db];
452       PgBouncer  tries  to disconnect from all servers, first waiting for all
453       queries to complete. The command will not return before all queries are
454       finished.  To be used at the time of database restart.
455
456       If database name is given, only that database will be paused.
457
458   DISABLE db;
459       Reject all new client connections on the given database.
460
461   ENABLE db;
462       Allow new client connections after a previous DISABLE command.
463
464   KILL db;
465       Immediately drop all client and server connections on given database.
466
467   SUSPEND;
468       All  socket  buffers are flushed and PgBouncer stops listening for data
469       on them.  The command will not return before all buffers are empty.  To
470       be used at the time of PgBouncer online reboot.
471
472   RESUME [db];
473       Resume work from previous PAUSE or SUSPEND command.
474
475   SHUTDOWN;
476       The PgBouncer process will exit.
477
478   RELOAD;
479       The  PgBouncer  process  will  reload its configuration file and update
480       changeable settings.
481
482   Signals
483       SIGHUP Reload config. Same as issuing command RELOAD; on console.
484
485       SIGINT Safe shutdown. Same as issuing PAUSE; and SHUTDOWN; on console.
486
487       SIGTERM
488              Immediate shutdown.  Same as issuing SHUTDOWN; on console.
489
490   Libevent settings
491       From libevent docs:
492
493          It is possible to disable support for epoll, kqueue, devpoll, poll
494          or select by setting the environment variable EVENT_NOEPOLL,
495          EVENT_NOKQUEUE, EVENT_NODEVPOLL, EVENT_NOPOLL or EVENT_NOSELECT,
496          respectively.
497
498          By setting the environment variable EVENT_SHOW_METHOD, libevent
499          displays the kernel notification method that it uses.
500

SEE ALSO

502       pgbouncer(5) - man page of configuration settings descriptions.
503
504       https://pgbouncer.github.io/
505
506       https://wiki.postgresql.org/wiki/PgBouncer
507
508
509
510
5111.8.1                             2017-12-20                      PGBOUNCER(1)
Impressum