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"
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 @@ intscale = 1;
122119 */
123120int 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
12601264for (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
12791293executeStatement (con ,"begin" );
@@ -1767,6 +1781,7 @@ main(int argc, char **argv)
17671781int do_vacuum_accounts = 0 ;/* do vacuum accounts before testing? */
17681782int ttype = 0 ;/* transaction type. 0: TPC-B, 1: SELECT only,
17691783 * 2: skip update of branches and tellers */
1784+ int optindex ;
17701785char * filename = NULL ;
17711786bool scale_given = false;
17721787
@@ -1780,6 +1795,11 @@ main(int argc, char **argv)
17801795
17811796int 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
17841804struct rlimit rlim ;
17851805#endif
@@ -1823,7 +1843,7 @@ main(int argc, char **argv)
18231843state = (CState * )xmalloc (sizeof (CState ));
18241844memset (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{
18281848switch (c )
18291849{
@@ -1975,6 +1995,9 @@ main(int argc, char **argv)
19751995exit (1 );
19761996}
19771997break ;
1998+ case 0 :
1999+ /* This covers the long options. */
2000+ break ;
19782001default :
19792002fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),progname );
19802003exit (1 );