Skip to content

Commit 2d6fee0

Browse files
committed
Add new pgbench switch, --unlogged-tables.
This entails adjusting pgbench to use getopt_long() rather than getopt().
1 parent bcf23ba commit 2d6fee0

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

contrib/pgbench/pgbench.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "postgres_fe.h"
3535

36+
#include "getopt_long.h"
3637
#include "libpq-fe.h"
3738
#include "libpq/pqsignal.h"
3839
#include "portability/instr_time.h"
@@ -44,10 +45,6 @@
4445
#include <unistd.h>
4546
#endif /* ! WIN32 */
4647

47-
#ifdef HAVE_GETOPT_H
48-
#include <getopt.h>
49-
#endif
50-
5148
#ifdef HAVE_SYS_SELECT_H
5249
#include <sys/select.h>
5350
#endif
@@ -122,6 +119,11 @@ int scale = 1;
122119
*/
123120
int fillfactor = 100;
124121

122+
/*
123+
* use unlogged tables?
124+
*/
125+
int unlogged_tables = 0;
126+
125127
/*
126128
* end of configurable parameters
127129
*********************************************************************/
@@ -357,6 +359,8 @@ usage(const char *progname)
357359
" -h HOSTNAME database server host or socket directory\n"
358360
" -p PORT database server port number\n"
359361
" -U USERNAME connect as specified database user\n"
362+
" --unlogged-tables\n"
363+
" create tables as unlogged tables\n"
360364
" --help show this help, then exit\n"
361365
" --version output version information, then exit\n"
362366
"\n"
@@ -1259,21 +1263,31 @@ init(void)
12591263

12601264
for (i = 0; i < lengthof(DDLs); i++)
12611265
{
1266+
char buffer1[128];
1267+
char buffer2[128];
1268+
char *qry = DDLs[i];
1269+
12621270
/*
12631271
* set fillfactor for branches, tellers and accounts tables
12641272
*/
1265-
if ((strstr(DDLs[i], "create table pgbench_branches") == DDLs[i]) ||
1266-
(strstr(DDLs[i], "create table pgbench_tellers") == DDLs[i]) ||
1267-
(strstr(DDLs[i], "create table pgbench_accounts") == DDLs[i]))
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]))
12681276
{
1269-
char ddl_stmt[128];
1277+
snprintf(buffer1, 128, qry, fillfactor);
1278+
qry = buffer1;
1279+
}
12701280

1271-
snprintf(ddl_stmt, 128, DDLs[i], fillfactor);
1272-
executeStatement(con, ddl_stmt);
1273-
continue;
1281+
/*
1282+
* set unlogged tables, if requested
1283+
*/
1284+
if (unlogged_tables && strncmp(qry, "create table", 12) == 0)
1285+
{
1286+
snprintf(buffer2, 128, "create unlogged%s", qry + 6);
1287+
qry = buffer2;
12741288
}
1275-
else
1276-
executeStatement(con, DDLs[i]);
1289+
1290+
executeStatement(con, qry);
12771291
}
12781292

12791293
executeStatement(con, "begin");
@@ -1767,6 +1781,7 @@ main(int argc, char **argv)
17671781
int do_vacuum_accounts = 0; /* do vacuum accounts before testing? */
17681782
int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only,
17691783
* 2: skip update of branches and tellers */
1784+
int optindex;
17701785
char *filename = NULL;
17711786
bool scale_given = false;
17721787

@@ -1780,6 +1795,11 @@ main(int argc, char **argv)
17801795

17811796
int i;
17821797

1798+
static struct option long_options[] = {
1799+
{"unlogged-tables", no_argument, &unlogged_tables, 1},
1800+
{NULL, 0, NULL, 0}
1801+
};
1802+
17831803
#ifdef HAVE_GETRLIMIT
17841804
struct rlimit rlim;
17851805
#endif
@@ -1823,7 +1843,7 @@ main(int argc, char **argv)
18231843
state = (CState *) xmalloc(sizeof(CState));
18241844
memset(state, 0, sizeof(CState));
18251845

1826-
while ((c = getopt(argc, argv, "ih:nvp:dSNc:j:Crs:t:T:U:lf:D:F:M:")) != -1)
1846+
while ((c = getopt_long(argc, argv, "ih:nvp:dSNc:j:Crs:t:T:U:lf:D:F:M:", long_options, &optindex)) != -1)
18271847
{
18281848
switch (c)
18291849
{
@@ -1975,6 +1995,9 @@ main(int argc, char **argv)
19751995
exit(1);
19761996
}
19771997
break;
1998+
case 0:
1999+
/* This covers the long options. */
2000+
break;
19782001
default:
19792002
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
19802003
exit(1);

doc/src/sgml/pgbench.sgml

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

162+
<varlistentry>
163+
<term><option>--unlogged-tables</option></term>
164+
<listitem>
165+
<para>
166+
Create all tables as unlogged tables, rather than permanent tables.
167+
</para>
168+
</listitem>
169+
</varlistentry>
170+
162171
</variablelist>
163172
</para>
164173

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy