Improve version reporting in pgbench.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 18 Jun 2021 21:05:23 +0000 (17:05 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 18 Jun 2021 21:05:23 +0000 (17:05 -0400)
Commit 547f04e73 caused pgbench to start printing its version number,
which seems like a fine idea, but it needs a bit more work:
* Print the server version number too, when different.
* Print the PG_VERSION string, not some reconstructed approximation.

This patch copies psql's well-tested code for the same purpose.

Discussion: https://postgr.es/m/1226654.1624036821@sss.pgh.pa.us

src/bin/pgbench/pgbench.c
src/bin/pgbench/t/001_pgbench_with_server.pl

index d7479925cb35a88c720fe6e1037e782f41f4541c..e61055b6b7b70de0f0fd41531e7d39374d44c93b 100644 (file)
@@ -63,6 +63,7 @@
 #include "common/username.h"
 #include "fe_utils/cancel.h"
 #include "fe_utils/conditional.h"
+#include "fe_utils/string_utils.h"
 #include "getopt_long.h"
 #include "libpq-fe.h"
 #include "pgbench.h"
@@ -5493,6 +5494,37 @@ printSimpleStats(const char *prefix, SimpleStats *ss)
    }
 }
 
+/* print version banner */
+static void
+printVersion(PGconn *con)
+{
+   int         server_ver = PQserverVersion(con);
+   int         client_ver = PG_VERSION_NUM;
+
+   if (server_ver != client_ver)
+   {
+       const char *server_version;
+       char        sverbuf[32];
+
+       /* Try to get full text form, might include "devel" etc */
+       server_version = PQparameterStatus(con, "server_version");
+       /* Otherwise fall back on server_ver */
+       if (!server_version)
+       {
+           formatPGVersionNumber(server_ver, true,
+                                 sverbuf, sizeof(sverbuf));
+           server_version = sverbuf;
+       }
+
+       printf(_("%s (%s, server %s)\n"),
+              "pgbench", PG_VERSION, server_version);
+   }
+   /* For version match, only print pgbench version */
+   else
+       printf("%s (%s)\n", "pgbench", PG_VERSION);
+   fflush(stdout);
+}
+
 /* print out results */
 static void
 printResults(StatsData *total,
@@ -5506,7 +5538,6 @@ printResults(StatsData *total,
    double      bench_duration = PG_TIME_GET_DOUBLE(total_duration);
    double      tps = ntx / bench_duration;
 
-   printf("pgbench (PostgreSQL) %d.%d\n", PG_VERSION_NUM / 10000, PG_VERSION_NUM % 100);
    /* Report test parameters. */
    printf("transaction type: %s\n",
           num_scripts == 1 ? sql_script[0].desc : "multiple scripts");
@@ -6334,6 +6365,9 @@ main(int argc, char **argv)
    if (con == NULL)
        exit(1);
 
+   /* report pgbench and server versions */
+   printVersion(con);
+
    pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s",
                 PQhost(con), PQport(con), nclients,
                 duration <= 0 ? "nxacts" : "duration",
index 55b3c3f6fdd5ab72c5d0797a98cc34bb7ebef6e1..923203ea517500fe5ea99fe851792a322e992529 100644 (file)
@@ -100,7 +100,7 @@ pgbench(
    'no such database');
 
 pgbench(
-   '-S -t 1', 1, [qr{^$}],
+   '-S -t 1', 1, [],
    [qr{Perhaps you need to do initialization}],
    'run without init');