random(-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;
</programlisting>
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 —
otherwise they'd not be independently touching different rows.)
</para>
</refsect2>
<refsect2>
<title>Per-Transaction Logging</title>
<para>
With the <option>-l</option> option (but without
the <option>--aggregate-interval</option> option),
<application>pgbench</application> writes information about each transaction
to a log file. The log file will be named
<filename><replaceable>prefix</replaceable>.<replaceable>nnn</replaceable></filename>,
where <replaceable>prefix</replaceable> defaults to <literal>pgbench_log</literal>, and
<replaceable>nnn</replaceable> is the PID of the
<application>pgbench</application> process.
The prefix can be changed by using the <option>--log-prefix</option> option.
If the <option>-j</option> option is 2 or higher, so that there are 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
<filename><replaceable>prefix</replaceable>.<replaceable>nnn</replaceable>.<replaceable>mmm</replaceable></filename>,
where <replaceable>mmm</replaceable> is a sequential number for each worker starting
with 1.
</para>
<para>
Each line in a log file describes one transaction.
It contains the following space-separated fields:
<variablelist>
<varlistentry>
<term><replaceable>client_id</replaceable></term>
<listitem>
<para>
identifies the client session that ran the transaction
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>transaction_no</replaceable></term>
<listitem>
<para>
counts how many transactions have been run by that session
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>time</replaceable></term>
<listitem>
<para>
transaction's elapsed time, in microseconds
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>script_no</replaceable></term>
<listitem>
<para>
identifies the script file that was used for the transaction
(useful when multiple scripts are specified
with <option>-f</option> or <option>-b</option>)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>time_epoch</replaceable></term>
<listitem>
<para>
transaction's completion time, as a Unix-epoch time stamp
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>time_us</replaceable></term>
<listitem>
<para>
fractional-second part of transaction's completion time, in
microseconds
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>schedule_lag</replaceable></term>
<listitem>
<para>
transaction start delay, that is the difference between the
transaction's scheduled start time and the time it actually
started, in microseconds
(present only if <option>--rate</option> is specified)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>retries</replaceable></term>
<listitem>
<para>
count of