pgbench -f and vacuum - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject pgbench -f and vacuum
Date
Msg-id 20141213.191654.1409898280330806597.t-ishii@sraoss.co.jp
Whole thread Raw
Responses Re: pgbench -f and vacuum  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Currently pgbench -f (run custom script) executes vacuum against
pgbench_* tables before stating bench marking if -n (or --no-vacuum)
is not specified. If those tables do not exist, pgbench fails. To
prevent this, -n must be specified. For me this behavior seems insane
because "-f" does not necessarily suppose the existence of the
pgbench_* tables.  Attached patch prevents pgbench from exiting even
if those tables do not exist. Here is the sample session:

./pgbench -f /tmp/a.sql test2
starting vacuum...ERROR:  relation "pgbench_branches" does not exist
ERROR:  relation "pgbench_tellers" does not exist
ERROR:  relation "pgbench_history" does not exist
end.
transaction type: Custom query
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
number of transactions per client: 10
number of transactions actually processed: 10/10
latency average: 0.000 ms
tps = 5977.286312 (including connections establishing)
tps = 15822.784810 (excluding connections establishing)

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 3453a1f..0a48646 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -605,6 +605,22 @@ executeStatement(PGconn *con, const char *sql)    PQclear(res);}
+/* call PQexec() but does not exit() on failure, instead returns -1. */
+static int
+executeStatement2(PGconn *con, const char *sql)
+{
+    PGresult   *res;
+
+    res = PQexec(con, sql);
+    if (PQresultStatus(res) != PGRES_COMMAND_OK)
+    {
+        fprintf(stderr, "%s", PQerrorMessage(con));
+        return -1;
+    }
+    PQclear(res);
+    return 0;
+}
+/* set up a connection to the backend */static PGconn *doConnect(void)
@@ -3193,15 +3209,19 @@ main(int argc, char **argv)    if (!is_no_vacuum)    {        fprintf(stderr, "starting
vacuum...");
-        executeStatement(con, "vacuum pgbench_branches");
-        executeStatement(con, "vacuum pgbench_tellers");
-        executeStatement(con, "truncate pgbench_history");
+        if (executeStatement2(con, "vacuum pgbench_branches") && ttype != 3)
+            exit(1);
+        if (executeStatement2(con, "vacuum pgbench_tellers") && ttype != 3)
+            exit(1);
+        if (executeStatement2(con, "truncate pgbench_history") && ttype != 3)
+            exit(1);        fprintf(stderr, "end.\n");        if (do_vacuum_accounts)        {
fprintf(stderr,"starting vacuum pgbench_accounts...");
 
-            executeStatement(con, "vacuum analyze pgbench_accounts");
+            if (executeStatement2(con, "vacuum analyze pgbench_accounts") && ttype != 3)
+                exit(1);            fprintf(stderr, "end.\n");        }    }

pgsql-hackers by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Commitfest problems
Next
From: Pavel Stehule
Date:
Subject: moving Orafce from pgFoundry - pgFoundry management