New -x option for pgbench executes the given command once after connection of each session.
e.g. pgbench -x "SET synchronous_commit = off" pgbench -x "SET foo_extension.enabled = on" Allows easier testing of user parameters. Command listed in final report $ pgbench -c 2 -t 4 -x "set synchronous_commit = off" starting vacuum...end. transaction type: TPC-B (sort of) post connect command: [set synchronous_commit = off] scaling factor: 1 query mode: simple number of clients: 2 number of threads: 1 number of transactions per client: 4 number of transactions actually processed: 8/8 tps = 122.897304 (including connections establishing) tps = 179.953212 (excluding connections establishing) -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 9081f09..1a975d8 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -150,6 +150,7 @@ char *pgoptions = NULL; char *pgtty = NULL; char *login = NULL; char *dbName; +char *postConnectCommand = NULL; volatile bool timer_exceeded = false; /* flag from signal handler */ @@ -367,6 +368,7 @@ usage(const char *progname) " -t NUM number of transactions each client runs (default: 10)\n" " -T NUM duration of benchmark test in seconds\n" " -v vacuum all four standard tables before tests\n" + " -x SQLCMD execute SQLCMD once after connection of each db session\n" "\nCommon options:\n" " -d print debugging output\n" " -h HOSTNAME database server host or socket directory\n" @@ -454,6 +456,9 @@ doConnect(void) return NULL; } + if (postConnectCommand) + executeStatement(conn, postConnectCommand); + return conn; } @@ -1769,6 +1774,7 @@ printResults(int ttype, int normal_xacts, int nclients, s = "Custom query"; printf("transaction type: %s\n", s); + printf("post connect command: [%s]\n", (postConnectCommand ? postConnectCommand : "not set")); printf("scaling factor: %d\n", scale); printf("query mode: %s\n", QUERYMODE[querymode]); printf("number of clients: %d\n", nclients); @@ -1910,7 +1916,7 @@ main(int argc, char **argv) state = (CState *) xmalloc(sizeof(CState)); memset(state, 0, sizeof(CState)); - while ((c = getopt_long(argc, argv, "ih:nvp:dSNc:j:Crs:t:T:U:lf:D:F:M:", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "ih:nvp:dSNc:j:Crs:t:T:U:lf:D:F:M:x:", long_options, &optindex)) != -1) { switch (c) { @@ -2062,6 +2068,9 @@ main(int argc, char **argv) exit(1); } break; + case 'x': + postConnectCommand = optarg; + break; case 0: /* This covers long options which take no argument. */ break;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers