Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06ba4a6

Browse files
committed
Use COPY FREEZE in pgbench for faster benchmark table population.
While populating the pgbench_accounts table, plain COPY wasunconditionally used. By changing it to COPY FREEZE, the time forVACUUM is significantly reduced, thus the total time of "pgbench -i"is also reduced. This only happens if pgbench runs against PostgreSQL14 or later because COPY FREEZE in previous versions of PostgreSQL doesnot bring the benefit. Also if partitioning is used, COPY FREEZEcannot be used. In this case plain COPY will be used too.Author: Tatsuo IshiiDiscussion:https://postgr.es/m/20210308.143907.2014279678657453983.t-ishii@gmail.comReviewed-by: Fabien COELHO, Laurenz Albe, Peter Geoghegan, Dean Rasheed
1 parent469150a commit06ba4a6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

‎doc/src/sgml/ref/pgbench.sgml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
220220
data is generated in <command>pgbench</command> client and then
221221
sent to the server. This uses the client/server bandwidth
222222
extensively through a <command>COPY</command>.
223+
<command>pgbench</command> uses the FREEZE option with 14 or later
224+
versions of <productname>PostgreSQL</productname> to speed up
225+
subsequent <command>VACUUM</command>, unless partitions are enabled.
223226
Using <literal>g</literal> causes logging to print one message
224227
every 100,000 rows while generating data for the
225228
<structname>pgbench_accounts</structname> table.

‎src/bin/pgbench/pgbench.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4153,6 +4153,7 @@ initGenerateDataClientSide(PGconn *con)
41534153
PGresult*res;
41544154
inti;
41554155
int64k;
4156+
char*copy_statement;
41564157

41574158
/* used to track elapsed time and estimate of the remaining time */
41584159
pg_time_usec_tstart;
@@ -4199,7 +4200,15 @@ initGenerateDataClientSide(PGconn *con)
41994200
/*
42004201
* accounts is big enough to be worth using COPY and tracking runtime
42014202
*/
4202-
res=PQexec(con,"copy pgbench_accounts from stdin");
4203+
4204+
/* use COPY with FREEZE on v14 and later without partioning */
4205+
if (partitions==0&&PQserverVersion(con) >=140000)
4206+
copy_statement="copy pgbench_accounts from stdin with (freeze on)";
4207+
else
4208+
copy_statement="copy pgbench_accounts from stdin";
4209+
4210+
res=PQexec(con,copy_statement);
4211+
42034212
if (PQresultStatus(res)!=PGRES_COPY_IN)
42044213
{
42054214
pg_log_fatal("unexpected copy in result: %s",PQerrorMessage(con));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp