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

Commit7c26395

Browse files
committed
Add new pgbench options, --tablespace and --index-tablespace.
Per a request from Greg Smith.
1 parent2d6fee0 commit7c26395

File tree

2 files changed

+104
-31
lines changed

2 files changed

+104
-31
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 84 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ intfillfactor = 100;
124124
*/
125125
intunlogged_tables=0;
126126

127+
/*
128+
* tablespace selection
129+
*/
130+
char*tablespace=NULL;
131+
char*index_tablespace=NULL;
132+
127133
/*
128134
* end of configurable parameters
129135
*********************************************************************/
@@ -359,6 +365,10 @@ usage(const char *progname)
359365
" -h HOSTNAME database server host or socket directory\n"
360366
" -p PORT database server port number\n"
361367
" -U USERNAME connect as specified database user\n"
368+
" --index-tablespace=TABLESPACE\n"
369+
" create indexes in the specified tablespace\n"
370+
" --tablespace=TABLESPACE\n"
371+
" create tables in the specified tablespace\n"
362372
" --unlogged-tables\n"
363373
" create tables as unlogged tables\n"
364374
" --help show this help, then exit\n"
@@ -1237,15 +1247,32 @@ init(void)
12371247
* versions. Since pgbench has never pretended to be fully TPC-B
12381248
* compliant anyway, we stick with the historical behavior.
12391249
*/
1240-
staticchar*DDLs[]= {
1241-
"drop table if exists pgbench_branches",
1242-
"create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=%d)",
1243-
"drop table if exists pgbench_tellers",
1244-
"create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=%d)",
1245-
"drop table if exists pgbench_accounts",
1246-
"create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=%d)",
1247-
"drop table if exists pgbench_history",
1248-
"create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"
1250+
structddlinfo {
1251+
char*table;
1252+
char*cols;
1253+
intdeclare_fillfactor;
1254+
};
1255+
structddlinfoDDLs[]= {
1256+
{
1257+
"pgbench_branches",
1258+
"bid int not null,bbalance int,filler char(88)",
1259+
1
1260+
},
1261+
{
1262+
"pgbench_tellers",
1263+
"tid int not null,bid int,tbalance int,filler char(84)",
1264+
1
1265+
},
1266+
{
1267+
"pgbench_accounts",
1268+
"aid int not null,bid int,abalance int,filler char(84)",
1269+
1
1270+
},
1271+
{
1272+
"pgbench_history",
1273+
"tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
1274+
0
1275+
}
12491276
};
12501277
staticchar*DDLAFTERs[]= {
12511278
"alter table pgbench_branches add primary key (bid)",
@@ -1263,31 +1290,33 @@ init(void)
12631290

12641291
for (i=0;i<lengthof(DDLs);i++)
12651292
{
1266-
charbuffer1[128];
1267-
charbuffer2[128];
1268-
char*qry=DDLs[i];
1293+
charopts[256];
1294+
charbuffer[256];
1295+
structddlinfo*ddl=&DDLs[i];
12691296

1270-
/*
1271-
* set fillfactor for branches, tellers and accounts tables
1272-
*/
1273-
if ((strstr(qry,"create table pgbench_branches")==DDLs[i])||
1274-
(strstr(qry,"create table pgbench_tellers")==DDLs[i])||
1275-
(strstr(qry,"create table pgbench_accounts")==DDLs[i]))
1276-
{
1277-
snprintf(buffer1,128,qry,fillfactor);
1278-
qry=buffer1;
1279-
}
1297+
/* Remove old table, if it exists. */
1298+
snprintf(buffer,256,"drop table if exists %s",ddl->table);
1299+
executeStatement(con,buffer);
12801300

1281-
/*
1282-
* set unlogged tables, if requested
1283-
*/
1284-
if (unlogged_tables&&strncmp(qry,"create table",12)==0)
1301+
/* Construct new create table statement. */
1302+
opts[0]='\0';
1303+
if (ddl->declare_fillfactor)
1304+
snprintf(opts+strlen(opts),256-strlen(opts),
1305+
" with (fillfactor=%d)",fillfactor);
1306+
if (tablespace!=NULL)
12851307
{
1286-
snprintf(buffer2,128,"create unlogged%s",qry+6);
1287-
qry=buffer2;
1308+
char*escape_tablespace;
1309+
escape_tablespace=PQescapeIdentifier(con,tablespace,
1310+
strlen(tablespace));
1311+
snprintf(opts+strlen(opts),256-strlen(opts),
1312+
" tablespace %s",escape_tablespace);
1313+
PQfreemem(escape_tablespace);
12881314
}
1315+
snprintf(buffer,256,"create%s table %s(%s)%s",
1316+
unlogged_tables ?" unlogged" :"",
1317+
ddl->table,ddl->cols,opts);
12891318

1290-
executeStatement(con,qry);
1319+
executeStatement(con,buffer);
12911320
}
12921321

12931322
executeStatement(con,"begin");
@@ -1354,7 +1383,23 @@ init(void)
13541383
*/
13551384
fprintf(stderr,"set primary key...\n");
13561385
for (i=0;i<lengthof(DDLAFTERs);i++)
1357-
executeStatement(con,DDLAFTERs[i]);
1386+
{
1387+
charbuffer[256];
1388+
1389+
strncpy(buffer,DDLAFTERs[i],256);
1390+
1391+
if (index_tablespace!=NULL)
1392+
{
1393+
char*escape_tablespace;
1394+
escape_tablespace=PQescapeIdentifier(con,index_tablespace,
1395+
strlen(index_tablespace));
1396+
snprintf(buffer+strlen(buffer),256-strlen(buffer),
1397+
" using index tablespace %s",escape_tablespace);
1398+
PQfreemem(escape_tablespace);
1399+
}
1400+
1401+
executeStatement(con,buffer);
1402+
}
13581403

13591404
/* vacuum */
13601405
fprintf(stderr,"vacuum...");
@@ -1796,6 +1841,8 @@ main(int argc, char **argv)
17961841
inti;
17971842

17981843
staticstructoptionlong_options[]= {
1844+
{"index-tablespace",required_argument,NULL,3},
1845+
{"tablespace",required_argument,NULL,2},
17991846
{"unlogged-tables",no_argument,&unlogged_tables,1},
18001847
{NULL,0,NULL,0}
18011848
};
@@ -1996,7 +2043,13 @@ main(int argc, char **argv)
19962043
}
19972044
break;
19982045
case0:
1999-
/* This covers the long options. */
2046+
/* This covers long options which take no argument. */
2047+
break;
2048+
case2:/* tablespace */
2049+
tablespace=optarg;
2050+
break;
2051+
case3:/* index-tablespace */
2052+
index_tablespace=optarg;
20002053
break;
20012054
default:
20022055
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);

‎doc/src/sgml/pgbench.sgml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
159159
</listitem>
160160
</varlistentry>
161161

162+
<varlistentry>
163+
<term><option>--index-tablespace=<replaceable>index_tablespace</replaceable></option></term>
164+
<listitem>
165+
<para>
166+
Create indexes in the specified tablespace, rather than the default
167+
tablespace.
168+
</para>
169+
</listitem>
170+
</varlistentry>
171+
172+
<varlistentry>
173+
<term><option>--tablespace=<replaceable>tablespace</replaceable></option></term>
174+
<listitem>
175+
<para>
176+
Create tables in the specified tablespace, rather than the default
177+
tablespace.
178+
</para>
179+
</listitem>
180+
</varlistentry>
181+
162182
<varlistentry>
163183
<term><option>--unlogged-tables</option></term>
164184
<listitem>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp