mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
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
This commit is contained in:
parent
7c337b6b52
commit
84bee96109
@ -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",
|
||||
|
@ -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');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user