-
Notifications
You must be signed in to change notification settings - Fork 29
/
pgreplay.html
486 lines (354 loc) · 13 KB
/
pgreplay.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Mon May 22 10:06:02 2023 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>pgreplay</title>
</head>
<body>
<h1 align="center">pgreplay</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#OPTIONS">OPTIONS</a><br>
<a href="#ENVIRONMENT">ENVIRONMENT</a><br>
<a href="#LIMITATIONS">LIMITATIONS</a><br>
<a href="#AUTHOR">AUTHOR</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">pgreplay
− PostgreSQL log file replayer for performance
tests</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>pgreplay</b>
[<i>parse options</i>] [<i>replay options</i>] [<b>-d</b>
<i>level</i>] [<i>infile</i>] <b><br>
pgreplay -f</b> [<i>parse options</i>] [<b>-o</b>
<i>outfile</i>] [<b>-d</b> <i>level</i>] [<i>infile</i>]
<b><br>
pgreplay -r</b> [<i>replay options</i>] [<b>-d</b>
<i>level</i>] [<i>infile</i>]</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>pgreplay</b>
reads a PostgreSQL log file (<i>not</i> a WAL file),
extracts the SQL statements and executes them in the same
order and relative time against a PostgreSQL database
cluster. A final report gives you a useful statistical
analysis of your workload and its execution.</p>
<p style="margin-left:11%; margin-top: 1em">In the first
form, the log file <i>infile</i> is replayed at the time it
is read.</p>
<p style="margin-left:11%; margin-top: 1em">With the
<b>-f</b> option, <b>pgreplay</b> will not execute the
statements, but write them to a ‘replay file’
<i>outfile</i> that can be replayed with the third form.</p>
<p style="margin-left:11%; margin-top: 1em">With the
<b>-r</b> option, <b>pgreplay</b> will execute the
statements in the replay file <i>infile</i> that was created
by the second form.</p>
<p style="margin-left:11%; margin-top: 1em">If the
execution of statements gets behind schedule, warning
messages are issued that indicate that the server cannot
handle the load in a timely fashion. The idea is to replay a
real-world database workload as exactly as possible.</p>
<p style="margin-left:11%; margin-top: 1em">To create a log
file that can be parsed by <b>pgreplay</b>, you need to set
the following parameters in <b>postgresql.conf</b>:</p>
<p style="margin-left:22%; margin-top: 1em"><b>log_min_messages=error</b>
(or more) <b><br>
log_min_error_statement=log</b> (or more) <b><br>
log_connections=on <br>
log_disconnections=on <br>
log_line_prefix='%m|%u|%d|%c|'</b> (if you don't use CSV
logging) <b><br>
log_statement='all' <br>
lc_messages</b> must be set to English (encoding does not
matter) <b><br>
bytea_output=escape</b> (from version 9.0 on, only if you
want to replay the log on 8.4 or earlier)</p>
<p style="margin-left:11%; margin-top: 1em">The database
cluster against which you replay the SQL statements must be
a clone of the database cluster that generated the logs from
the time <i>immediately before</i> the logs were
generated.</p>
<p style="margin-left:11%; margin-top: 1em"><b>pgreplay</b>
is useful for performance tests, particularly in the
following situations:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>You want to compare the performance of your PostgreSQL
application on different hardware or different operating
systems.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>You want to upgrade your database and want to make sure
that the new database version does not suffer from
performance regressions that affect you.</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">Moreover,
<b>pgreplay</b> can give you some feeling as to how your
application <i>might</i> scale by allowing you to try to
replay the workload at a higher speed. Be warned, though,
that 500 users working at double speed is not really the
same as 1000 users working at normal speed.</p>
<h2>OPTIONS
<a name="OPTIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>Parse
options:</b></p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="3%">
<p style="margin-top: 1em"><b>-c</b></p></td>
<td width="8%"></td>
<td width="78%">
<p style="margin-top: 1em">Specifies that the log file is
in 'csvlog' format (highly recommended) and not in 'stderr'
format.</p> </td></tr>
</table>
<p style="margin-left:11%;"><b>-b</b> <i>timestamp</i></p>
<p style="margin-left:22%;">Only log entries greater or
equal to that timestamp will be parsed. The format is
<b>YYYY-MM-DD HH:MM:SS.FFF</b> like in the log file. An
optional time zone part will be ignored.</p>
<p style="margin-left:11%;"><b>-e</b> <i>timestamp</i></p>
<p style="margin-left:22%;">Only log entries less or equal
to that timestamp will be parsed. The format is
<b>YYYY-MM-DD HH:MM:SS.FFF</b> like in the log file. An
optional time zone part will be ignored.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="3%">
<p><b>-q</b></p></td>
<td width="8%"></td>
<td width="78%">
<p>Specifies that a backslash in a simple string literal
will escape the following single quote. This depends on
configuration options like
<b>standard_conforming_strings</b> and is the default for
server version 9.0 and less.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>-D</b> <i>database</i></p>
<p style="margin-left:22%;">Only log entries related to the
specified database will be parsed (this option can be
specified multiple times for more than one database).</p>
<p style="margin-left:11%;"><b>-U</b> <i>username</i></p>
<p style="margin-left:22%;">Only log entries related to the
specified username will be parsed (this option can be
specified multiple times for more than one user).</p>
<p style="margin-left:11%; margin-top: 1em"><b>Replay
options: <br>
-h</b> <i>hostname</i></p>
<p style="margin-left:22%;">Host name where the target
database cluster is running (or directory where the UNIX
socket can be found). Defaults to local connections. <br>
This works just like the <b>-h</b> option of
<b>psql</b>.</p>
<p style="margin-left:11%;"><b>-p</b> <i>port</i></p>
<p style="margin-left:22%;">TCP port where the target
database cluster can be reached.</p>
<p style="margin-left:11%;"><b>-W</b> <i>password</i></p>
<p style="margin-left:22%;">By default, <b>pgreplay</b>
assumes that the target database cluster is configured for
<i>trust</i> authentication. With the <b>-W</b> option you
can specify a password that will be used for all users in
the cluster.</p>
<p style="margin-left:11%;"><b>-s</b> <i>factor</i></p>
<p style="margin-left:22%;">Speed factor for replay, by
default 1. This can be any valid positive floating point
number. A <i>factor</i> less than 1 will replay the workload
in ‘slow motion’, while a <i>factor</i> greater
than 1 means ‘fast forward’.</p>
<p style="margin-left:11%;"><b>-E</b> <i>encoding</i></p>
<p style="margin-left:22%;">Specifies the encoding of the
log file, which will be used as client encoding during
replay. If it is omitted, your default client encoding will
be used.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="3%">
<p><b>-j</b></p></td>
<td width="8%"></td>
<td width="78%">
<p>If all connections are idle, jump ahead to the next
request instead of sleeping. This will speed up replay.
Execution delays will still be reported correctly, but
replay statistics will not contain the idle time.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="3%">
<p><b>-n</b></p></td>
<td width="8%"></td>
<td width="78%">
<p>Dry run mode. No connections to the server are made.
Useful for checking if the replay file is corrupt or to get
statistics about the replay file (number of statements,
original duration, ...)</p></td></tr>
</table>
<p style="margin-left:11%;"><b>-X</b> <i>options</i></p>
<p style="margin-left:22%;">Extra connection options for
replay connections. These must be libpq connection options
specified in the format ‘option=value
[...]’.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Output
options: <br>
-o</b> <i>outfile</i></p>
<p style="margin-left:22%;">specifies the replay file where
the statements will be written for later replay.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Debug
options: <br>
-d</b> <i>level</i></p>
<p style="margin-left:22%;">Specifies the trace level
(between 1 and 3). Increasing levels will produce more
detailed information about what <b>pgreplay</b> is
doing.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="3%">
<p><b>-v</b></p></td>
<td width="8%"></td>
<td width="56%">
<p>Prints the program version and exits.</p></td>
<td width="22%">
</td></tr>
</table>
<h2>ENVIRONMENT
<a name="ENVIRONMENT"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>PGHOST</b></p></td>
<td width="2%"></td>
<td width="70%">
<p style="margin-top: 1em">Specifies the default value for
the <b>-h</b> option.</p></td>
<td width="8%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>PGPORT</b></p></td>
<td width="2%"></td>
<td width="70%">
<p>Specifies the default value for the <b>-p</b>
option.</p> </td>
<td width="8%">
</td></tr>
</table>
<p style="margin-left:11%;"><b>PGCLIENTENCODING</b></p>
<p style="margin-left:22%;">Specifies the default value for
the <b>-E</b> option.</p>
<h2>LIMITATIONS
<a name="LIMITATIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>pgreplay</b>
can only replay what is logged by PostgreSQL. This leads to
some limitations:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p><b>COPY</b> statements will not be replayed, because the
copy data are not logged.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>Fast-path API function calls are not logged and will not
be replayed. Unfortunately, this includes the Large Object
API.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>Since the log file is always in the server encoding
(which you can specify with the <b>-E</b> switch of
<b>pgreplay</b>), all <b>SET client_encoding</b> statements
will be ignored.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>Since the preparation time of prepared statements is not
logged (unless <b>log_min_messages</b> is <b>debug2</b> or
more), these statements will be prepared immediately before
they are first executed during replay.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>Because the log file contains only text, query
parameters and return values will always be in text and
never in binary format. If you use binary mode to, say,
transfer large binary data, <b>pgreplay</b> can cause
significantly more network traffic than the original
run.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="5%"></td>
<td width="83%">
<p>Sometimes, if a connection takes longer to complete, the
session ID unexpectedly changes in the PostgreSQL log file.
This causes <b>pgreplay</b> to treat the session as two
different ones, resulting in an additional connection. This
is arguably a bug in PostgreSQL.</p></td></tr>
</table>
<h2>AUTHOR
<a name="AUTHOR"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Written by
Laurenz Albe <b><[email protected]></b>.</p>
<hr>
</body>
</html>