From c02aae418527ec6f5178c68e2980e02d36090c42 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 16 Mar 2016 23:18:07 -0400 Subject: [PATCH] Fix "pg_bench -C -M prepared". This didn't work because when we dropped and re-established a database connection, we did not bother to reset session-specific state such as the statements-are-prepared flags. The st->prepared[] array certainly needs to be flushed, and I cleared a couple of other fields as well that couldn't possibly retain meaningful state for a new connection. In passing, fix some bogus comments and strange field order choices. Per report from Robins Tharakan. --- contrib/pgbench/pgbench.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 7498e2fc3f1..c6b4b7512b0 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -201,7 +201,7 @@ typedef struct int state; /* state No. */ int cnt; /* xacts count */ int ecnt; /* error count */ - int listen; /* 0 indicates that an async query has been + int listen; /* 1 indicates that an async query has been * sent */ int sleeping; /* 1 indicates that the client is napping */ int64 until; /* napping until (usec) */ @@ -1115,6 +1115,11 @@ top: } INSTR_TIME_SET_CURRENT(end); INSTR_TIME_ACCUM_DIFF(*conn_time, end, start); + + /* Reset session-local state */ + st->listen = 0; + st->sleeping = 0; + memset(st->prepared, 0, sizeof(st->prepared)); } /* Record transaction start time if logging is enabled */