Hi Fabien,
> That looks good!
>
> As COPY FREEZE was introduced in 9.3, this means that loading data
> would break with previous versions. Pgbench attempts at being
> compatible with older versions. I'm wondering whether we should not
> care or if we should attempt some compatibility layer. It seems enough
> to test "PQserverVersion() >= 90300"?
Good point.
Unfortunately with pre-14 COPY FREEZE we cannot get the speed up
effect because it requires the commit:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7db0cd2145f2bce84cac92402e205e4d2b045bf2
which was there only in the master branch as of Jan 17, 2021.
So I think adding "freeze" to the copy statement should only happen in
PostgreSQL 14 or later. Probably the test should be
"PQserverVersion() >= 140000" I think. Attached is the patch doing
what you suggest.
Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index f1d98be2d2..6fbf8d3311 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3820,6 +3820,7 @@ initGenerateDataClientSide(PGconn *con)
PGresult *res;
int i;
int64 k;
+ int server_version;
/* used to track elapsed time and estimate of the remaining time */
instr_time start,
@@ -3869,7 +3870,23 @@ initGenerateDataClientSide(PGconn *con)
/*
* accounts is big enough to be worth using COPY and tracking runtime
*/
- res = PQexec(con, "copy pgbench_accounts from stdin");
+
+ server_version = PQserverVersion(con);
+ if (server_version == 0)
+ {
+ pg_log_fatal("could not get server version");
+ exit(1);
+ }
+
+ /*
+ * If server version is 14.0 or later, we can take account of freeze
+ * option of copy.
+ */
+ if (server_version >= 140000)
+ res = PQexec(con, "copy pgbench_accounts from stdin with (freeze on)");
+ else
+ res = PQexec(con, "copy pgbench_accounts from stdin");
+
if (PQresultStatus(res) != PGRES_COPY_IN)
{
pg_log_fatal("unexpected copy in result: %s", PQerrorMessage(con));