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

Commitb332dc3

Browse files
committed
When invoked with -i (initialize mode), split the copy command every
10000 tuples, rather than one big copy. This will prevent generatingtoo much WAL logs.
1 parentda87253 commitb332dc3

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
intj=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)

[8]ページ先頭

©2009-2025 Movatter.jp