diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 886632ff43..c1da75fbab 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -7592,11 +7592,24 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; - Abort any statement that takes more than the specified duration - (defaults to milliseconds), starting from the time the command arrives at the server - from the client. If log_min_error_statement is set to - ERROR or lower, the statement that timed out will also be - logged. A value of zero (the default) turns this off. + Abort any statement that takes more than the specified duration. + If log_min_error_statement is set + to ERROR or lower, the statement that timed out + will also be logged. + If the value is specified without units, it is taken as milliseconds. + A value of zero (the default) disables the timeout. + + + + The timeout is measured from the time a command arrives at the + server until it is completed by the server. If multiple SQL + statements appear in a single simple-Query message, the timeout + is applied to each statement separately. + (PostgreSQL versions before 13 usually + treated the timeout as applying to the whole query string.) + In extended query protocol, the timeout starts running when any + query-related message (Parse, Bind, Execute, Describe) arrives, and + it is cancelled by completion of an Execute or Sync message. diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index e8d8e6f828..1ecaba0d57 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -1270,6 +1270,13 @@ exec_simple_query(const char *query_string) * those that start or end a transaction block. */ CommandCounterIncrement(); + + /* + * Disable statement timeout between queries of a multi-query + * string, so that the timeout applies separately to each query. + * (Our next loop iteration will start a fresh timeout.) + */ + disable_statement_timeout(); } /* @@ -2135,7 +2142,10 @@ exec_execute_message(const char *portal_name, long max_rows) */ CommandCounterIncrement(); - /* full command has been executed, reset timeout */ + /* + * Disable statement timeout whenever we complete an Execute + * message. The next protocol message will start a fresh timeout. + */ disable_statement_timeout(); }