Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/pgbench.sgml`
3c90a1b3779a946d12b985c1620341329ba60cb0c10fd9d80000000100000fa0
 TPC-B-like transaction test requires specific tables to be
   set up beforehand.  <application>pgbench</application> should be invoked with
   the <option>-i</option> (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:

<programlisting>
pgbench -i <optional> <replaceable>other-options</replaceable> </optional> <replaceable>dbname</replaceable>
</programlisting>

   where <replaceable>dbname</replaceable> is the name of the already-created
   database to test in.  (You may also need <option>-h</option>,
   <option>-p</option>, and/or <option>-U</option> options to specify how to
   connect to the database server.)
  </para>

  <caution>
   <para>
    <literal>pgbench -i</literal> creates four tables <structname>pgbench_accounts</structname>,
    <structname>pgbench_branches</structname>, <structname>pgbench_history</structname>, and
    <structname>pgbench_tellers</structname>,
    destroying any existing tables of these names.
    Be very careful to use another database if you have tables having these
    names!
   </para>
  </caution>

  <para>
   At the default <quote>scale factor</quote> of 1, the tables initially
   contain this many rows:
<screen>
table                   # of rows
---------------------------------
pgbench_branches        1
pgbench_tellers         10
pgbench_accounts        100000
pgbench_history         0
</screen>
   You can (and, for most purposes, probably should) increase the number
   of rows by using the <option>-s</option> (scale factor) option.  The
   <option>-F</option> (fillfactor) option might also be used at this point.
  </para>

  <para>
   Once you have done the necessary setup, you can run your benchmark
   with a command that doesn't include <option>-i</option>, that is

<programlisting>
pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>dbname</replaceable>
</programlisting>

   In nearly all cases, you'll need some options to make a useful test.
   The most important options are <option>-c</option> (number of clients),
   <option>-t</option> (number of transactions), <option>-T</option> (time limit),
   and <option>-f</option> (specify a custom script file).
   See below for a full list.
  </para>
 </refsect1>

 <refsect1>
  <title>Options</title>

  <para>
   The following is divided into three subsections.  Different options are
   used during database initialization and while running benchmarks, but some
   options are useful in both cases.
  </para>

 <refsect2 id="pgbench-init-options">
  <title>Initialization Options</title>

   <para>
    <application>pgbench</application> accepts the following command-line
    initialization arguments:

    <variablelist>

     <varlistentry id="pgbench-option-dbname">
      <term><option><optional>-d</optional> <replaceable class="parameter">dbname</replaceable></option></term>
      <term><option><optional>--dbname=</optional><replaceable class="parameter">dbname</replaceable></option></term>
      <listitem>
       <para>
        Specifies the name of the database to test in. If this is
        not specified, the environment variable
        <envar>PGDATABASE</envar> is used. If that is not set, the
        user name specified for the connection is used.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry id="pgbench-option-initialize">
      <term><option>-i</option></term>
      <term><option>--initialize</option></term>
      <listitem>
       <para>
        Required to invoke initialization mode.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry id="pgbench-option-init-steps">
      <term><option>-I <replaceable>init_steps</replaceable></option></term>
      <term><option>--init-steps=<replaceable>init_steps</replaceable></option></term>
      <listitem>
       <para>
        Perform just a selected

Title: pgbench Initialization and Usage
Summary
The pgbench -i command initializes the necessary tables for the TPC-B-like benchmark. It creates pgbench_accounts, pgbench_branches, pgbench_history, and pgbench_tellers, destroying any existing tables with those names. The scale factor (-s) option increases the number of rows in the tables. After initialization, benchmarks can be run without the -i option. The -c, -t, -T, and -f options are important for configuring the benchmark.