Commit 591c504f authored by Tom Lane's avatar Tom Lane

Allow running just selected steps of pgbench's initialization sequence.

This feature caters to specialized use-cases such as running the normal
pgbench scenario with nonstandard indexes, or inserting other actions
between steps of the initialization sequence.  The normal sequence of
initialization actions is broken down into half a dozen steps which can
be executed in a user-specified order, to the extent to which that's
sensible.  The actions themselves aren't changed, except to make them
more robust against nonstandard uses:

* all four tables are now dropped in one DROP command, to reduce
assumptions about what foreign key relationships exist;

* all four tables are now truncated at the start of the data load
step, for consistency;

* the foreign key creation commands now specify constraint names, to
prevent accidentally creating duplicate constraints by executing the
'f' step twice.

Make some cosmetic adjustments in the messages emitted by pgbench
so that it's clear which steps are getting run, and so that the
messages agree with the documented names of the steps.

In passing, fix failure to enforce that the -v option is used only
in benchmarking mode.

Masahiko Sawada, reviewed by Fabien Coelho, editorialized a bit by me

Discussion: https://postgr.es/m/CAD21AoCsz0ZzfCFcxYZ+PUdpkDd5VsCSG0Pre_-K1EgokCDFYA@mail.gmail.com
parent 44ae64c3
......@@ -134,9 +134,9 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
<title>Options</title>
<para>
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.
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">
......@@ -158,6 +158,79 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
</listitem>
</varlistentry>
<varlistentry>
<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 set of the normal initialization steps.
<replaceable>init_steps</replaceable> specifies the
initialization steps to be performed, using one character per step.
Each step is invoked in the specified order.
The default is <literal>dtgvp</literal>.
The available steps are:
<variablelist>
<varlistentry>
<term><literal>d</literal> (Drop)</term>
<listitem>
<para>
Drop any existing <application>pgbench</application> tables.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>t</literal> (create Tables)</term>
<listitem>
<para>
Create the tables used by the
standard <application>pgbench</application> scenario, namely
<structname>pgbench_accounts</structname>,
<structname>pgbench_branches</structname>,
<structname>pgbench_history</structname>, and
<structname>pgbench_tellers</structname>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>g</literal> (Generate data)</term>
<listitem>
<para>
Generate data and load it into the standard tables,
replacing any data already present.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>v</literal> (Vacuum)</term>
<listitem>
<para>
Invoke <command>VACUUM</command> on the standard tables.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>p</literal> (create Primary keys)</term>
<listitem>
<para>
Create primary key indexes on the standard tables.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>f</literal> (create Foreign keys)</term>
<listitem>
<para>
Create foreign key constraints between the standard tables.
(Note that this step is not performed by default.)
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-F</option> <replaceable>fillfactor</replaceable></term>
<term><option>--fillfactor=</option><replaceable>fillfactor</replaceable></term>
......@@ -176,7 +249,9 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
<term><option>--no-vacuum</option></term>
<listitem>
<para>
Perform no vacuuming after initialization.
Perform no vacuuming during initialization.
(This option suppresses the <literal>v</literal> initialization step,
even if it was specified in <option>-I</option>.)
</para>
</listitem>
</varlistentry>
......@@ -215,6 +290,8 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
<listitem>
<para>
Create foreign key constraints between the standard tables.
(This option adds the <literal>f</literal> step to the initialization
step sequence, if it is not already present.)
</para>
</listitem>
</varlistentry>
......
This diff is collapsed.
......@@ -76,21 +76,34 @@ pgbench(
# Initialize pgbench tables scale 1
pgbench(
'-i', 0, [qr{^$}],
[ qr{creating tables}, qr{vacuum}, qr{set primary keys}, qr{done\.} ],
[ qr{creating tables}, qr{vacuuming}, qr{creating primary keys}, qr{done\.} ],
'pgbench scale 1 initialization',);
# Again, with all possible options
pgbench(
'--initialize --scale=1 --unlogged-tables --fillfactor=98 --foreign-keys --quiet --tablespace=pg_default --index-tablespace=pg_default',
'--initialize --init-steps=dtpvg --scale=1 --unlogged-tables --fillfactor=98 --foreign-keys --quiet --tablespace=pg_default --index-tablespace=pg_default',
0,
[qr{^$}i],
[ qr{creating tables},
qr{vacuum},
qr{set primary keys},
qr{set foreign keys},
[ qr{dropping old tables},
qr{creating tables},
qr{vacuuming},
qr{creating primary keys},
qr{creating foreign keys},
qr{done\.} ],
'pgbench scale 1 initialization');
# Test interaction of --init-steps with legacy step-selection options
pgbench(
'--initialize --init-steps=dtpvgvv --no-vacuum --foreign-keys --unlogged-tables',
0, [qr{^$}],
[ qr{dropping old tables},
qr{creating tables},
qr{creating primary keys},
qr{.* of .* tuples \(.*\) done},
qr{creating foreign keys},
qr{done\.} ],
'pgbench --init-steps');
# Run all builtin scripts, for a few transactions each
pgbench(
'--transactions=5 -Dfoo=bla --client=2 --protocol=simple --builtin=t'
......
......@@ -73,6 +73,11 @@ my @options = (
[ 'ambiguous builtin', '-b s', [qr{ambiguous}] ],
[ '--progress-timestamp => --progress', '--progress-timestamp',
[qr{allowed only under}] ],
[ '-I without init option', '-I dtg',
[qr{cannot be used in benchmarking mode}] ],
[ 'invalid init step', '-i -I dta',
[qr{unrecognized initialization step},
qr{allowed steps are} ] ],
# loging sub-options
[ 'sampling => log', '--sampling-rate=0.01',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment