|
1 | 1 | /*
|
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 $ |
3 | 3 | *
|
4 | 4 | * pgbench: a simple TPC-B like benchmark program for PostgreSQL
|
5 | 5 | * written by Tatsuo Ishii
|
@@ -417,45 +417,68 @@ init(char *pghost, char *pgport, char *dbName)
|
417 | 417 | PQclear(res);
|
418 | 418 | }
|
419 | 419 |
|
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) |
422 | 422 | {
|
423 | 423 | fprintf(stderr,"%s",PQerrorMessage(con));
|
424 | 424 | exit(1);
|
425 | 425 | }
|
426 |
| -PQclear(res); |
427 | 426 |
|
| 427 | + |
| 428 | +/* |
| 429 | + * occupy accounts table with some data |
| 430 | + */ |
428 | 431 | fprintf(stderr,"creating tables...\n");
|
429 | 432 | for (i=0;i<naccounts*tps;i++)
|
430 | 433 | {
|
431 | 434 | intj=i+1;
|
432 | 435 |
|
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); |
434 | 448 | if (PQputline(con,sql))
|
435 | 449 | {
|
436 | 450 | fprintf(stderr,"PQputline failed\n");
|
437 | 451 | exit(1);
|
438 | 452 | }
|
| 453 | + |
439 | 454 | 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 | + */ |
440 | 460 | 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 | +} |
453 | 466 |
|
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 | +} |
459 | 482 | }
|
460 | 483 |
|
461 | 484 | /* vacuum */
|
|