Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb231608

Browse files
committed
Add :client_id automatic variable for custom pgbench scripts.
This makes it easier to write custom scripts that have different logic foreach client.Gurjeet Singh, with some changes by me.
1 parent46e1434 commitb231608

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,20 @@ main(int argc, char **argv)
25442544
}
25452545
}
25462546

2547+
/*
2548+
* Define a :client_id variable that is unique per connection. But don't
2549+
* override an explicit -D switch.
2550+
*/
2551+
if (getVariable(&state[0],"client_id")==NULL)
2552+
{
2553+
for (i=0;i<nclients;i++)
2554+
{
2555+
snprintf(val,sizeof(val),"%d",i);
2556+
if (!putVariable(&state[i],"startup","client_id",val))
2557+
exit(1);
2558+
}
2559+
}
2560+
25472561
if (!is_no_vacuum)
25482562
{
25492563
fprintf(stderr,"starting vacuum...");

‎doc/src/sgml/pgbench.sgml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,39 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
600600
Variables can be set by the command-line <option>-D</> option,
601601
explained above, or by the meta commands explained below.
602602
In addition to any variables preset by <option>-D</> command-line options,
603-
the variable <literal>scale</> is preset to the current scale factor.
603+
there are a few variables that are preset automatically, listed in
604+
<xref linkend="pgbench-automatic-variables">. A value specified for these
605+
variables using <option>-D</> takes precedence over the automatic presets.
604606
Once set, a variable's
605607
value can be inserted into a SQL command by writing
606608
<literal>:</><replaceable>variablename</>. When running more than
607609
one client session, each session has its own set of variables.
608610
</para>
609611

612+
<table id="pgbench-automatic-variables">
613+
<title>Automatic variables</title>
614+
<tgroup cols="2">
615+
<thead>
616+
<row>
617+
<entry>Variable</entry>
618+
<entry>Description</entry>
619+
</row>
620+
</thead>
621+
622+
<tbody>
623+
<row>
624+
<entry> <literal>scale</literal> </entry>
625+
<entry>current scale factor</entry>
626+
</row>
627+
628+
<row>
629+
<entry> <literal>client_id</literal> </entry>
630+
<entry>unique number identifying the client session (starts from zero)</entry>
631+
</row>
632+
</tbody>
633+
</tgroup>
634+
</table>
635+
610636
<para>
611637
Script file meta commands begin with a backslash (<literal>\</>).
612638
Arguments to a meta command are separated by white space.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp