Skip to content

Commit 1d468b9

Browse files
committed
Add query cancellation capabilities in pgbench init phase
This can be useful to stop data generation happening on the server for long-running queries caused by large scale factors. This cannot happen by default as data is generated on the client, but it is possible to control the initialization steps of pgbench to do that. Reported-by: Fujii Masao Author: Fabien Coelho Discussion: https://postgr.es/m/alpine.DEB.2.21.1910311939430.27369@lancre Discussion: https://postgr.es/m/CAHGQGwHWEyTXxZh46qgFY8a2bDF_EYeUdp3+_Hy=qLZSzwVPKg@mail.gmail.com
1 parent a4fd3aa commit 1d468b9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

‎src/bin/pgbench/pgbench.c

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
#include "common/int.h"
6161
#include "common/logging.h"
62+
#include "fe_utils/cancel.h"
6263
#include "fe_utils/conditional.h"
6364
#include "getopt_long.h"
6465
#include "libpq-fe.h"
@@ -3894,6 +3895,9 @@ initGenerateDataClientSide(PGconn *con)
38943895
exit(1);
38953896
}
38963897

3898+
if (CancelRequested)
3899+
break;
3900+
38973901
/*
38983902
* If we want to stick with the original logging, print a message each
38993903
* 100k inserted rows.
@@ -4109,6 +4113,9 @@ runInitSteps(const char *initialize_steps)
41094113
if ((con = doConnect()) == NULL)
41104114
exit(1);
41114115

4116+
setup_cancel_handler(NULL);
4117+
SetCancelConn(con);
4118+
41124119
for (step = initialize_steps; *step != '\0'; step++)
41134120
{
41144121
instr_time start;
@@ -4176,6 +4183,7 @@ runInitSteps(const char *initialize_steps)
41764183
}
41774184

41784185
fprintf(stderr, "done in %.2f s (%s).\n", run_time, stats.data);
4186+
ResetCancelConn();
41794187
PQfinish(con);
41804188
termPQExpBuffer(&stats);
41814189
}

0 commit comments

Comments
 (0)