Skip to content

Commit b332dc3

Browse files
committed
When invoked with -i (initialize mode), split the copy command every
10000 tuples, rather than one big copy. This will prevent generating too much WAL logs.
1 parent da87253 commit b332dc3

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

contrib/pgbench/pgbench.c

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.8 2001/02/10 02:31:25 tgl Exp $
2+
* $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.9 2001/08/01 01:08:17 ishii Exp $
33
*
44
* pgbench: a simple TPC-B like benchmark program for PostgreSQL
55
* written by Tatsuo Ishii
@@ -417,45 +417,68 @@ init(char *pghost, char *pgport, char *dbName)
417417
PQclear(res);
418418
}
419419

420-
res = PQexec(con, "copy accounts from stdin");
421-
if (PQresultStatus(res) != PGRES_COPY_IN)
420+
res = PQexec(con, "end");
421+
if (PQresultStatus(res) != PGRES_COMMAND_OK)
422422
{
423423
fprintf(stderr, "%s", PQerrorMessage(con));
424424
exit(1);
425425
}
426-
PQclear(res);
427426

427+
428+
/*
429+
* occupy accounts table with some data
430+
*/
428431
fprintf(stderr, "creating tables...\n");
429432
for (i = 0; i < naccounts * tps; i++)
430433
{
431434
int j = i + 1;
432435

433-
sprintf(sql, "%d\t%d\t%d\t\n", i + 1, (i + 1) / naccounts, 0);
436+
if (j % 10000 == 1)
437+
{
438+
res = PQexec(con, "copy accounts from stdin");
439+
if (PQresultStatus(res) != PGRES_COPY_IN)
440+
{
441+
fprintf(stderr, "%s", PQerrorMessage(con));
442+
exit(1);
443+
}
444+
PQclear(res);
445+
}
446+
447+
sprintf(sql, "%d\t%d\t%d\t\n", j, j / naccounts, 0);
434448
if (PQputline(con, sql))
435449
{
436450
fprintf(stderr, "PQputline failed\n");
437451
exit(1);
438452
}
453+
439454
if (j % 10000 == 0)
455+
{
456+
/*
457+
* every 10000 tuples, we commit the copy command.
458+
* this should avoid generating too much WAL logs
459+
*/
440460
fprintf(stderr, "%d tuples done.\n", j);
441-
}
442-
if (PQputline(con, "\\.\n"))
443-
{
444-
fprintf(stderr, "very last PQputline failed\n");
445-
exit(1);
446-
}
447-
448-
if (PQendcopy(con))
449-
{
450-
fprintf(stderr, "PQendcopy failed\n");
451-
exit(1);
452-
}
461+
if (PQputline(con, "\\.\n"))
462+
{
463+
fprintf(stderr, "very last PQputline failed\n");
464+
exit(1);
465+
}
453466

454-
res = PQexec(con, "end");
455-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
456-
{
457-
fprintf(stderr, "%s", PQerrorMessage(con));
458-
exit(1);
467+
if (PQendcopy(con))
468+
{
469+
fprintf(stderr, "PQendcopy failed\n");
470+
exit(1);
471+
}
472+
/*
473+
* do a checkpoint to purge the old WAL logs
474+
*/
475+
res = PQexec(con, "checkpoint");
476+
if (PQresultStatus(res) != PGRES_COMMAND_OK)
477+
{
478+
fprintf(stderr, "%s", PQerrorMessage(con));
479+
exit(1);
480+
}
481+
}
459482
}
460483

461484
/* vacuum */

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