From ba708ea3dc84e35900a43015236f90b1a67d3ca3 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sun, 9 Sep 2001 03:15:56 +0000 Subject: [PATCH] Add -U, -P, -C options. See README.pgbench for more details. --- contrib/pgbench/README.pgbench | 19 +++- contrib/pgbench/README.pgbench_jis | 138 +++++++++++++++------------ contrib/pgbench/pgbench.c | 148 +++++++++++++++++++++++------ 3 files changed, 211 insertions(+), 94 deletions(-) diff --git a/contrib/pgbench/README.pgbench b/contrib/pgbench/README.pgbench index d062b01e816..de51b2c7bc2 100644 --- a/contrib/pgbench/README.pgbench +++ b/contrib/pgbench/README.pgbench @@ -1,4 +1,4 @@ -pgbench 1.2 README 2000/1/15 Tatsuo Ishii (t-ishii@sra.co.jp) +pgbench 1.3 README 2001/09/09 Tatsuo Ishii (t-ishii@sra.co.jp) o What is pgbench? @@ -101,6 +101,15 @@ o options (10,000,000) tuples in the accounts table. default is 1. + -U login + Specify db user's login name if it is different from + the Unix login name. + + -P password + Specify the db password. CAUTION: using this option + might be a security hole since ps command will + show the password. Use this for TESTING PURPOSE ONLY. + -n No vacuuming and cleaning the history table prior the test is performed. @@ -113,6 +122,11 @@ o options -S Perform select only transactions instead of TPC-B. + -C + Establish connection for each transaction, rather than + doing it just once at begining of pgbench in the normal + mode. This is usefull to measure the connection overhead. + -d debug option. @@ -139,6 +153,9 @@ Basically it is same as BSD license. See pgbench.c for more details. o History +2001/09/09 + * Add -U, -P, -C options + 2000/1/15 pgbench-1.2 contributed to PostgreSQL * Add -v option diff --git a/contrib/pgbench/README.pgbench_jis b/contrib/pgbench/README.pgbench_jis index 03d466b581a..04a5900c65c 100644 --- a/contrib/pgbench/README.pgbench_jis +++ b/contrib/pgbench/README.pgbench_jis @@ -1,16 +1,16 @@ -pgbench 1.2 README 2000/1/15 Tatsuo Ishii (t-ishii@sra.co.jp) +pgbench 1.3 README 2001/09/09 Tatsuo Ishii (t-ishii@sra.co.jp) $B"#(Bpgbench $B$H$O!)(B -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U%!%/%?!<(B]$B$K$J$j$^$9!%(B + $B%G%U%)%k%H$N%9%1!<%j%s%0%U%!%/%?!<$O(B 1 $B$G$9!%(B --v $B$3$N%*%W%7%g%s$r;XDj$9$k$H!"%Y%s%A%^!<%/3+;OA0$K(B vacuum $B$H(B - history $B$N%/%j%"$r9T$J$$$^$9!#(B-v $B$H(B -n $B$r>JN,$9$k$H!"(B - $B:G>.8B$N(B vacuum $B$J$I$r9T$$$^$9!#$9$J$o$A!"(Bhistory $B$N:o=|!"(B - $B$H(B history, branches, history $B$N(B vacuum $B$r9T$$$^$9!#(B - $B$3$l$O!"(Bvacuum $B$N;~4V$r:G>.8B$K$7$J$,$i!"%Q%U%)!<%^%s%9$K(B - $B1F6A$9$k%4%_A]=|$r8z2LE*$K9T$$$^$9!#DL>o$O(B -v $B$H(B -n $B$r(B - $B>JN,$9$k$3$H$r$*$9$9$a$7$^$9!#(B +-U login DB$B%f!<%6$N%m%0%$%sL>$r;XDj$7$^$9!%(B --n $B$3$N%*%W%7%g%s$r;XDj$9$k$H!"%Y%s%A%^!<%/3+;OA0$K(B vacuum $B$H(B - history $B$N%/%j%"$r9T$J$$$^$;$s!#(B +-P password $B%Q%9%o!<%I$r;XDj$7$^$9!%$J$*!$$3$N%*%W%7%g%s$r;H$&$H!$(B + $B%Q%9%o!<%I$r(Bps$B%3%^%s%I$G8+$i$l$k$J$I!$%;%-%e%j%F%#%[!<(B + $B%k$K$J$k2DG=@-$,$"$k$N$G!$%F%9%HMQ$K$N$_$*;H$$2<$5$$!%(B --S TPC-B$B$N%H%i%s%6%/%7%g%s$G$O$J$/!"8!:w$N$_$N%H%i%s%6%/%7%g%s$r(B - $BpJs$,I=<($5$l$^$9!#(B +-v $B$3$N%*%W%7%g%s$r;XDj$9$k$H!$%Y%s%A%^!<%/3+;OA0$K(B vacuum $B$H(B + history $B$N%/%j%"$r9T$J$$$^$9!%(B-v $B$H(B -n $B$r>JN,$9$k$H!$(B + $B:G>.8B$N(B vacuum $B$J$I$r9T$$$^$9!%$9$J$o$A!$(Bhistory $B$N:o=|!$(B + $B$H(B history, branches, history $B$N(B vacuum $B$r9T$$$^$9!%(B + $B$3$l$O!$(Bvacuum $B$N;~4V$r:G>.8B$K$7$J$,$i!$%Q%U%)!<%^%s%9$K(B + $B1F6A$9$k%4%_A]=|$r8z2LE*$K9T$$$^$9!%DL>o$O(B -v $B$H(B -n $B$r(B + $B>JN,$9$k$3$H$r$*$9$9$a$7$^$9!%(B + +-S TPC-B$B$N%H%i%s%6%/%7%g%s$G$O$J$/!$8!:w$N$_$N%H%i%s%6%/%7%g%s$r(B + $BpJs$,I=<($5$l$^$9!%(B $B"#%G!<%?%Y!<%9$N=i4|2=(B -pgbench $B$G%Y%s%A%^!<%/%F%9%H$r(B] -$B$3$l$K$h$j0J2<$N%F!<%V%k$,:n$i$l$^$9(B($B%9%1!<%j%s%0%U%!%/%?!<(B == 1 $B$N>l9g(B)$B!#(B +$B$3$l$K$h$j0J2<$N%F!<%V%k$,:n$i$l$^$9(B($B%9%1!<%j%s%0%U%!%/%?!<(B == 1 $B$N>l9g(B)$B!%(B $B!vCm0U!v(B $BF1$8L>A0$N%F!<%V%k$,$"$k$H:o=|$5$l$F$7$^$&$N$G$4Cm0U2<$5$$!*!*(B @@ -112,9 +123,9 @@ tellers 10 accounts 100000 history 0 -$B%9%1!<%j%s%0%U%!%/%?!<$r(B 10,100,1000 $B$J$I$KJQ99$9$k$H!">e5-%?%W%k?t$O(B -$B$=$l$K1~$8$F(B10$BG\!"(B100$BG\!"(B1000$BG\$K$J$j$^$9!#$?$H$($P!"%9%1!<%j%s%0%U%!(B -$B%/%?!<$r(B 10 $B$H$9$k$H!"(B +$B%9%1!<%j%s%0%U%!%/%?!<$r(B 10,100,1000 $B$J$I$KJQ99$9$k$H!$>e5-%?%W%k?t$O(B +$B$=$l$K1~$8$F(B10$BG\!$(B100$BG\!$(B1000$BG\$K$J$j$^$9!%$?$H$($P!$%9%1!<%j%s%0%U%!(B +$B%/%?!<$r(B 10 $B$H$9$k$H!$(B $B%F!<%V%kL>(B $B%?%W%k?t(B ------------------------- @@ -123,28 +134,28 @@ tellers 100 accounts 1000000 history 0 -$B$K$J$j$^$9!#(B +$B$K$J$j$^$9!%(B $B"#!V%H%i%s%6%/%7%g%s!W$NDj5A(B -pgbench $B$G$O!"0J2<$N%7!<%1%s%9$rA4It40N;$7$F(B1$B%H%i%s%6%/%7%g%s$H?t$($F(B -$B$$$^$9!#(B +pgbench $B$G$O!$0J2<$N%7!<%1%s%9$rA4It40N;$7$F(B1$B%H%i%s%6%/%7%g%s$H?t$($F(B +$B$$$^$9!%(B (1) begin; (2) update accounts set abalance = abalance + :delta where aid = :aid; - $B$3$3$G!"(B:delta$B$O(B1$B$+$i(B1000$B$^$G$NCM$r$l$3$N%H%i%s%6%/%7%g%s$N(B - $BCf$G$OF1$8CM$r;H$$$^$9!#(B + $B$3$3$G!$(B:delta$B$O(B1$B$+$i(B1000$B$^$G$NCM$r$l$3$N%H%i%s%6%/%7%g%s$N(B + $BCf$G$OF1$8CM$r;H$$$^$9!%(B (3) select abalance from accounts where aid = :aid; - $B$3$3$G$O(B1$B7o$@$18!:w$5$l$^$9!#(B + $B$3$3$G$O(B1$B7o$@$18!:w$5$l$^$9!%(B (4) update tellers set tbalance = tbalance + :delta where tid = :tid; - $B$3$3$G(B :tid $B$O(B 1$B$+$i(B10$B$N4V$NCM$r$H$kMp?t$G$9!#(B + $B$3$3$G(B :tid $B$O(B 1$B$+$i(B10$B$N4V$NCM$r$H$kMp?t$G$9!%(B (5) update branches set bbalance = bbalance + :delta where bid = :bid; - $B$3$3$G(B :bid $B$O(B 1 $B$+$i(B[$B%9%1%j%s%0%U%!%/%?!<(B]$B$N4V$NCM$rr7o(B -pgbench $B$O@P0f(B $BC#IW$K$h$C$F=q$+$l$^$7$?!#%i%$%;%s%9>r7o$O(B pgbench.c $B$N(B -$BKAF,$K=q$$$F$"$j$^$9!#$3$N>r7o$rr7o$O(B pgbench.c $B$N(B +$BKAF,$K=q$$$F$"$j$^$9!%$3$N>r7o$rcon = NULL; return (-1); } - return (0); + return (0); /* OK */ } /* process a transaction */ @@ -201,11 +240,20 @@ doOne(CState * state, int n, int debug) PQclear(res); discard_response(st); + if (is_connect) + { + PQfinish(st->con); + st->con = NULL; + } + if (++st->cnt >= nxacts) { remains--; /* I've done */ - PQfinish(st->con); - st->con = NULL; + if (st->con != NULL) + { + PQfinish(st->con); + st->con = NULL; + } return; } break; @@ -217,6 +265,19 @@ doOne(CState * state, int n, int debug) st->state = 0; } + if (st->con == NULL) + { + if ((st->con = doConnect()) == NULL) + { + fprintf(stderr, "Client %d aborted in establishing connection.\n", + n); + remains--; /* I've aborted */ + PQfinish(st->con); + st->con = NULL; + return; + } + } + switch (st->state) { case 0: /* about to start */ @@ -295,11 +356,20 @@ doSelectOnly(CState * state, int n, int debug) PQclear(res); discard_response(st); + if (is_connect) + { + PQfinish(st->con); + st->con = NULL; + } + if (++st->cnt >= nxacts) { remains--; /* I've done */ - PQfinish(st->con); - st->con = NULL; + if (st->con != NULL) + { + PQfinish(st->con); + st->con = NULL; + } return; } break; @@ -311,6 +381,19 @@ doSelectOnly(CState * state, int n, int debug) st->state = 0; } + if (st->con == NULL) + { + if ((st->con = doConnect()) == NULL) + { + fprintf(stderr, "Client %d aborted in establishing connection.\n", + n); + remains--; /* I've aborted */ + PQfinish(st->con); + st->con = NULL; + return; + } + } + switch (st->state) { case 0: @@ -349,7 +432,7 @@ disconnect_all(CState * state) /* create tables and setup data */ static void -init(char *pghost, char *pgport, char *dbName) +init() { PGconn *con; PGresult *res; @@ -366,13 +449,8 @@ init(char *pghost, char *pgport, char *dbName) int i; - con = PQsetdb(pghost, pgport, NULL, NULL, dbName); - if (PQstatus(con) == CONNECTION_BAD) - { - fprintf(stderr, "Connection to database '%s' on %s failed.\n", dbName, pghost); - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } + if ((con = doConnect()) == NULL) + exit(1); for (i = 0; i < (sizeof(DDLs) / sizeof(char *)); i++) { @@ -524,6 +602,7 @@ printResults( printf("tps = %f(excluding connections establishing)\n", t2); } + int main(int argc, char **argv) { @@ -532,9 +611,6 @@ main(int argc, char **argv) opterr, optopt; int c; - char *pghost = NULL; - char *pgport = NULL; - char *dbName; int is_init_mode = 0; /* initialize mode? */ int is_no_vacuum = 0; /* no vacuum at all before * testing? */ @@ -564,7 +640,7 @@ main(int argc, char **argv) PGconn *con; PGresult *res; - while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:S")) != EOF) + while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:U:P:CS")) != EOF) { switch (c) { @@ -615,6 +691,9 @@ main(int argc, char **argv) } #endif /* #ifndef __CYGWIN__ */ break; + case 'C': + is_connect = 1; + break; case 's': tps = atoi(optarg); if (tps <= 0) @@ -631,6 +710,12 @@ main(int argc, char **argv) exit(1); } break; + case 'U': + login = optarg; + break; + case 'P': + pwd = optarg; + break; default: usage(); exit(1); @@ -649,7 +734,7 @@ main(int argc, char **argv) if (is_init_mode) { - init(pghost, pgport, dbName); + init(); exit(0); } @@ -662,7 +747,10 @@ main(int argc, char **argv) } /* opening connection... */ - con = PQsetdb(pghost, pgport, NULL, NULL, dbName); + con = doConnect(); + if (con == NULL) + exit(1); + if (PQstatus(con) == CONNECTION_BAD) { fprintf(stderr, "Connection to database '%s' failed.\n", dbName); @@ -746,16 +834,14 @@ main(int argc, char **argv) /* get start up time */ gettimeofday(&tv1, 0); - /* make connections to the database */ - for (i = 0; i < nclients; i++) + if (is_connect == 0) { - state[i].con = PQsetdb(pghost, pgport, NULL, NULL, dbName); - if (PQstatus(state[i].con) == CONNECTION_BAD) - { - fprintf(stderr, "Connection to database '%s' failed.\n", dbName); - fprintf(stderr, "%s", PQerrorMessage(state[i].con)); - exit(1); - } + /* make connections to the database */ + for (i = 0; i < nclients; i++) + { + if ((state[i].con = doConnect()) == NULL) + exit(1); + } } /* time after connections set up */