From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Cc: Thomas Munro <thomas.munro@gmail.com>
Subject: Re: Version reporting in pgbench
Date: Fri, 18 Jun 2021 23:18:45 +0200 (CEST)
Message-ID: <alpine.DEB.2.22.394.2106182300170.3211875@pseudo> (raw)
In-Reply-To: <1234107.1624041603@sss.pgh.pa.us>
References: <1226654.1624036821@sss.pgh.pa.us>
<alpine.DEB.2.22.394.2106182021570.3211875@pseudo>
<1234107.1624041603@sss.pgh.pa.us>
Hello Tom,
>> Why not move the printVersion call right after the connection is
>> created, at line 6374?
>
> I started with that, and one of the 001_pgbench_with_server.pl
> tests fell over --- it was expecting no stdout output before a
> "Perhaps you need to do initialization" failure. If you don't
> mind changing that,
Why would I mind?
> I agree that printing immediately after the connection is made is a bit
> less astonishing.
Ok, so let's just update the test? Attached a proposal with the version
moved.
Note that if no connections are available, then you do not get the
version, which may be a little bit strange. Attached v3 prints out the
local version in that case. Not sure whether it is worth the effort.
--
Fabien.
Attachments:download all (2 files, .tar.gz)pgbench-version-banner-2.patch (text/x-diff, 2.5K) downloaddiff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.cindex d7479925cb..e61055b6b7 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.plindex 55b3c3f6fd..49fe48093c 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{^pgbench \([^\n]+\)$}],
[qr{Perhaps you need to do initialization}],
'run without init');
pgbench-version-banner-3.patch (text/x-diff, 2.8K) downloaddiff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.cindex d7479925cb..20910e5ad1 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");
@@ -6332,7 +6363,13 @@ main(int argc, char **argv)
/* opening connection... */
con = doConnect();
if (con == NULL)
+ {+ printf("%s (%s)\n", "pgbench", PG_VERSION);
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,
diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl b/src/bin/pgbench/t/001_pgbench_with_server.plindex 55b3c3f6fd..6a40e4b7d1 100644--- a/src/bin/pgbench/t/001_pgbench_with_server.pl+++ b/src/bin/pgbench/t/001_pgbench_with_server.pl@@ -92,7 +92,7 @@ pgbench(
pgbench(
'no-such-database',
1,
- [qr{^$}],+ [qr{^pgbench \([^\n]*\)$}],
[
qr{connection to server .* failed},
qr{FATAL: database "no-such-database" does not exist}
@@ -100,7 +100,7 @@ pgbench(
'no such database');
pgbench(
- '-S -t 1', 1, [qr{^$}],+ '-S -t 1', 1, [qr{^pgbench \([^\n]+\)$}],
[qr{Perhaps you need to do initialization}],
'run without init');
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: coelho@cri.ensmp.fr, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org, thomas.munro@gmail.com
Subject: Re: Version reporting in pgbench
In-Reply-To: <alpine.DEB.2.22.394.2106182300170.3211875@pseudo>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox