Re: Using COPY FREEZE in pgbench - Mailing list pgsql-hackers
From | Tatsuo Ishii |
---|---|
Subject | Re: Using COPY FREEZE in pgbench |
Date | |
Msg-id | 20210704.173156.2097825742796807238.t-ishii@gmail.com Whole thread Raw |
In response to | Re: Using COPY FREEZE in pgbench (Fabien COELHO <coelho@cri.ensmp.fr>) |
Responses |
Re: Using COPY FREEZE in pgbench
|
List | pgsql-hackers |
Hi fabien, >> So overall gain by the patch is around 15%, whereas the last test >> before the commit was 14%. It seems the patch is still beneficial >> after the commit. > > Yes, that's good! Yeah! > I had a quick look again, and about the comment: > > /* > * If partitioning is not enabled and server version is 14.0 or later, we > * can take account of freeze option of copy. > */ > > I'd suggest instead the shorter: > > /* use COPY with FREEZE on v14 and later without partioning */ > > Or maybe even to fully drop the comment, because the code is clear > enough and the doc already says it. I'd prefer to leave a comment. People (including me) tend to forget things in the future, that are obvious now:-) 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 0c60077e1f..0f432767c2 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 the FREEZE option with 14 or later + versions of <productname>PostgreSQL</productname> to speed up + subsequent <command>VACUUM</command>, unless partitions are enabled. 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 4aeccd93af..54d993075f 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -4119,6 +4119,7 @@ initGenerateDataClientSide(PGconn *con) PGresult *res; int i; int64 k; + char *copy_statement; /* used to track elapsed time and estimate of the remaining time */ pg_time_usec_t start; @@ -4165,7 +4166,15 @@ initGenerateDataClientSide(PGconn *con) /* * accounts is big enough to be worth using COPY and tracking runtime */ - res = PQexec(con, "copy pgbench_accounts from stdin"); + + /* use COPY with FREEZE on v14 and later without partioning */ + if (partitions == 0 && PQserverVersion(con) >= 140000) + copy_statement = "copy pgbench_accounts from stdin with (freeze on)"; + else + copy_statement = "copy pgbench_accounts from stdin"; + + res = PQexec(con, copy_statement); + if (PQresultStatus(res) != PGRES_COPY_IN) { pg_log_fatal("unexpected copy in result: %s", PQerrorMessage(con));
pgsql-hackers by date: