33
33
34
34
#include "postgres_fe.h"
35
35
36
+ #include "getopt_long.h"
36
37
#include "libpq-fe.h"
37
38
#include "libpq/pqsignal.h"
38
39
#include "portability/instr_time.h"
44
45
#include <unistd.h>
45
46
#endif /* ! WIN32 */
46
47
47
- #ifdef HAVE_GETOPT_H
48
- #include <getopt.h>
49
- #endif
50
-
51
48
#ifdef HAVE_SYS_SELECT_H
52
49
#include <sys/select.h>
53
50
#endif
@@ -122,6 +119,11 @@ int scale = 1;
122
119
*/
123
120
int fillfactor = 100 ;
124
121
122
+ /*
123
+ * use unlogged tables?
124
+ */
125
+ int unlogged_tables = 0 ;
126
+
125
127
/*
126
128
* end of configurable parameters
127
129
*********************************************************************/
@@ -357,6 +359,8 @@ usage(const char *progname)
357
359
" -h HOSTNAME database server host or socket directory\n"
358
360
" -p PORT database server port number\n"
359
361
" -U USERNAME connect as specified database user\n"
362
+ " --unlogged-tables\n"
363
+ " create tables as unlogged tables\n"
360
364
" --help show this help, then exit\n"
361
365
" --version output version information, then exit\n"
362
366
"\n"
@@ -1259,21 +1263,31 @@ init(void)
1259
1263
1260
1264
for (i = 0 ; i < lengthof (DDLs ); i ++ )
1261
1265
{
1266
+ char buffer1 [128 ];
1267
+ char buffer2 [128 ];
1268
+ char * qry = DDLs [i ];
1269
+
1262
1270
/*
1263
1271
* set fillfactor for branches, tellers and accounts tables
1264
1272
*/
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 ]))
1268
1276
{
1269
- char ddl_stmt [128 ];
1277
+ snprintf (buffer1 , 128 , qry , fillfactor );
1278
+ qry = buffer1 ;
1279
+ }
1270
1280
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 ;
1274
1288
}
1275
- else
1276
- executeStatement (con , DDLs [ i ] );
1289
+
1290
+ executeStatement (con , qry );
1277
1291
}
1278
1292
1279
1293
executeStatement (con , "begin" );
@@ -1767,6 +1781,7 @@ main(int argc, char **argv)
1767
1781
int do_vacuum_accounts = 0 ; /* do vacuum accounts before testing? */
1768
1782
int ttype = 0 ; /* transaction type. 0: TPC-B, 1: SELECT only,
1769
1783
* 2: skip update of branches and tellers */
1784
+ int optindex ;
1770
1785
char * filename = NULL ;
1771
1786
bool scale_given = false;
1772
1787
@@ -1780,6 +1795,11 @@ main(int argc, char **argv)
1780
1795
1781
1796
int i ;
1782
1797
1798
+ static struct option long_options [] = {
1799
+ {"unlogged-tables" , no_argument , & unlogged_tables , 1 },
1800
+ {NULL , 0 , NULL , 0 }
1801
+ };
1802
+
1783
1803
#ifdef HAVE_GETRLIMIT
1784
1804
struct rlimit rlim ;
1785
1805
#endif
@@ -1823,7 +1843,7 @@ main(int argc, char **argv)
1823
1843
state = (CState * ) xmalloc (sizeof (CState ));
1824
1844
memset (state , 0 , sizeof (CState ));
1825
1845
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 )
1827
1847
{
1828
1848
switch (c )
1829
1849
{
@@ -1975,6 +1995,9 @@ main(int argc, char **argv)
1975
1995
exit (1 );
1976
1996
}
1977
1997
break ;
1998
+ case 0 :
1999
+ /* This covers the long options. */
2000
+ break ;
1978
2001
default :
1979
2002
fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
1980
2003
exit (1 );
0 commit comments