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

Commit2b2bacd

Browse files
committed
Reset statement_timeout between queries of a multi-query string.
Historically, we started the timer (if StatementTimeout > 0) at thebeginning of a simple-Query message and usually let it run until theend, so that the timeout limit applied to the entire query string,and intra-string changes of the statement_timeout GUC had no effect.But, confusingly, a COMMIT within the string would reset the stateand allow a fresh timeout cycle to start with the current setting.Commitf8e5f15 changed the behavior of statement_timeout for extendedquery protocol, and as an apparently-unintended side effect, a change inthe statement_timeout GUC during a multi-statement simple-Query messagemight have an effect immediately --- but only if it was going from"disabled" to "enabled".This is all pretty confusing, not to mention completely undocumented.Let's change things so that the timeout is always reset between queriesof a multi-query string, whether they're transaction control commandsor not. Thus the active timeout setting is applied to each query inthe string, separately. This costs a few more cycles if statement_timeoutis active, but it provides much more intuitive behavior, especially if onechanges statement_timeout in one of the queries of the string.Also, add something to the documentation to explain all this.Per bug #16035 from Raj Mohite. Although this is a bug fix, I'm hesitantto back-patch it; conceivably somebody has worked out the old behaviorand is depending on it. (But note that this change should make thebehavior less restrictive in most cases, since the timeout will nowbe applied to shorter segments of code.)Discussion:https://postgr.es/m/16035-456e6e69ebfd4374@postgresql.org
1 parentc114229 commit2b2bacd

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7592,11 +7592,24 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
75927592
</term>
75937593
<listitem>
75947594
<para>
7595-
Abort any statement that takes more than the specified duration
7596-
(defaults to milliseconds), starting from the time the command arrives at the server
7597-
from the client. If <varname>log_min_error_statement</varname> is set to
7598-
<literal>ERROR</literal> or lower, the statement that timed out will also be
7599-
logged. A value of zero (the default) turns this off.
7595+
Abort any statement that takes more than the specified duration.
7596+
If <varname>log_min_error_statement</varname> is set
7597+
to <literal>ERROR</literal> or lower, the statement that timed out
7598+
will also be logged.
7599+
If the value is specified without units, it is taken as milliseconds.
7600+
A value of zero (the default) disables the timeout.
7601+
</para>
7602+
7603+
<para>
7604+
The timeout is measured from the time a command arrives at the
7605+
server until it is completed by the server. If multiple SQL
7606+
statements appear in a single simple-Query message, the timeout
7607+
is applied to each statement separately.
7608+
(<productname>PostgreSQL</productname> versions before 13 usually
7609+
treated the timeout as applying to the whole query string.)
7610+
In extended query protocol, the timeout starts running when any
7611+
query-related message (Parse, Bind, Execute, Describe) arrives, and
7612+
it is cancelled by completion of an Execute or Sync message.
76007613
</para>
76017614

76027615
<para>

‎src/backend/tcop/postgres.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,13 @@ exec_simple_query(const char *query_string)
12701270
* those that start or end a transaction block.
12711271
*/
12721272
CommandCounterIncrement();
1273+
1274+
/*
1275+
* Disable statement timeout between queries of a multi-query
1276+
* string, so that the timeout applies separately to each query.
1277+
* (Our next loop iteration will start a fresh timeout.)
1278+
*/
1279+
disable_statement_timeout();
12731280
}
12741281

12751282
/*
@@ -2135,7 +2142,10 @@ exec_execute_message(const char *portal_name, long max_rows)
21352142
*/
21362143
CommandCounterIncrement();
21372144

2138-
/* full command has been executed, reset timeout */
2145+
/*
2146+
* Disable statement timeout whenever we complete an Execute
2147+
* message. The next protocol message will start a fresh timeout.
2148+
*/
21392149
disable_statement_timeout();
21402150
}
21412151

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp