~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/pgbench.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>pgbench</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="Additional Supplied Modules"
 
16
HREF="contrib.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="pg_archivecleanup"
 
19
HREF="pgarchivecleanup.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="pg_buffercache"
 
22
HREF="pgbuffercache.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="SECT1"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="pg_archivecleanup"
 
57
HREF="pgarchivecleanup.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="Additional Supplied Modules"
 
67
HREF="contrib.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
>Appendix F. Additional Supplied Modules</TD
 
75
><TD
 
76
WIDTH="10%"
 
77
ALIGN="right"
 
78
VALIGN="top"
 
79
><A
 
80
TITLE="Additional Supplied Modules"
 
81
HREF="contrib.html"
 
82
>Fast Forward</A
 
83
></TD
 
84
><TD
 
85
WIDTH="10%"
 
86
ALIGN="right"
 
87
VALIGN="top"
 
88
><A
 
89
TITLE="pg_buffercache"
 
90
HREF="pgbuffercache.html"
 
91
ACCESSKEY="N"
 
92
>Next</A
 
93
></TD
 
94
></TR
 
95
></TABLE
 
96
><HR
 
97
ALIGN="LEFT"
 
98
WIDTH="100%"></DIV
 
99
><DIV
 
100
CLASS="SECT1"
 
101
><H1
 
102
CLASS="SECT1"
 
103
><A
 
104
NAME="PGBENCH"
 
105
>F.26. pgbench</A
 
106
></H1
 
107
><P
 
108
>  <SPAN
 
109
CLASS="APPLICATION"
 
110
>pgbench</SPAN
 
111
> is a simple program for running benchmark
 
112
  tests on <SPAN
 
113
CLASS="PRODUCTNAME"
 
114
>PostgreSQL</SPAN
 
115
>.  It runs the same sequence of SQL
 
116
  commands over and over, possibly in multiple concurrent database sessions,
 
117
  and then calculates the average transaction rate (transactions per second).
 
118
  By default, <SPAN
 
119
CLASS="APPLICATION"
 
120
>pgbench</SPAN
 
121
> tests a scenario that is
 
122
  loosely based on TPC-B, involving five <TT
 
123
CLASS="COMMAND"
 
124
>SELECT</TT
 
125
>,
 
126
  <TT
 
127
CLASS="COMMAND"
 
128
>UPDATE</TT
 
129
>, and <TT
 
130
CLASS="COMMAND"
 
131
>INSERT</TT
 
132
> commands per transaction.
 
133
  However, it is easy to test other cases by writing your own transaction
 
134
  script files.
 
135
 </P
 
136
><P
 
137
>  Typical output from pgbench looks like:
 
138
 
 
139
</P><PRE
 
140
CLASS="SCREEN"
 
141
>transaction type: TPC-B (sort of)
 
142
scaling factor: 10
 
143
query mode: simple
 
144
number of clients: 10
 
145
number of threads: 1
 
146
number of transactions per client: 1000
 
147
number of transactions actually processed: 10000/10000
 
148
tps = 85.184871 (including connections establishing)
 
149
tps = 85.296346 (excluding connections establishing)</PRE
 
150
><P>
 
151
 
 
152
  The first six lines report some of the most important parameter
 
153
  settings.  The next line reports the number of transactions completed
 
154
  and intended (the latter being just the product of number of clients
 
155
  and number of transactions per client); these will be equal unless the run
 
156
  failed before completion.  (In <TT
 
157
CLASS="LITERAL"
 
158
>-T</TT
 
159
> mode, only the actual
 
160
  number of transactions is printed.)
 
161
  The last two lines report the number of transactions per second,
 
162
  figured with and without counting the time to start database sessions.
 
163
 </P
 
164
><DIV
 
165
CLASS="SECT2"
 
166
><H2
 
167
CLASS="SECT2"
 
168
><A
 
169
NAME="AEN132101"
 
170
>F.26.1. Overview</A
 
171
></H2
 
172
><P
 
173
>   The default TPC-B-like transaction test requires specific tables to be
 
174
   set up beforehand.  <SPAN
 
175
CLASS="APPLICATION"
 
176
>pgbench</SPAN
 
177
> should be invoked with
 
178
   the <TT
 
179
CLASS="LITERAL"
 
180
>-i</TT
 
181
> (initialize) option to create and populate these
 
182
   tables.  (When you are testing a custom script, you don't need this
 
183
   step, but will instead need to do whatever setup your test needs.)
 
184
   Initialization looks like:
 
185
 
 
186
</P><PRE
 
187
CLASS="PROGRAMLISTING"
 
188
>pgbench -i [<SPAN
 
189
CLASS="OPTIONAL"
 
190
> <TT
 
191
CLASS="REPLACEABLE"
 
192
><I
 
193
>other-options</I
 
194
></TT
 
195
> </SPAN
 
196
>] <TT
 
197
CLASS="REPLACEABLE"
 
198
><I
 
199
>dbname</I
 
200
></TT
 
201
></PRE
 
202
><P>
 
203
 
 
204
   where <TT
 
205
CLASS="REPLACEABLE"
 
206
><I
 
207
>dbname</I
 
208
></TT
 
209
> is the name of the already-created
 
210
   database to test in.  (You may also need <TT
 
211
CLASS="LITERAL"
 
212
>-h</TT
 
213
>,
 
214
   <TT
 
215
CLASS="LITERAL"
 
216
>-p</TT
 
217
>, and/or <TT
 
218
CLASS="LITERAL"
 
219
>-U</TT
 
220
> options to specify how to
 
221
   connect to the database server.)
 
222
  </P
 
223
><DIV
 
224
CLASS="CAUTION"
 
225
><P
 
226
></P
 
227
><TABLE
 
228
CLASS="CAUTION"
 
229
BORDER="1"
 
230
WIDTH="100%"
 
231
><TR
 
232
><TD
 
233
ALIGN="CENTER"
 
234
><B
 
235
>Caution</B
 
236
></TD
 
237
></TR
 
238
><TR
 
239
><TD
 
240
ALIGN="LEFT"
 
241
><P
 
242
>    <TT
 
243
CLASS="LITERAL"
 
244
>pgbench -i</TT
 
245
> creates four tables <TT
 
246
CLASS="STRUCTNAME"
 
247
>pgbench_accounts</TT
 
248
>,
 
249
    <TT
 
250
CLASS="STRUCTNAME"
 
251
>pgbench_branches</TT
 
252
>, <TT
 
253
CLASS="STRUCTNAME"
 
254
>pgbench_history</TT
 
255
>, and
 
256
    <TT
 
257
CLASS="STRUCTNAME"
 
258
>pgbench_tellers</TT
 
259
>,
 
260
    destroying any existing tables of these names.
 
261
    Be very careful to use another database if you have tables having these
 
262
    names!
 
263
   </P
 
264
></TD
 
265
></TR
 
266
></TABLE
 
267
></DIV
 
268
><P
 
269
>   At the default <SPAN
 
270
CLASS="QUOTE"
 
271
>"scale factor"</SPAN
 
272
> of 1, the tables initially
 
273
   contain this many rows:
 
274
</P><PRE
 
275
CLASS="SCREEN"
 
276
>table                   # of rows
 
277
---------------------------------
 
278
pgbench_branches        1
 
279
pgbench_tellers         10
 
280
pgbench_accounts        100000
 
281
pgbench_history         0</PRE
 
282
><P>
 
283
   You can (and, for most purposes, probably should) increase the number
 
284
   of rows by using the <TT
 
285
CLASS="LITERAL"
 
286
>-s</TT
 
287
> (scale factor) option.  The
 
288
   <TT
 
289
CLASS="LITERAL"
 
290
>-F</TT
 
291
> (fillfactor) option might also be used at this point.
 
292
  </P
 
293
><P
 
294
>   Once you have done the necessary setup, you can run your benchmark
 
295
   with a command that doesn't include <TT
 
296
CLASS="LITERAL"
 
297
>-i</TT
 
298
>, that is
 
299
 
 
300
</P><PRE
 
301
CLASS="PROGRAMLISTING"
 
302
>pgbench [<SPAN
 
303
CLASS="OPTIONAL"
 
304
> <TT
 
305
CLASS="REPLACEABLE"
 
306
><I
 
307
>options</I
 
308
></TT
 
309
> </SPAN
 
310
>] <TT
 
311
CLASS="REPLACEABLE"
 
312
><I
 
313
>dbname</I
 
314
></TT
 
315
></PRE
 
316
><P>
 
317
 
 
318
   In nearly all cases, you'll need some options to make a useful test.
 
319
   The most important options are <TT
 
320
CLASS="LITERAL"
 
321
>-c</TT
 
322
> (number of clients),
 
323
   <TT
 
324
CLASS="LITERAL"
 
325
>-t</TT
 
326
> (number of transactions), <TT
 
327
CLASS="LITERAL"
 
328
>-T</TT
 
329
> (time limit),
 
330
   and <TT
 
331
CLASS="LITERAL"
 
332
>-f</TT
 
333
> (specify a custom script file).
 
334
   See below for a full list.
 
335
  </P
 
336
><P
 
337
>   <A
 
338
HREF="pgbench.html#PGBENCH-INIT-OPTIONS"
 
339
>Section F.26.2</A
 
340
> shows options that are used
 
341
   during database initialization, while
 
342
   <A
 
343
HREF="pgbench.html#PGBENCH-RUN-OPTIONS"
 
344
>Section F.26.3</A
 
345
> shows options that are used
 
346
   while running benchmarks, and
 
347
   <A
 
348
HREF="pgbench.html#PGBENCH-COMMON-OPTIONS"
 
349
>Section F.26.4</A
 
350
> shows options that are useful
 
351
   in both cases.
 
352
  </P
 
353
></DIV
 
354
><DIV
 
355
CLASS="SECT2"
 
356
><H2
 
357
CLASS="SECT2"
 
358
><A
 
359
NAME="PGBENCH-INIT-OPTIONS"
 
360
>F.26.2. <SPAN
 
361
CLASS="APPLICATION"
 
362
>pgbench</SPAN
 
363
> Initialization Options</A
 
364
></H2
 
365
><P
 
366
>    <SPAN
 
367
CLASS="APPLICATION"
 
368
>pgbench</SPAN
 
369
> accepts the following command-line
 
370
    initialization arguments:
 
371
 
 
372
    <P
 
373
></P
 
374
></P><DIV
 
375
CLASS="VARIABLELIST"
 
376
><DL
 
377
><DT
 
378
><TT
 
379
CLASS="OPTION"
 
380
>-i</TT
 
381
></DT
 
382
><DD
 
383
><P
 
384
>        Required to invoke initialization mode.
 
385
       </P
 
386
></DD
 
387
><DT
 
388
><TT
 
389
CLASS="OPTION"
 
390
>-F</TT
 
391
> <TT
 
392
CLASS="REPLACEABLE"
 
393
><I
 
394
>fillfactor</I
 
395
></TT
 
396
></DT
 
397
><DD
 
398
><P
 
399
>        Create the <TT
 
400
CLASS="STRUCTNAME"
 
401
>pgbench_accounts</TT
 
402
>,
 
403
        <TT
 
404
CLASS="STRUCTNAME"
 
405
>pgbench_tellers</TT
 
406
> and
 
407
        <TT
 
408
CLASS="STRUCTNAME"
 
409
>pgbench_branches</TT
 
410
> tables with the given fillfactor.
 
411
        Default is 100.
 
412
       </P
 
413
></DD
 
414
><DT
 
415
><TT
 
416
CLASS="OPTION"
 
417
>-s</TT
 
418
> <TT
 
419
CLASS="REPLACEABLE"
 
420
><I
 
421
>scale_factor</I
 
422
></TT
 
423
></DT
 
424
><DD
 
425
><P
 
426
>        Multiply the number of rows generated by the scale factor.
 
427
        For example, <TT
 
428
CLASS="LITERAL"
 
429
>-s 100</TT
 
430
> will create 10,000,000 rows
 
431
        in the <TT
 
432
CLASS="STRUCTNAME"
 
433
>pgbench_accounts</TT
 
434
> table. Default is 1.
 
435
       </P
 
436
></DD
 
437
></DL
 
438
></DIV
 
439
><P>
 
440
   </P
 
441
></DIV
 
442
><DIV
 
443
CLASS="SECT2"
 
444
><H2
 
445
CLASS="SECT2"
 
446
><A
 
447
NAME="PGBENCH-RUN-OPTIONS"
 
448
>F.26.3. <SPAN
 
449
CLASS="APPLICATION"
 
450
>pgbench</SPAN
 
451
> Benchmarking Options</A
 
452
></H2
 
453
><P
 
454
>    <SPAN
 
455
CLASS="APPLICATION"
 
456
>pgbench</SPAN
 
457
> accepts the following command-line
 
458
    benchmarking arguments:
 
459
 
 
460
    <P
 
461
></P
 
462
></P><DIV
 
463
CLASS="VARIABLELIST"
 
464
><DL
 
465
><DT
 
466
><TT
 
467
CLASS="OPTION"
 
468
>-c</TT
 
469
> <TT
 
470
CLASS="REPLACEABLE"
 
471
><I
 
472
>clients</I
 
473
></TT
 
474
></DT
 
475
><DD
 
476
><P
 
477
>        Number of clients simulated, that is, number of concurrent database
 
478
        sessions.  Default is 1.
 
479
       </P
 
480
></DD
 
481
><DT
 
482
><TT
 
483
CLASS="OPTION"
 
484
>-C</TT
 
485
></DT
 
486
><DD
 
487
><P
 
488
>        Establish a new connection for each transaction, rather than
 
489
        doing it just once per client session.
 
490
        This is useful to measure the connection overhead.
 
491
       </P
 
492
></DD
 
493
><DT
 
494
><TT
 
495
CLASS="OPTION"
 
496
>-d</TT
 
497
></DT
 
498
><DD
 
499
><P
 
500
>        Print debugging output.
 
501
       </P
 
502
></DD
 
503
><DT
 
504
><TT
 
505
CLASS="OPTION"
 
506
>-D</TT
 
507
> <TT
 
508
CLASS="REPLACEABLE"
 
509
><I
 
510
>varname</I
 
511
></TT
 
512
><TT
 
513
CLASS="LITERAL"
 
514
>=</TT
 
515
><TT
 
516
CLASS="REPLACEABLE"
 
517
><I
 
518
>value</I
 
519
></TT
 
520
></DT
 
521
><DD
 
522
><P
 
523
>        Define a variable for use by a custom script (see below).
 
524
        Multiple <TT
 
525
CLASS="LITERAL"
 
526
>-D</TT
 
527
> options are allowed.
 
528
       </P
 
529
></DD
 
530
><DT
 
531
><TT
 
532
CLASS="OPTION"
 
533
>-f</TT
 
534
> <TT
 
535
CLASS="REPLACEABLE"
 
536
><I
 
537
>filename</I
 
538
></TT
 
539
></DT
 
540
><DD
 
541
><P
 
542
>        Read transaction script from <TT
 
543
CLASS="REPLACEABLE"
 
544
><I
 
545
>filename</I
 
546
></TT
 
547
>.
 
548
        See below for details.
 
549
        <TT
 
550
CLASS="LITERAL"
 
551
>-N</TT
 
552
>, <TT
 
553
CLASS="LITERAL"
 
554
>-S</TT
 
555
>, and <TT
 
556
CLASS="LITERAL"
 
557
>-f</TT
 
558
>
 
559
        are mutually exclusive.
 
560
       </P
 
561
></DD
 
562
><DT
 
563
><TT
 
564
CLASS="OPTION"
 
565
>-j</TT
 
566
> <TT
 
567
CLASS="REPLACEABLE"
 
568
><I
 
569
>threads</I
 
570
></TT
 
571
></DT
 
572
><DD
 
573
><P
 
574
>        Number of worker threads within <SPAN
 
575
CLASS="APPLICATION"
 
576
>pgbench</SPAN
 
577
>.
 
578
        Using more than one thread can be helpful on multi-CPU machines.
 
579
        The number of clients must be a multiple of the number of threads,
 
580
        since each thread is given the same number of client sessions to manage.
 
581
        Default is 1.
 
582
       </P
 
583
></DD
 
584
><DT
 
585
><TT
 
586
CLASS="OPTION"
 
587
>-l</TT
 
588
></DT
 
589
><DD
 
590
><P
 
591
>        Write the time taken by each transaction to a log file.
 
592
        See below for details.
 
593
       </P
 
594
></DD
 
595
><DT
 
596
><TT
 
597
CLASS="OPTION"
 
598
>-M</TT
 
599
> <TT
 
600
CLASS="REPLACEABLE"
 
601
><I
 
602
>querymode</I
 
603
></TT
 
604
></DT
 
605
><DD
 
606
><P
 
607
>        Protocol to use for submitting queries to the server:
 
608
          <P
 
609
></P
 
610
></P><UL
 
611
><LI
 
612
><P
 
613
><TT
 
614
CLASS="LITERAL"
 
615
>simple</TT
 
616
>: use simple query protocol.</P
 
617
></LI
 
618
><LI
 
619
><P
 
620
><TT
 
621
CLASS="LITERAL"
 
622
>extended</TT
 
623
>: use extended query protocol.</P
 
624
></LI
 
625
><LI
 
626
><P
 
627
><TT
 
628
CLASS="LITERAL"
 
629
>prepared</TT
 
630
>: use extended query protocol with prepared statements.</P
 
631
></LI
 
632
></UL
 
633
><P>
 
634
        The default is simple query protocol.  (See <A
 
635
HREF="protocol.html"
 
636
>Chapter 46</A
 
637
>
 
638
        for more information.)
 
639
       </P
 
640
></DD
 
641
><DT
 
642
><TT
 
643
CLASS="OPTION"
 
644
>-n</TT
 
645
></DT
 
646
><DD
 
647
><P
 
648
>        Perform no vacuuming before running the test.
 
649
        This option is <SPAN
 
650
CLASS="emphasis"
 
651
><I
 
652
CLASS="EMPHASIS"
 
653
>necessary</I
 
654
></SPAN
 
655
>
 
656
        if you are running a custom test scenario that does not include
 
657
        the standard tables <TT
 
658
CLASS="STRUCTNAME"
 
659
>pgbench_accounts</TT
 
660
>,
 
661
        <TT
 
662
CLASS="STRUCTNAME"
 
663
>pgbench_branches</TT
 
664
>, <TT
 
665
CLASS="STRUCTNAME"
 
666
>pgbench_history</TT
 
667
>, and
 
668
        <TT
 
669
CLASS="STRUCTNAME"
 
670
>pgbench_tellers</TT
 
671
>.
 
672
       </P
 
673
></DD
 
674
><DT
 
675
><TT
 
676
CLASS="OPTION"
 
677
>-N</TT
 
678
></DT
 
679
><DD
 
680
><P
 
681
>        Do not update <TT
 
682
CLASS="STRUCTNAME"
 
683
>pgbench_tellers</TT
 
684
> and
 
685
        <TT
 
686
CLASS="STRUCTNAME"
 
687
>pgbench_branches</TT
 
688
>.
 
689
        This will avoid update contention on these tables, but
 
690
        it makes the test case even less like TPC-B.
 
691
       </P
 
692
></DD
 
693
><DT
 
694
><TT
 
695
CLASS="OPTION"
 
696
>-r</TT
 
697
></DT
 
698
><DD
 
699
><P
 
700
>        Report the average per-statement latency (execution time from the
 
701
        perspective of the client) of each command after the benchmark
 
702
        finishes.  See below for details.
 
703
       </P
 
704
></DD
 
705
><DT
 
706
><TT
 
707
CLASS="OPTION"
 
708
>-s</TT
 
709
> <TT
 
710
CLASS="REPLACEABLE"
 
711
><I
 
712
>scale_factor</I
 
713
></TT
 
714
></DT
 
715
><DD
 
716
><P
 
717
>        Report the specified scale factor in <SPAN
 
718
CLASS="APPLICATION"
 
719
>pgbench</SPAN
 
720
>'s
 
721
        output.  With the built-in tests, this is not necessary; the
 
722
        correct scale factor will be detected by counting the number of
 
723
        rows in the <TT
 
724
CLASS="STRUCTNAME"
 
725
>pgbench_branches</TT
 
726
> table.  However, when testing
 
727
        custom benchmarks (<TT
 
728
CLASS="LITERAL"
 
729
>-f</TT
 
730
> option), the scale factor
 
731
        will be reported as 1 unless this option is used.
 
732
       </P
 
733
></DD
 
734
><DT
 
735
><TT
 
736
CLASS="OPTION"
 
737
>-S</TT
 
738
></DT
 
739
><DD
 
740
><P
 
741
>        Perform select-only transactions instead of TPC-B-like test.
 
742
       </P
 
743
></DD
 
744
><DT
 
745
><TT
 
746
CLASS="OPTION"
 
747
>-t</TT
 
748
> <TT
 
749
CLASS="REPLACEABLE"
 
750
><I
 
751
>transactions</I
 
752
></TT
 
753
></DT
 
754
><DD
 
755
><P
 
756
>        Number of transactions each client runs.  Default is 10.
 
757
       </P
 
758
></DD
 
759
><DT
 
760
><TT
 
761
CLASS="OPTION"
 
762
>-T</TT
 
763
> <TT
 
764
CLASS="REPLACEABLE"
 
765
><I
 
766
>seconds</I
 
767
></TT
 
768
></DT
 
769
><DD
 
770
><P
 
771
>        Run the test for this many seconds, rather than a fixed number of
 
772
        transactions per client. <TT
 
773
CLASS="LITERAL"
 
774
>-t</TT
 
775
> and
 
776
        <TT
 
777
CLASS="LITERAL"
 
778
>-T</TT
 
779
> are mutually exclusive.
 
780
       </P
 
781
></DD
 
782
><DT
 
783
><TT
 
784
CLASS="OPTION"
 
785
>-v</TT
 
786
></DT
 
787
><DD
 
788
><P
 
789
>        Vacuum all four standard tables before running the test.
 
790
        With neither <TT
 
791
CLASS="LITERAL"
 
792
>-n</TT
 
793
> nor <TT
 
794
CLASS="LITERAL"
 
795
>-v</TT
 
796
>, pgbench will vacuum the
 
797
        <TT
 
798
CLASS="STRUCTNAME"
 
799
>pgbench_tellers</TT
 
800
> and <TT
 
801
CLASS="STRUCTNAME"
 
802
>pgbench_branches</TT
 
803
>
 
804
        tables, and will truncate <TT
 
805
CLASS="STRUCTNAME"
 
806
>pgbench_history</TT
 
807
>.
 
808
       </P
 
809
></DD
 
810
></DL
 
811
></DIV
 
812
><P>
 
813
   </P
 
814
></DIV
 
815
><DIV
 
816
CLASS="SECT2"
 
817
><H2
 
818
CLASS="SECT2"
 
819
><A
 
820
NAME="PGBENCH-COMMON-OPTIONS"
 
821
>F.26.4. <SPAN
 
822
CLASS="APPLICATION"
 
823
>pgbench</SPAN
 
824
> Common Options</A
 
825
></H2
 
826
><P
 
827
>    <SPAN
 
828
CLASS="APPLICATION"
 
829
>pgbench</SPAN
 
830
> accepts the following command-line
 
831
    common arguments:
 
832
 
 
833
    <P
 
834
></P
 
835
></P><DIV
 
836
CLASS="VARIABLELIST"
 
837
><DL
 
838
><DT
 
839
><TT
 
840
CLASS="OPTION"
 
841
>-h</TT
 
842
> <TT
 
843
CLASS="REPLACEABLE"
 
844
><I
 
845
>hostname</I
 
846
></TT
 
847
></DT
 
848
><DD
 
849
><P
 
850
>        The database server's host name
 
851
       </P
 
852
></DD
 
853
><DT
 
854
><TT
 
855
CLASS="OPTION"
 
856
>-p</TT
 
857
> <TT
 
858
CLASS="REPLACEABLE"
 
859
><I
 
860
>port</I
 
861
></TT
 
862
></DT
 
863
><DD
 
864
><P
 
865
>        The database server's port number
 
866
       </P
 
867
></DD
 
868
><DT
 
869
><TT
 
870
CLASS="OPTION"
 
871
>-U</TT
 
872
> <TT
 
873
CLASS="REPLACEABLE"
 
874
><I
 
875
>login</I
 
876
></TT
 
877
></DT
 
878
><DD
 
879
><P
 
880
>        The user name to connect as
 
881
       </P
 
882
></DD
 
883
></DL
 
884
></DIV
 
885
><P>
 
886
   </P
 
887
></DIV
 
888
><DIV
 
889
CLASS="SECT2"
 
890
><H2
 
891
CLASS="SECT2"
 
892
><A
 
893
NAME="AEN132322"
 
894
>F.26.5. What is the <SPAN
 
895
CLASS="QUOTE"
 
896
>"Transaction"</SPAN
 
897
> Actually Performed in pgbench?</A
 
898
></H2
 
899
><P
 
900
>   The default transaction script issues seven commands per transaction:
 
901
  </P
 
902
><P
 
903
></P
 
904
><OL
 
905
TYPE="1"
 
906
><LI
 
907
><P
 
908
><TT
 
909
CLASS="LITERAL"
 
910
>BEGIN;</TT
 
911
></P
 
912
></LI
 
913
><LI
 
914
><P
 
915
><TT
 
916
CLASS="LITERAL"
 
917
>UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</TT
 
918
></P
 
919
></LI
 
920
><LI
 
921
><P
 
922
><TT
 
923
CLASS="LITERAL"
 
924
>SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</TT
 
925
></P
 
926
></LI
 
927
><LI
 
928
><P
 
929
><TT
 
930
CLASS="LITERAL"
 
931
>UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</TT
 
932
></P
 
933
></LI
 
934
><LI
 
935
><P
 
936
><TT
 
937
CLASS="LITERAL"
 
938
>UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</TT
 
939
></P
 
940
></LI
 
941
><LI
 
942
><P
 
943
><TT
 
944
CLASS="LITERAL"
 
945
>INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</TT
 
946
></P
 
947
></LI
 
948
><LI
 
949
><P
 
950
><TT
 
951
CLASS="LITERAL"
 
952
>END;</TT
 
953
></P
 
954
></LI
 
955
></OL
 
956
><P
 
957
>   If you specify <TT
 
958
CLASS="LITERAL"
 
959
>-N</TT
 
960
>, steps 4 and 5 aren't included in the
 
961
   transaction.  If you specify <TT
 
962
CLASS="LITERAL"
 
963
>-S</TT
 
964
>, only the <TT
 
965
CLASS="COMMAND"
 
966
>SELECT</TT
 
967
> is
 
968
   issued.
 
969
  </P
 
970
></DIV
 
971
><DIV
 
972
CLASS="SECT2"
 
973
><H2
 
974
CLASS="SECT2"
 
975
><A
 
976
NAME="AEN132352"
 
977
>F.26.6. Custom Scripts</A
 
978
></H2
 
979
><P
 
980
>   <SPAN
 
981
CLASS="APPLICATION"
 
982
>pgbench</SPAN
 
983
> has support for running custom
 
984
   benchmark scenarios by replacing the default transaction script
 
985
   (described above) with a transaction script read from a file
 
986
   (<TT
 
987
CLASS="LITERAL"
 
988
>-f</TT
 
989
> option).  In this case a <SPAN
 
990
CLASS="QUOTE"
 
991
>"transaction"</SPAN
 
992
>
 
993
   counts as one execution of a script file.  You can even specify
 
994
   multiple scripts (multiple <TT
 
995
CLASS="LITERAL"
 
996
>-f</TT
 
997
> options), in which
 
998
   case a random one of the scripts is chosen each time a client session
 
999
   starts a new transaction.
 
1000
  </P
 
1001
><P
 
1002
>   The format of a script file is one SQL command per line; multiline
 
1003
   SQL commands are not supported.  Empty lines and lines beginning with
 
1004
   <TT
 
1005
CLASS="LITERAL"
 
1006
>--</TT
 
1007
> are ignored.  Script file lines can also be
 
1008
   <SPAN
 
1009
CLASS="QUOTE"
 
1010
>"meta commands"</SPAN
 
1011
>, which are interpreted by <SPAN
 
1012
CLASS="APPLICATION"
 
1013
>pgbench</SPAN
 
1014
>
 
1015
   itself, as described below.
 
1016
  </P
 
1017
><P
 
1018
>   There is a simple variable-substitution facility for script files.
 
1019
   Variables can be set by the command-line <TT
 
1020
CLASS="LITERAL"
 
1021
>-D</TT
 
1022
> option,
 
1023
   explained above, or by the meta commands explained below.
 
1024
   In addition to any variables preset by <TT
 
1025
CLASS="LITERAL"
 
1026
>-D</TT
 
1027
> command-line options,
 
1028
   the variable <TT
 
1029
CLASS="LITERAL"
 
1030
>scale</TT
 
1031
> is preset to the current scale factor.
 
1032
   Once set, a variable's
 
1033
   value can be inserted into a SQL command by writing
 
1034
   <TT
 
1035
CLASS="LITERAL"
 
1036
>:</TT
 
1037
><TT
 
1038
CLASS="REPLACEABLE"
 
1039
><I
 
1040
>variablename</I
 
1041
></TT
 
1042
>.  When running more than
 
1043
   one client session, each session has its own set of variables.
 
1044
  </P
 
1045
><P
 
1046
>   Script file meta commands begin with a backslash (<TT
 
1047
CLASS="LITERAL"
 
1048
>\</TT
 
1049
>).
 
1050
   Arguments to a meta command are separated by white space.
 
1051
   These meta commands are supported:
 
1052
  </P
 
1053
><P
 
1054
></P
 
1055
><DIV
 
1056
CLASS="VARIABLELIST"
 
1057
><DL
 
1058
><DT
 
1059
><TT
 
1060
CLASS="LITERAL"
 
1061
>\set <TT
 
1062
CLASS="REPLACEABLE"
 
1063
><I
 
1064
>varname</I
 
1065
></TT
 
1066
> <TT
 
1067
CLASS="REPLACEABLE"
 
1068
><I
 
1069
>operand1</I
 
1070
></TT
 
1071
> [ <TT
 
1072
CLASS="REPLACEABLE"
 
1073
><I
 
1074
>operator</I
 
1075
></TT
 
1076
> <TT
 
1077
CLASS="REPLACEABLE"
 
1078
><I
 
1079
>operand2</I
 
1080
></TT
 
1081
> ]</TT
 
1082
></DT
 
1083
><DD
 
1084
><P
 
1085
>      Sets variable <TT
 
1086
CLASS="REPLACEABLE"
 
1087
><I
 
1088
>varname</I
 
1089
></TT
 
1090
> to a calculated integer value.
 
1091
      Each <TT
 
1092
CLASS="REPLACEABLE"
 
1093
><I
 
1094
>operand</I
 
1095
></TT
 
1096
> is either an integer constant or a
 
1097
      <TT
 
1098
CLASS="LITERAL"
 
1099
>:</TT
 
1100
><TT
 
1101
CLASS="REPLACEABLE"
 
1102
><I
 
1103
>variablename</I
 
1104
></TT
 
1105
> reference to a variable
 
1106
      having an integer value.  The <TT
 
1107
CLASS="REPLACEABLE"
 
1108
><I
 
1109
>operator</I
 
1110
></TT
 
1111
> can be
 
1112
      <TT
 
1113
CLASS="LITERAL"
 
1114
>+</TT
 
1115
>, <TT
 
1116
CLASS="LITERAL"
 
1117
>-</TT
 
1118
>, <TT
 
1119
CLASS="LITERAL"
 
1120
>*</TT
 
1121
>, or <TT
 
1122
CLASS="LITERAL"
 
1123
>/</TT
 
1124
>.
 
1125
     </P
 
1126
><P
 
1127
>      Example:
 
1128
</P><PRE
 
1129
CLASS="PROGRAMLISTING"
 
1130
>\set ntellers 10 * :scale</PRE
 
1131
><P>
 
1132
     </P
 
1133
></DD
 
1134
><DT
 
1135
><TT
 
1136
CLASS="LITERAL"
 
1137
>\setrandom <TT
 
1138
CLASS="REPLACEABLE"
 
1139
><I
 
1140
>varname</I
 
1141
></TT
 
1142
> <TT
 
1143
CLASS="REPLACEABLE"
 
1144
><I
 
1145
>min</I
 
1146
></TT
 
1147
> <TT
 
1148
CLASS="REPLACEABLE"
 
1149
><I
 
1150
>max</I
 
1151
></TT
 
1152
></TT
 
1153
></DT
 
1154
><DD
 
1155
><P
 
1156
>      Sets variable <TT
 
1157
CLASS="REPLACEABLE"
 
1158
><I
 
1159
>varname</I
 
1160
></TT
 
1161
> to a random integer value
 
1162
      between the limits <TT
 
1163
CLASS="REPLACEABLE"
 
1164
><I
 
1165
>min</I
 
1166
></TT
 
1167
> and <TT
 
1168
CLASS="REPLACEABLE"
 
1169
><I
 
1170
>max</I
 
1171
></TT
 
1172
> inclusive.
 
1173
      Each limit can be either an integer constant or a
 
1174
      <TT
 
1175
CLASS="LITERAL"
 
1176
>:</TT
 
1177
><TT
 
1178
CLASS="REPLACEABLE"
 
1179
><I
 
1180
>variablename</I
 
1181
></TT
 
1182
> reference to a variable
 
1183
      having an integer value.
 
1184
     </P
 
1185
><P
 
1186
>      Example:
 
1187
</P><PRE
 
1188
CLASS="PROGRAMLISTING"
 
1189
>\setrandom aid 1 :naccounts</PRE
 
1190
><P>
 
1191
     </P
 
1192
></DD
 
1193
><DT
 
1194
><TT
 
1195
CLASS="LITERAL"
 
1196
>\sleep <TT
 
1197
CLASS="REPLACEABLE"
 
1198
><I
 
1199
>number</I
 
1200
></TT
 
1201
> [ us | ms | s ]</TT
 
1202
></DT
 
1203
><DD
 
1204
><P
 
1205
>      Causes script execution to sleep for the specified duration in
 
1206
      microseconds (<TT
 
1207
CLASS="LITERAL"
 
1208
>us</TT
 
1209
>), milliseconds (<TT
 
1210
CLASS="LITERAL"
 
1211
>ms</TT
 
1212
>) or seconds
 
1213
      (<TT
 
1214
CLASS="LITERAL"
 
1215
>s</TT
 
1216
>).  If the unit is omitted then seconds are the default.
 
1217
      <TT
 
1218
CLASS="REPLACEABLE"
 
1219
><I
 
1220
>number</I
 
1221
></TT
 
1222
> can be either an integer constant or a
 
1223
      <TT
 
1224
CLASS="LITERAL"
 
1225
>:</TT
 
1226
><TT
 
1227
CLASS="REPLACEABLE"
 
1228
><I
 
1229
>variablename</I
 
1230
></TT
 
1231
> reference to a variable
 
1232
      having an integer value.
 
1233
     </P
 
1234
><P
 
1235
>      Example:
 
1236
</P><PRE
 
1237
CLASS="PROGRAMLISTING"
 
1238
>\sleep 10 ms</PRE
 
1239
><P>
 
1240
     </P
 
1241
></DD
 
1242
><DT
 
1243
><TT
 
1244
CLASS="LITERAL"
 
1245
>\setshell <TT
 
1246
CLASS="REPLACEABLE"
 
1247
><I
 
1248
>varname</I
 
1249
></TT
 
1250
> <TT
 
1251
CLASS="REPLACEABLE"
 
1252
><I
 
1253
>command</I
 
1254
></TT
 
1255
> [ <TT
 
1256
CLASS="REPLACEABLE"
 
1257
><I
 
1258
>argument</I
 
1259
></TT
 
1260
> ... ]</TT
 
1261
></DT
 
1262
><DD
 
1263
><P
 
1264
>      Sets variable <TT
 
1265
CLASS="REPLACEABLE"
 
1266
><I
 
1267
>varname</I
 
1268
></TT
 
1269
> to the result of the shell command
 
1270
      <TT
 
1271
CLASS="REPLACEABLE"
 
1272
><I
 
1273
>command</I
 
1274
></TT
 
1275
>. The command must return an integer value
 
1276
      through its standard output.
 
1277
     </P
 
1278
><P
 
1279
>      <TT
 
1280
CLASS="REPLACEABLE"
 
1281
><I
 
1282
>argument</I
 
1283
></TT
 
1284
> can be either a text constant or a
 
1285
      <TT
 
1286
CLASS="LITERAL"
 
1287
>:</TT
 
1288
><TT
 
1289
CLASS="REPLACEABLE"
 
1290
><I
 
1291
>variablename</I
 
1292
></TT
 
1293
> reference to a variable of
 
1294
      any types. If you want to use <TT
 
1295
CLASS="REPLACEABLE"
 
1296
><I
 
1297
>argument</I
 
1298
></TT
 
1299
> starting with
 
1300
      colons, you need to add an additional colon at the beginning of
 
1301
      <TT
 
1302
CLASS="REPLACEABLE"
 
1303
><I
 
1304
>argument</I
 
1305
></TT
 
1306
>.
 
1307
     </P
 
1308
><P
 
1309
>      Example:
 
1310
</P><PRE
 
1311
CLASS="PROGRAMLISTING"
 
1312
>\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon</PRE
 
1313
><P>
 
1314
     </P
 
1315
></DD
 
1316
><DT
 
1317
><TT
 
1318
CLASS="LITERAL"
 
1319
>\shell <TT
 
1320
CLASS="REPLACEABLE"
 
1321
><I
 
1322
>command</I
 
1323
></TT
 
1324
> [ <TT
 
1325
CLASS="REPLACEABLE"
 
1326
><I
 
1327
>argument</I
 
1328
></TT
 
1329
> ... ]</TT
 
1330
></DT
 
1331
><DD
 
1332
><P
 
1333
>      Same as <TT
 
1334
CLASS="LITERAL"
 
1335
>\setshell</TT
 
1336
>, but the result is ignored.
 
1337
     </P
 
1338
><P
 
1339
>      Example:
 
1340
</P><PRE
 
1341
CLASS="PROGRAMLISTING"
 
1342
>\shell command literal_argument :variable ::literal_starting_with_colon</PRE
 
1343
><P>
 
1344
     </P
 
1345
></DD
 
1346
></DL
 
1347
></DIV
 
1348
><P
 
1349
>   As an example, the full definition of the built-in TPC-B-like
 
1350
   transaction is:
 
1351
 
 
1352
</P><PRE
 
1353
CLASS="PROGRAMLISTING"
 
1354
>\set nbranches :scale
 
1355
\set ntellers 10 * :scale
 
1356
\set naccounts 100000 * :scale
 
1357
\setrandom aid 1 :naccounts
 
1358
\setrandom bid 1 :nbranches
 
1359
\setrandom tid 1 :ntellers
 
1360
\setrandom delta -5000 5000
 
1361
BEGIN;
 
1362
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
 
1363
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
 
1364
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
 
1365
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
 
1366
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
 
1367
END;</PRE
 
1368
><P>
 
1369
 
 
1370
   This script allows each iteration of the transaction to reference
 
1371
   different, randomly-chosen rows.  (This example also shows why it's
 
1372
   important for each client session to have its own variables &mdash;
 
1373
   otherwise they'd not be independently touching different rows.)
 
1374
  </P
 
1375
></DIV
 
1376
><DIV
 
1377
CLASS="SECT2"
 
1378
><H2
 
1379
CLASS="SECT2"
 
1380
><A
 
1381
NAME="AEN132451"
 
1382
>F.26.7. Per-Transaction Logging</A
 
1383
></H2
 
1384
><P
 
1385
>   With the <TT
 
1386
CLASS="LITERAL"
 
1387
>-l</TT
 
1388
> option, <SPAN
 
1389
CLASS="APPLICATION"
 
1390
>pgbench</SPAN
 
1391
> writes the time
 
1392
   taken by each transaction to a log file.  The log file will be named
 
1393
   <TT
 
1394
CLASS="FILENAME"
 
1395
>pgbench_log.<TT
 
1396
CLASS="REPLACEABLE"
 
1397
><I
 
1398
>nnn</I
 
1399
></TT
 
1400
></TT
 
1401
>, where
 
1402
   <TT
 
1403
CLASS="REPLACEABLE"
 
1404
><I
 
1405
>nnn</I
 
1406
></TT
 
1407
> is the PID of the pgbench process.
 
1408
   If the <TT
 
1409
CLASS="LITERAL"
 
1410
>-j</TT
 
1411
> option is 2 or higher, creating multiple worker
 
1412
   threads, each will have its own log file. The first worker will use the
 
1413
   same name for its log file as in the standard single worker case.
 
1414
   The additional log files for the other workers will be named
 
1415
   <TT
 
1416
CLASS="FILENAME"
 
1417
>pgbench_log.<TT
 
1418
CLASS="REPLACEABLE"
 
1419
><I
 
1420
>nnn</I
 
1421
></TT
 
1422
>.<TT
 
1423
CLASS="REPLACEABLE"
 
1424
><I
 
1425
>mmm</I
 
1426
></TT
 
1427
></TT
 
1428
>,
 
1429
   where <TT
 
1430
CLASS="REPLACEABLE"
 
1431
><I
 
1432
>mmm</I
 
1433
></TT
 
1434
> is a sequential number for each worker starting
 
1435
   with 1.
 
1436
  </P
 
1437
><P
 
1438
>   The format of the log is:
 
1439
 
 
1440
</P><PRE
 
1441
CLASS="SYNOPSIS"
 
1442
><TT
 
1443
CLASS="REPLACEABLE"
 
1444
><I
 
1445
>client_id</I
 
1446
></TT
 
1447
> <TT
 
1448
CLASS="REPLACEABLE"
 
1449
><I
 
1450
>transaction_no</I
 
1451
></TT
 
1452
> <TT
 
1453
CLASS="REPLACEABLE"
 
1454
><I
 
1455
>time</I
 
1456
></TT
 
1457
> <TT
 
1458
CLASS="REPLACEABLE"
 
1459
><I
 
1460
>file_no</I
 
1461
></TT
 
1462
> <TT
 
1463
CLASS="REPLACEABLE"
 
1464
><I
 
1465
>time_epoch</I
 
1466
></TT
 
1467
> <TT
 
1468
CLASS="REPLACEABLE"
 
1469
><I
 
1470
>time_us</I
 
1471
></TT
 
1472
></PRE
 
1473
><P>
 
1474
 
 
1475
   where <TT
 
1476
CLASS="REPLACEABLE"
 
1477
><I
 
1478
>time</I
 
1479
></TT
 
1480
> is the total elapsed transaction time in microseconds,
 
1481
   <TT
 
1482
CLASS="REPLACEABLE"
 
1483
><I
 
1484
>file_no</I
 
1485
></TT
 
1486
> identifies which script file was used
 
1487
   (useful when multiple scripts were specified with <TT
 
1488
CLASS="LITERAL"
 
1489
>-f</TT
 
1490
>),
 
1491
   and <TT
 
1492
CLASS="REPLACEABLE"
 
1493
><I
 
1494
>time_epoch</I
 
1495
></TT
 
1496
>/<TT
 
1497
CLASS="REPLACEABLE"
 
1498
><I
 
1499
>time_us</I
 
1500
></TT
 
1501
> are a
 
1502
   UNIX epoch format timestamp and an offset
 
1503
   in microseconds (suitable for creating a ISO 8601
 
1504
   timestamp with fractional seconds) showing when
 
1505
   the transaction completed.
 
1506
  </P
 
1507
><P
 
1508
>   Here are example outputs:
 
1509
</P><PRE
 
1510
CLASS="SCREEN"
 
1511
> 0 199 2241 0 1175850568 995598
 
1512
 0 200 2465 0 1175850568 998079
 
1513
 0 201 2513 0 1175850569 608
 
1514
 0 202 2038 0 1175850569 2663</PRE
 
1515
><P>
 
1516
  </P
 
1517
></DIV
 
1518
><DIV
 
1519
CLASS="SECT2"
 
1520
><H2
 
1521
CLASS="SECT2"
 
1522
><A
 
1523
NAME="AEN132479"
 
1524
>F.26.8. Per-Statement Latencies</A
 
1525
></H2
 
1526
><P
 
1527
>   With the <TT
 
1528
CLASS="LITERAL"
 
1529
>-r</TT
 
1530
> option, <SPAN
 
1531
CLASS="APPLICATION"
 
1532
>pgbench</SPAN
 
1533
> collects
 
1534
   the elapsed transaction time of each statement executed by every
 
1535
   client.  It then reports an average of those values, referred to
 
1536
   as the latency for each statement, after the benchmark has finished.
 
1537
  </P
 
1538
><P
 
1539
>   For the default script, the output will look similar to this:
 
1540
</P><PRE
 
1541
CLASS="SCREEN"
 
1542
>starting vacuum...end.
 
1543
transaction type: TPC-B (sort of)
 
1544
scaling factor: 1
 
1545
query mode: simple
 
1546
number of clients: 10
 
1547
number of threads: 1
 
1548
number of transactions per client: 1000
 
1549
number of transactions actually processed: 10000/10000
 
1550
tps = 618.764555 (including connections establishing)
 
1551
tps = 622.977698 (excluding connections establishing)
 
1552
statement latencies in milliseconds:
 
1553
        0.004386        \set nbranches 1 * :scale
 
1554
        0.001343        \set ntellers 10 * :scale
 
1555
        0.001212        \set naccounts 100000 * :scale
 
1556
        0.001310        \setrandom aid 1 :naccounts
 
1557
        0.001073        \setrandom bid 1 :nbranches
 
1558
        0.001005        \setrandom tid 1 :ntellers
 
1559
        0.001078        \setrandom delta -5000 5000
 
1560
        0.326152        BEGIN;
 
1561
        0.603376        UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
 
1562
        0.454643        SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
 
1563
        5.528491        UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
 
1564
        7.335435        UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
 
1565
        0.371851        INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
 
1566
        1.212976        END;</PRE
 
1567
><P>
 
1568
  </P
 
1569
><P
 
1570
>   If multiple script files are specified, the averages are reported
 
1571
   separately for each script file.
 
1572
  </P
 
1573
><P
 
1574
>   Note that collecting the additional timing information needed for
 
1575
   per-statement latency computation adds some overhead.  This will slow
 
1576
   average execution speed and lower the computed TPS.  The amount
 
1577
   of slowdown varies significantly depending on platform and hardware.
 
1578
   Comparing average TPS values with and without latency reporting enabled
 
1579
   is a good way to measure if the timing overhead is significant.
 
1580
  </P
 
1581
></DIV
 
1582
><DIV
 
1583
CLASS="SECT2"
 
1584
><H2
 
1585
CLASS="SECT2"
 
1586
><A
 
1587
NAME="AEN132488"
 
1588
>F.26.9. Good Practices</A
 
1589
></H2
 
1590
><P
 
1591
>   It is very easy to use <SPAN
 
1592
CLASS="APPLICATION"
 
1593
>pgbench</SPAN
 
1594
> to produce completely
 
1595
   meaningless numbers.  Here are some guidelines to help you get useful
 
1596
   results.
 
1597
  </P
 
1598
><P
 
1599
>   In the first place, <SPAN
 
1600
CLASS="emphasis"
 
1601
><I
 
1602
CLASS="EMPHASIS"
 
1603
>never</I
 
1604
></SPAN
 
1605
> believe any test that runs
 
1606
   for only a few seconds.  Use the <TT
 
1607
CLASS="LITERAL"
 
1608
>-t</TT
 
1609
> or <TT
 
1610
CLASS="LITERAL"
 
1611
>-T</TT
 
1612
> option
 
1613
   to make the run last at least a few minutes, so as to average out noise.
 
1614
   In some cases you could need hours to get numbers that are reproducible.
 
1615
   It's a good idea to try the test run a few times, to find out if your
 
1616
   numbers are reproducible or not.
 
1617
  </P
 
1618
><P
 
1619
>   For the default TPC-B-like test scenario, the initialization scale factor
 
1620
   (<TT
 
1621
CLASS="LITERAL"
 
1622
>-s</TT
 
1623
>) should be at least as large as the largest number of
 
1624
   clients you intend to test (<TT
 
1625
CLASS="LITERAL"
 
1626
>-c</TT
 
1627
>); else you'll mostly be
 
1628
   measuring update contention.  There are only <TT
 
1629
CLASS="LITERAL"
 
1630
>-s</TT
 
1631
> rows in
 
1632
   the <TT
 
1633
CLASS="STRUCTNAME"
 
1634
>pgbench_branches</TT
 
1635
> table, and every transaction wants to
 
1636
   update one of them, so <TT
 
1637
CLASS="LITERAL"
 
1638
>-c</TT
 
1639
> values in excess of <TT
 
1640
CLASS="LITERAL"
 
1641
>-s</TT
 
1642
>
 
1643
   will undoubtedly result in lots of transactions blocked waiting for
 
1644
   other transactions.
 
1645
  </P
 
1646
><P
 
1647
>   The default test scenario is also quite sensitive to how long it's been
 
1648
   since the tables were initialized: accumulation of dead rows and dead space
 
1649
   in the tables changes the results.  To understand the results you must keep
 
1650
   track of the total number of updates and when vacuuming happens.  If
 
1651
   autovacuum is enabled it can result in unpredictable changes in measured
 
1652
   performance.
 
1653
  </P
 
1654
><P
 
1655
>   A limitation of <SPAN
 
1656
CLASS="APPLICATION"
 
1657
>pgbench</SPAN
 
1658
> is that it can itself become
 
1659
   the bottleneck when trying to test a large number of client sessions.
 
1660
   This can be alleviated by running <SPAN
 
1661
CLASS="APPLICATION"
 
1662
>pgbench</SPAN
 
1663
> on a different
 
1664
   machine from the database server, although low network latency will be
 
1665
   essential.  It might even be useful to run several <SPAN
 
1666
CLASS="APPLICATION"
 
1667
>pgbench</SPAN
 
1668
>
 
1669
   instances concurrently, on several client machines, against the same
 
1670
   database server.
 
1671
  </P
 
1672
></DIV
 
1673
></DIV
 
1674
><DIV
 
1675
CLASS="NAVFOOTER"
 
1676
><HR
 
1677
ALIGN="LEFT"
 
1678
WIDTH="100%"><TABLE
 
1679
SUMMARY="Footer navigation table"
 
1680
WIDTH="100%"
 
1681
BORDER="0"
 
1682
CELLPADDING="0"
 
1683
CELLSPACING="0"
 
1684
><TR
 
1685
><TD
 
1686
WIDTH="33%"
 
1687
ALIGN="left"
 
1688
VALIGN="top"
 
1689
><A
 
1690
HREF="pgarchivecleanup.html"
 
1691
ACCESSKEY="P"
 
1692
>Prev</A
 
1693
></TD
 
1694
><TD
 
1695
WIDTH="34%"
 
1696
ALIGN="center"
 
1697
VALIGN="top"
 
1698
><A
 
1699
HREF="index.html"
 
1700
ACCESSKEY="H"
 
1701
>Home</A
 
1702
></TD
 
1703
><TD
 
1704
WIDTH="33%"
 
1705
ALIGN="right"
 
1706
VALIGN="top"
 
1707
><A
 
1708
HREF="pgbuffercache.html"
 
1709
ACCESSKEY="N"
 
1710
>Next</A
 
1711
></TD
 
1712
></TR
 
1713
><TR
 
1714
><TD
 
1715
WIDTH="33%"
 
1716
ALIGN="left"
 
1717
VALIGN="top"
 
1718
>pg_archivecleanup</TD
 
1719
><TD
 
1720
WIDTH="34%"
 
1721
ALIGN="center"
 
1722
VALIGN="top"
 
1723
><A
 
1724
HREF="contrib.html"
 
1725
ACCESSKEY="U"
 
1726
>Up</A
 
1727
></TD
 
1728
><TD
 
1729
WIDTH="33%"
 
1730
ALIGN="right"
 
1731
VALIGN="top"
 
1732
>pg_buffercache</TD
 
1733
></TR
 
1734
></TABLE
 
1735
></DIV
 
1736
></BODY
 
1737
></HTML
 
1738
>
 
 
b'\\ No newline at end of file'