Home Explore Blog CI



postgresql

15th chunk of `doc/src/sgml/ref/pgbench.sgml`
a59c11598323b556d485c60950991938070d426d34290a9e0000000100000fa8
 with <option>-b</option>
   and user-provided scripts specified with <option>-f</option>.
   Each script may be given a relative weight specified after an
   <literal>@</literal> so as to change its selection probability.
   The default weight is <literal>1</literal>.
   Scripts with a weight of <literal>0</literal> are ignored.
 </para>

  <para>
   The default built-in transaction script (also invoked with <option>-b tpcb-like</option>)
   issues seven commands per transaction over randomly chosen <literal>aid</literal>,
   <literal>tid</literal>, <literal>bid</literal> and <literal>delta</literal>.
   The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B,
   hence the name.
  </para>

  <orderedlist>
   <listitem><para><literal>BEGIN;</literal></para></listitem>
   <listitem><para><literal>UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</literal></para></listitem>
   <listitem><para><literal>SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</literal></para></listitem>
   <listitem><para><literal>UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</literal></para></listitem>
   <listitem><para><literal>UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</literal></para></listitem>
   <listitem><para><literal>INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</literal></para></listitem>
   <listitem><para><literal>END;</literal></para></listitem>
  </orderedlist>

  <para>
   If you select the <literal>simple-update</literal> built-in (also <option>-N</option>),
   steps 4 and 5 aren't included in the transaction.
   This will avoid update contention on these tables, but
   it makes the test case even less like TPC-B.
  </para>

  <para>
   If you select the <literal>select-only</literal> built-in (also <option>-S</option>),
   only the <command>SELECT</command> is issued.
  </para>
 </refsect2>

 <refsect2>
  <title>Custom Scripts</title>

  <para>
   <application>pgbench</application> has support for running custom
   benchmark scenarios by replacing the default transaction script
   (described above) with a transaction script read from a file
   (<option>-f</option> option).  In this case a <quote>transaction</quote>
   counts as one execution of a script file.
  </para>

  <para>
   A script file contains one or more SQL commands terminated by
   semicolons.  Empty lines and lines beginning with
   <literal>--</literal> are ignored.  Script files can also contain
   <quote>meta commands</quote>, which are interpreted by <application>pgbench</application>
   itself, as described below.
  </para>

  <note>
   <para>
    Before <productname>PostgreSQL</productname> 9.6, SQL commands in script files
    were terminated by newlines, and so they could not be continued across
    lines.  Now a semicolon is <emphasis>required</emphasis> to separate consecutive
    SQL commands (though an SQL command does not need one if it is followed
    by a meta command).  If you need to create a script file that works with
    both old and new versions of <application>pgbench</application>, be sure to write
    each SQL command on a single line ending with a semicolon.
   </para>
   <para>
    It is assumed that <application>pgbench</application> scripts do not contain
    incomplete blocks of SQL
    transactions. If at runtime the client reaches the end of the script without
    completing the last transaction block, it will be aborted.
   </para>
  </note>

  <para>
   There is a simple variable-substitution facility for script files.
   Variable names must consist of letters (including non-Latin letters),
   digits, and underscores, with the first character not being a digit.
   Variables can be set by the command-line <option>-D</option> option,
   explained above, or by the meta commands explained below.
   In addition to any variables preset by <option>-D</option> command-line options,

Title: pgbench: Built-in and Custom Transaction Scripts
Summary
This section elaborates on the transaction scripts used by pgbench, detailing the default TPC-B-like script (including the specific SQL commands) and its simplified variants. It then discusses the use of custom scripts, including the syntax, meta commands, and variable substitution facility available for creating personalized benchmark scenarios. Notably, before PostgreSQL 9.6, SQL commands in script files were terminated by newlines, requiring each SQL command to be written on a single line ending with a semicolon.