Commit ba708ea3 authored by Tatsuo Ishii's avatar Tatsuo Ishii

Add -U, -P, -C options. See README.pgbench for more details.

parent d330f09a
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? o What is pgbench?
...@@ -101,6 +101,15 @@ o options ...@@ -101,6 +101,15 @@ o options
(10,000,000) tuples in the accounts table. (10,000,000) tuples in the accounts table.
default is 1. 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 -n
No vacuuming and cleaning the history table prior the No vacuuming and cleaning the history table prior the
test is performed. test is performed.
...@@ -113,6 +122,11 @@ o options ...@@ -113,6 +122,11 @@ o options
-S -S
Perform select only transactions instead of TPC-B. 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 -d
debug option. debug option.
...@@ -139,6 +153,9 @@ Basically it is same as BSD license. See pgbench.c for more details. ...@@ -139,6 +153,9 @@ Basically it is same as BSD license. See pgbench.c for more details.
o History o History
2001/09/09
* Add -U, -P, -C options
2000/1/15 pgbench-1.2 contributed to PostgreSQL 2000/1/15 pgbench-1.2 contributed to PostgreSQL
* Add -v option * Add -v option
......
This diff is collapsed.
/* /*
* $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.9 2001/08/01 01:08:17 ishii Exp $ * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.10 2001/09/09 03:15:56 ishii Exp $
* *
* pgbench: a simple TPC-B like benchmark program for PostgreSQL * pgbench: a simple TPC-B like benchmark program for PostgreSQL
* written by Tatsuo Ishii * written by Tatsuo Ishii
...@@ -67,6 +67,16 @@ int tps = 1; ...@@ -67,6 +67,16 @@ int tps = 1;
int remains; /* number of remained clients */ int remains; /* number of remained clients */
int is_connect; /* establish connection for each transactoin */
char *pghost = "";
char *pgport = NULL;
char *pgoptions = NULL;
char *pgtty = NULL;
char *login = NULL;
char *pwd = NULL;
char *dbName;
typedef struct typedef struct
{ {
PGconn *con; /* connection handle to DB */ PGconn *con; /* connection handle to DB */
...@@ -85,8 +95,8 @@ typedef struct ...@@ -85,8 +95,8 @@ typedef struct
static void static void
usage() usage()
{ {
fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-v][-S][-d][dbname]\n"); fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-C][-v][-S][-U login][-P password][-d][dbname]\n");
fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-d][dbname]\n"); fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-U login][-P password][-d][dbname]\n");
} }
/* random number generator */ /* random number generator */
...@@ -96,6 +106,34 @@ getrand(int min, int max) ...@@ -96,6 +106,34 @@ getrand(int min, int max)
return (min + (int) (max * 1.0 * rand() / (RAND_MAX + 1.0))); return (min + (int) (max * 1.0 * rand() / (RAND_MAX + 1.0)));
} }
/* set up a connection to the backend */
static PGconn *doConnect()
{
PGconn *con;
con = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName,
login, pwd);
if (con == NULL)
{
fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
fprintf(stderr, "Memory allocatin problem?\n");
return(NULL);
}
if (PQstatus(con) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
if (PQerrorMessage(con))
fprintf(stderr, "%s", PQerrorMessage(con));
else
fprintf(stderr, "No explanation from the backend\n");
return(NULL);
}
return (con);
}
/* throw away response from backend */ /* throw away response from backend */
static void static void
discard_response(CState * state) discard_response(CState * state)
...@@ -110,6 +148,7 @@ discard_response(CState * state) ...@@ -110,6 +148,7 @@ discard_response(CState * state)
} while (res); } while (res);
} }
/* check to see if the SQL result was good */
static int static int
check(CState * state, PGresult *res, int n, int good) check(CState * state, PGresult *res, int n, int good)
{ {
...@@ -123,7 +162,7 @@ check(CState * state, PGresult *res, int n, int good) ...@@ -123,7 +162,7 @@ check(CState * state, PGresult *res, int n, int good)
st->con = NULL; st->con = NULL;
return (-1); return (-1);
} }
return (0); return (0); /* OK */
} }
/* process a transaction */ /* process a transaction */
...@@ -201,11 +240,20 @@ doOne(CState * state, int n, int debug) ...@@ -201,11 +240,20 @@ doOne(CState * state, int n, int debug)
PQclear(res); PQclear(res);
discard_response(st); discard_response(st);
if (is_connect)
{
PQfinish(st->con);
st->con = NULL;
}
if (++st->cnt >= nxacts) if (++st->cnt >= nxacts)
{ {
remains--; /* I've done */ remains--; /* I've done */
PQfinish(st->con); if (st->con != NULL)
st->con = NULL; {
PQfinish(st->con);
st->con = NULL;
}
return; return;
} }
break; break;
...@@ -217,6 +265,19 @@ doOne(CState * state, int n, int debug) ...@@ -217,6 +265,19 @@ doOne(CState * state, int n, int debug)
st->state = 0; 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) switch (st->state)
{ {
case 0: /* about to start */ case 0: /* about to start */
...@@ -295,11 +356,20 @@ doSelectOnly(CState * state, int n, int debug) ...@@ -295,11 +356,20 @@ doSelectOnly(CState * state, int n, int debug)
PQclear(res); PQclear(res);
discard_response(st); discard_response(st);
if (is_connect)
{
PQfinish(st->con);
st->con = NULL;
}
if (++st->cnt >= nxacts) if (++st->cnt >= nxacts)
{ {
remains--; /* I've done */ remains--; /* I've done */
PQfinish(st->con); if (st->con != NULL)
st->con = NULL; {
PQfinish(st->con);
st->con = NULL;
}
return; return;
} }
break; break;
...@@ -311,6 +381,19 @@ doSelectOnly(CState * state, int n, int debug) ...@@ -311,6 +381,19 @@ doSelectOnly(CState * state, int n, int debug)
st->state = 0; 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) switch (st->state)
{ {
case 0: case 0:
...@@ -349,7 +432,7 @@ disconnect_all(CState * state) ...@@ -349,7 +432,7 @@ disconnect_all(CState * state)
/* create tables and setup data */ /* create tables and setup data */
static void static void
init(char *pghost, char *pgport, char *dbName) init()
{ {
PGconn *con; PGconn *con;
PGresult *res; PGresult *res;
...@@ -366,13 +449,8 @@ init(char *pghost, char *pgport, char *dbName) ...@@ -366,13 +449,8 @@ init(char *pghost, char *pgport, char *dbName)
int i; int i;
con = PQsetdb(pghost, pgport, NULL, NULL, dbName); if ((con = doConnect()) == NULL)
if (PQstatus(con) == CONNECTION_BAD) exit(1);
{
fprintf(stderr, "Connection to database '%s' on %s failed.\n", dbName, pghost);
fprintf(stderr, "%s", PQerrorMessage(con));
exit(1);
}
for (i = 0; i < (sizeof(DDLs) / sizeof(char *)); i++) for (i = 0; i < (sizeof(DDLs) / sizeof(char *)); i++)
{ {
...@@ -524,6 +602,7 @@ printResults( ...@@ -524,6 +602,7 @@ printResults(
printf("tps = %f(excluding connections establishing)\n", t2); printf("tps = %f(excluding connections establishing)\n", t2);
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -532,9 +611,6 @@ main(int argc, char **argv) ...@@ -532,9 +611,6 @@ main(int argc, char **argv)
opterr, opterr,
optopt; optopt;
int c; int c;
char *pghost = NULL;
char *pgport = NULL;
char *dbName;
int is_init_mode = 0; /* initialize mode? */ int is_init_mode = 0; /* initialize mode? */
int is_no_vacuum = 0; /* no vacuum at all before int is_no_vacuum = 0; /* no vacuum at all before
* testing? */ * testing? */
...@@ -564,7 +640,7 @@ main(int argc, char **argv) ...@@ -564,7 +640,7 @@ main(int argc, char **argv)
PGconn *con; PGconn *con;
PGresult *res; 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) switch (c)
{ {
...@@ -615,6 +691,9 @@ main(int argc, char **argv) ...@@ -615,6 +691,9 @@ main(int argc, char **argv)
} }
#endif /* #ifndef __CYGWIN__ */ #endif /* #ifndef __CYGWIN__ */
break; break;
case 'C':
is_connect = 1;
break;
case 's': case 's':
tps = atoi(optarg); tps = atoi(optarg);
if (tps <= 0) if (tps <= 0)
...@@ -631,6 +710,12 @@ main(int argc, char **argv) ...@@ -631,6 +710,12 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
break; break;
case 'U':
login = optarg;
break;
case 'P':
pwd = optarg;
break;
default: default:
usage(); usage();
exit(1); exit(1);
...@@ -649,7 +734,7 @@ main(int argc, char **argv) ...@@ -649,7 +734,7 @@ main(int argc, char **argv)
if (is_init_mode) if (is_init_mode)
{ {
init(pghost, pgport, dbName); init();
exit(0); exit(0);
} }
...@@ -662,7 +747,10 @@ main(int argc, char **argv) ...@@ -662,7 +747,10 @@ main(int argc, char **argv)
} }
/* opening connection... */ /* opening connection... */
con = PQsetdb(pghost, pgport, NULL, NULL, dbName); con = doConnect();
if (con == NULL)
exit(1);
if (PQstatus(con) == CONNECTION_BAD) if (PQstatus(con) == CONNECTION_BAD)
{ {
fprintf(stderr, "Connection to database '%s' failed.\n", dbName); fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
...@@ -746,16 +834,14 @@ main(int argc, char **argv) ...@@ -746,16 +834,14 @@ main(int argc, char **argv)
/* get start up time */ /* get start up time */
gettimeofday(&tv1, 0); gettimeofday(&tv1, 0);
/* make connections to the database */ if (is_connect == 0)
for (i = 0; i < nclients; i++)
{ {
state[i].con = PQsetdb(pghost, pgport, NULL, NULL, dbName); /* make connections to the database */
if (PQstatus(state[i].con) == CONNECTION_BAD) for (i = 0; i < nclients; i++)
{ {
fprintf(stderr, "Connection to database '%s' failed.\n", dbName); if ((state[i].con = doConnect()) == NULL)
fprintf(stderr, "%s", PQerrorMessage(state[i].con)); exit(1);
exit(1); }
}
} }
/* time after connections set up */ /* time after connections set up */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment