1PGBOUNCER(1) [FIXME: manual] PGBOUNCER(1)
2
3
4
6 pgbouncer - Lightweight connection pooler for PostgreSQL.
7
9 pgbouncer [-d][-R][-v][-u user] <pgbouncer.ini>
10 pgbouncer -V|-h
11
12
13 On Windows computers, the options are:
14
15 pgbouncer.exe [-v][-u user] <pgbouncer.ini>
16 pgbouncer.exe -V|-h
17
18
19 Additional options for setting up a Windows service:
20
21 pgbouncer.exe -regservice <pgbouncer.ini>
22 pgbouncer.exe -unregservice <pgbouncer.ini>
23
25 pgbouncer is a PostgreSQL connection pooler. Any target application can
26 be connected to pgbouncer as if it were a PostgreSQL server, and
27 pgbouncer will create a connection to the actual server, or it will
28 reuse one of its existing connections.
29
30 The aim of pgbouncer is to lower the performance impact of opening new
31 connections to PostgreSQL.
32
33 In order not to compromise transaction semantics for connection
34 pooling, pgbouncer supports several types of pooling when rotating
35 connections:
36
37 Session pooling
38 Most polite method. When client connects, a server connection will
39 be assigned to it for the whole duration the client stays
40 connected. When the client disconnects, the server connection will
41 be put back into the pool. This is the default method.
42
43 Transaction pooling
44 A server connection is assigned to client only during a
45 transaction. When PgBouncer notices that transaction is over, the
46 server connection will be put back into the pool.
47
48 Statement pooling
49 Most aggressive method. The server connection will be put back into
50 pool immediately after a query completes. Multi-statement
51 transactions are disallowed in this mode as they would break.
52
53 The administration interface of pgbouncer consists of some new SHOW
54 commands available when connected to a special virtual database
55 pgbouncer.
56
58 Basic setup and usage as following.
59
60 1. Create a pgbouncer.ini file. Details in pgbouncer(5). Simple
61 example:
62
63 [databases]
64 template1 = host=127.0.0.1 port=5432 dbname=template1
65
66 [pgbouncer]
67 listen_port = 6543
68 listen_addr = 127.0.0.1
69 auth_type = md5
70 auth_file = users.txt
71 logfile = pgbouncer.log
72 pidfile = pgbouncer.pid
73 admin_users = someuser
74
75 2. Create a users.txt file:
76
77 "someuser" "same_password_as_in_server"
78
79 3. Launch pgbouncer:
80
81 $ pgbouncer -d pgbouncer.ini
82
83 4. Have your application (or the psql client) connect to pgbouncer
84 instead of directly to PostgreSQL server.
85
86 $ psql -p 6543 -U someuser template1
87
88 5. Manage pgbouncer by connecting to the special administration
89 database pgbouncer and issuing show help; to begin:
90
91 $ psql -p 6543 -U someuser pgbouncer
92 pgbouncer=# show help;
93 NOTICE: Console usage
94 DETAIL:
95 SHOW [HELP|CONFIG|DATABASES|FDS|POOLS|CLIENTS|SERVERS|SOCKETS|LISTS|VERSION]
96 SET key = arg
97 RELOAD
98 PAUSE
99 SUSPEND
100 RESUME
101 SHUTDOWN
102
103 6. If you made changes to the pgbouncer.ini file, you can reload it
104 with:
105
106 pgbouncer=# RELOAD;
107
109 -d
110 Run in background. Without it the process will run in foreground.
111 Note: Does not work on Windows, pgbouncer need to run as service
112 there.
113
114 -R
115 Do an online restart. That means connecting to the running process,
116 loading the open sockets from it, and then using them. If there is
117 no active process, boot normally. Note: Does not work on Windows
118 machines.
119
120 -u user
121 Switch to the given user on startup.
122
123 -v
124 Increase verbosity. Can be used multiple times.
125
126 -q
127 Be quiet - do not log to stdout. Note this does not affect logging
128 verbosity, only that stdout is not to be used. For use in init.d
129 scripts.
130
131 -V
132 Show version.
133
134 -h
135 Show short help.
136
137 -regservice
138 Win32: Register pgbouncer to run as Windows service. The
139 service_name config parameter value is used as name to register
140 under.
141
142 -unregservice
143 Win32: Unregister Windows service.
144
146 The console is available by connecting as normal to the database
147 pgbouncer
148
149 $ psql -p 6543 pgbouncer
150
151
152 Only users listed in configuration parameters admin_users or
153 stats_users are allowed to login to the console. (Except when
154 auth_mode=any, then any user is allowed in as an admin.)
155
156 Additionally, the username pgbouncer is allowed to log in without
157 password, if the login comes via Unix socket and the client has same
158 Unix user uid as the running process.
159
160 SHOW COMMANDS
161 The SHOW commands output information. Each command is described below.
162
163 SHOW STATS;
164 Shows statistics.
165
166 database
167 Statistics are presented per database.
168
169 total_requests
170 Total number of SQL requests pooled by pgbouncer.
171
172 total_received
173 Total volume in bytes of network traffic received by pgbouncer.
174
175 total_sent
176 Total volume in bytes of network traffic sent by pgbouncer.
177
178 total_query_time
179 Total number of microseconds spent by pgbouncer when actively
180 connected to PostgreSQL.
181
182 avg_req
183 Average requests per second in last stat period.
184
185 avg_recv
186 Average received (from clients) bytes per second.
187
188 avg_sent
189 Average sent (to clients) bytes per second.
190
191 avg_query
192 Average query duration in microseconds.
193
194 SHOW SERVERS;
195 type
196 S, for server.
197
198 user
199 Username pgbouncer uses to connect to server.
200
201 database
202 Database name.
203
204 state
205 State of the pgbouncer server connection, one of active, used
206 or idle.
207
208 addr
209 IP address of PostgreSQL server.
210
211 port
212 Port of PostgreSQL server.
213
214 local_addr
215 Connection start address on local machine.
216
217 local_port
218 Connection start port on local machine.
219
220 connect_time
221 When the connection was made.
222
223 request_time
224 When last request was issued.
225
226 ptr
227 Address of internal object for this connection. Used as unique
228 ID.
229
230 link
231 Address of client connection the server is paired with.
232
233 SHOW CLIENTS;
234 type
235 C, for client.
236
237 user
238 Client connected user.
239
240 database
241 Database name.
242
243 state
244 State of the client connection, one of active, used, waiting or
245 idle.
246
247 addr
248 IP address of client.
249
250 port
251 Port client is connected to.
252
253 local_addr
254 Connection end address on local machine.
255
256 local_port
257 Connection end port on local machine.
258
259 connect_time
260 Timestamp of connect time.
261
262 request_time
263 Timestamp of latest client request.
264
265 ptr
266 Address of internal object for this connection. Used as unique
267 ID.
268
269 link
270 Address of server connection the client is paired with.
271
272 SHOW POOLS;
273 A new pool entry is made for each couple of (database, user).
274
275 database
276 Database name.
277
278 user
279 Username.
280
281 cl_active
282 Count of currently active client connections.
283
284 cl_waiting
285 Count of currently waiting client connections.
286
287 sv_active
288 Count of currently active server connections.
289
290 sv_idle
291 Count of currently idle server connections.
292
293 sv_used
294 Count of currently used server connections.
295
296 sv_tested
297 Count of currently tested server connections.
298
299 sv_login
300 Count of server connections currently logged in to PostgreSQL.
301
302 maxwait
303 How long the first (oldest) client in queue has waited, in
304 seconds. If this starts increasing, then the current pool of
305 servers does not handle requests quick enough. Reason may be
306 either overloaded server or just too small of a pool_size
307 setting.
308
309 SHOW LISTS;
310 Show following internal information, in columns (not rows):
311
312 databases
313 Count of databases.
314
315 users
316 Count of users.
317
318 pools
319 Count of pools.
320
321 free_clients
322 Count of free clients.
323
324 used_clients
325 Count of used clients.
326
327 login_clients
328 Count of clients in login state.
329
330 free_servers
331 Count of free servers.
332
333 used_servers
334 Count of used servers.
335
336 SHOW USERS;
337 Shows one line per user, under the name column name.
338
339 SHOW DATABASES;
340 name
341 Name of configured database entry.
342
343 host
344 Host pgbouncer connects to.
345
346 port
347 Port pgbouncer connects to.
348
349 database
350 Actual database name pgbouncer connects to.
351
352 force_user
353 When user is part of the connection string, the connection
354 between pgbouncer and PostgreSQL is forced to the given user,
355 whatever the client user.
356
357 pool_size
358 Maximum number of server connections.
359
360 SHOW FDS;
361 Shows list of fds in use. When the connected user has username
362 "pgbouncer", connects through Unix socket and has same UID as
363 running process, the actual fds are passed over the connection.
364 This mechanism is used to do an online restart. Note: This does not
365 work on Windows machines.
366
367 fd
368 File descriptor numeric value.
369
370 task
371 One of pooler, client or server.
372
373 user
374 User of the connection using the FD.
375
376 database
377 Database of the connection using the FD.
378
379 addr
380 IP address of the connection using the FD, unix if a unix
381 socket is used.
382
383 port
384 Port used by the connection using the FD.
385
386 cancel
387 Cancel key for this connection.
388
389 link
390 fd for corresponding server/client. NULL if idle.
391
392 SHOW CONFIG;
393 Show the current configuration settings, one per row, with
394 following columns:
395
396 key
397 Configuration variable name
398
399 value
400 Configuration value
401
402 changeable
403 Either yes or no, shows if the variable can be changed while
404 running. If no, the variable can be changed only boot-time.
405
406 PROCESS CONTROLLING COMMANDS
407 PAUSE;
408 PgBouncer tries to disconnect from all servers, first waiting for
409 all queries to complete. The command will not return before all
410 queries are finished. To be used at the time of database restart.
411
412 SUSPEND;
413 All socket buffers are flushed and PgBouncer stops listening for
414 data on them. The command will not return before all buffers are
415 empty. To be used at the time of PgBouncer online reboot.
416
417 RESUME;
418 Resume work from previous PAUSE or SUSPEND command.
419
420 SHUTDOWN;
421 The PgBouncer process will exit.
422
423 RELOAD;
424 The PgBouncer process will reload its configuration file and update
425 changeable settings.
426
427 SIGNALS
428 SIGHUP
429 Reload config. Same as issuing command RELOAD; on console.
430
431 SIGINT
432 Safe shutdown. Same as issuing PAUSE; and SHUTDOWN; on console.
433
434 SIGTERM
435 Immediate shutdown. Same as issuing SHUTDOWN; on console.
436
437 LIBEVENT SETTINGS
438 From libevent docs:
439
440 It is possible to disable support for epoll, kqueue, devpoll, poll
441 or select by setting the environment variable EVENT_NOEPOLL,
442 EVENT_NOKQUEUE, EVENT_NODEVPOLL, EVENT_NOPOLL or EVENT_NOSELECT,
443 respectively.
444
445 By setting the environment variable EVENT_SHOW_METHOD, libevent
446 displays the kernel notification method that it uses.
447
449 pgbouncer(5) - manpage of configuration settings descriptions.
450
451 http://pgbouncer.projects.postgresql.org/doc/
452
453 https://developer.skype.com/SkypeGarage/DbProjects/PgBouncer
454
455
456
457[FIXME: source] 01/15/2010 PGBOUNCER(1)