Add hint to run "pgbench -i", if test tables don't exist.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sat, 22 Aug 2015 13:19:10 +0000 (14:19 +0100)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sat, 22 Aug 2015 13:19:10 +0000 (14:19 +0100)
Fabien Coelho, reviewed by Julien Rouhaud

src/bin/pgbench/pgbench.c

index 2e55c906b620ca6021ea350ca151a555bb0156fd..30e8d2a3f2ec88d9b73c445b725d06c228e3ae5c 100644 (file)
@@ -55,6 +55,8 @@
 
 #include "pgbench.h"
 
+#define ERRCODE_UNDEFINED_TABLE  "42P01"
+
 /*
  * Multi-platform pthread implementations
  */
@@ -3252,7 +3254,14 @@ main(int argc, char **argv)
                res = PQexec(con, "select count(*) from pgbench_branches");
                if (PQresultStatus(res) != PGRES_TUPLES_OK)
                {
+                       char       *sqlState = PQresultErrorField(res, PG_DIAG_SQLSTATE);
+
                        fprintf(stderr, "%s", PQerrorMessage(con));
+                       if (sqlState && strcmp(sqlState, ERRCODE_UNDEFINED_TABLE) == 0)
+                       {
+                               fprintf(stderr, "Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\"\n", PQdb(con));
+                       }
+
                        exit(1);
                }
                scale = atoi(PQgetvalue(res, 0, 0));