Re: Using COPY FREEZE in pgbench - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject Re: Using COPY FREEZE in pgbench
Date
Msg-id 20210319.135334.1757641418273383386.t-ishii@sraoss.co.jp
Whole thread Raw
Responses Re: Using COPY FREEZE in pgbench
List pgsql-hackers
> I have looked in the code of PQprotocolVersion. The only case in which
> it returns 0 is there's no connection. Yes, you are right. Once the
> connection has been successfuly established, there's no chance it
> fails. So I agree with you.

Attached v3 patch addresses this.

>> The "g" item in the section describing initialization steps
>> (i.e. option -I). I'd suggest just to replace "COPY" with "COPY
>> FREEZE" in the sentence.
> 
> Ok. The section is needed to be modified.

This is also addressed in the patch.

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/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 50cf22ba6b..9badafbc1f 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -220,6 +220,9 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
             data is generated in <command>pgbench</command> client and then
             sent to the server. This uses the client/server bandwidth
             extensively through a <command>COPY</command>.
+            <command>pgbench</command> uses FREEZE option with 14 or later
+            version of <productname>PostgreSQL</productname> to speed up
+            subsequent <command>VACUUM</command>.
             Using <literal>g</literal> causes logging to print one message
             every 100,000 rows while generating data for the
             <structname>pgbench_accounts</structname> table.
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index e69d43b26b..a842b59188 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3976,6 +3976,7 @@ initGenerateDataClientSide(PGconn *con)
     PGresult   *res;
     int            i;
     int64        k;
+    int            server_version;
 
     /* used to track elapsed time and estimate of the remaining time */
     pg_time_usec_t start;
@@ -4022,7 +4023,18 @@ initGenerateDataClientSide(PGconn *con)
     /*
      * accounts is big enough to be worth using COPY and tracking runtime
      */
-    res = PQexec(con, "copy pgbench_accounts from stdin");
+
+    /*
+     * If server version is 14.0 or later, we can take account of freeze
+     * option of copy.
+     */
+    server_version = PQserverVersion(con);
+
+    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));

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: make the stats collector shutdown without writing the statsfiles if the immediate shutdown is requested.
Next
From: Fujii Masao
Date:
Subject: Re: Type of wait events WalReceiverWaitStart and WalSenderWaitForWAL