Skip to content

Commit d0d649e

Browse files
Limit pgbench COPY FREEZE to ordinary relations
pgbench client-side data generation uses COPY FREEZE to load data for most tables. COPY FREEZE isn't supported for partitioned tables and since pgbench only supports partitioning pgbench_accounts, pgbench used a hard-coded check to skip COPY FREEZE and use plain COPY for a partitioned pgbench_accounts. If the user has manually partitioned one of the other pgbench tables, this causes client-side data generation to error out with: ERROR: cannot perform COPY FREEZE on a partitioned table Fix this by limiting COPY FREEZE to ordinary tables (RELKIND_RELATION). Author: Sergey Tatarintsev <s.tatarintsev@postgrespro.ru> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/flat/97f55fca-8a7b-4da8-b413-7d1c57010676%40postgrespro.ru
1 parent 38172d1 commit d0d649e

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

doc/src/sgml/ref/pgbench.sgml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,10 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
231231
sent to the server. This uses the client/server bandwidth
232232
extensively through a <command>COPY</command>.
233233
<command>pgbench</command> uses the <option>FREEZE</option> option
234-
with version 14 or later
235-
of <productname>PostgreSQL</productname> to speed up
236-
subsequent <command>VACUUM</command>, except on the
237-
<literal>pgbench_accounts</literal> table if partitions are
238-
enabled. Using <literal>g</literal> causes logging to
234+
to load data into ordinary (non-partition) tables with version 14
235+
or later of <productname>PostgreSQL</productname> to speed up
236+
subsequent <command>VACUUM</command>.
237+
Using <literal>g</literal> causes logging to
239238
print one message every 100,000 rows while generating data for all
240239
tables.
241240
</para>

src/bin/pgbench/pgbench.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <sys/select.h>
5454
#endif
5555

56+
#include "catalog/pg_class_d.h"
5657
#include "common/int.h"
5758
#include "common/logging.h"
5859
#include "common/pg_prng.h"
@@ -848,6 +849,31 @@ static const PsqlScanCallbacks pgbench_callbacks = {
848849
NULL, /* don't need get_variable functionality */
849850
};
850851

852+
static char
853+
get_table_relkind(PGconn *con, const char *table)
854+
{
855+
PGresult *res;
856+
char *val;
857+
char relkind;
858+
const char *params[1] = {table};
859+
const char *sql =
860+
"SELECT relkind FROM pg_catalog.pg_class WHERE oid=$1::pg_catalog.regclass";
861+
862+
res = PQexecParams(con, sql, 1, NULL, params, NULL, NULL, 0);
863+
if (PQresultStatus(res) != PGRES_TUPLES_OK)
864+
{
865+
pg_log_error("query failed: %s", PQerrorMessage(con));
866+
pg_log_error_detail("Query was: %s", sql);
867+
exit(1);
868+
}
869+
val = PQgetvalue(res, 0, 0);
870+
Assert(strlen(val) == 1);
871+
relkind = val[0];
872+
PQclear(res);
873+
874+
return relkind;
875+
}
876+
851877
static inline pg_time_usec_t
852878
pg_time_now(void)
853879
{
@@ -4962,16 +4988,11 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
49624988

49634989
initPQExpBuffer(&sql);
49644990

4965-
/*
4966-
* Use COPY with FREEZE on v14 and later for all the tables except
4967-
* pgbench_accounts when it is partitioned.
4968-
*/
4969-
if (PQserverVersion(con) >= 140000)
4970-
{
4971-
if (strcmp(table, "pgbench_accounts") != 0 ||
4972-
partitions == 0)
4973-
copy_statement_fmt = "copy %s from stdin with (freeze on)";
4974-
}
4991+
/* Use COPY with FREEZE on v14 and later for all ordinary tables */
4992+
if ((PQserverVersion(con) >= 140000) &&
4993+
get_table_relkind(con, table) == RELKIND_RELATION)
4994+
copy_statement_fmt = "copy %s from stdin with (freeze on)";
4995+
49754996

49764997
n = pg_snprintf(copy_statement, sizeof(copy_statement), copy_statement_fmt, table);
49774998
if (n >= sizeof(copy_statement))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy