From 84bee9610965331d5110971d8de390a5bbe2effc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 18 Jun 2021 17:05:23 -0400 Subject: [PATCH] Improve version reporting in pgbench. 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 | 36 +++++++++++++++++++- src/bin/pgbench/t/001_pgbench_with_server.pl | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index d7479925cb3..e61055b6b7b 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -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", diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl b/src/bin/pgbench/t/001_pgbench_with_server.pl index 55b3c3f6fdd..923203ea517 100644 --- a/src/bin/pgbench/t/001_pgbench_with_server.pl +++ b/src/bin/pgbench/t/001_pgbench_with_server.pl @@ -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');