Statement timeout behavior in extended queries

From: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Statement timeout behavior in extended queries
Date: 2017-02-22 02:50:44
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Last year I have proposed an enhancement regarding behavior of the
statement timeout in extended queries.

IMO the current behavior is counter intuitive and I would like to
change it toward PostgreSQL 10.0.

For example, suppose that the timeout is set to 4 seconds and the
first query takes 2 seconds and the second query takes 3 seconds. Then
the statement timeout is triggered if a sync message is sent to
backend after the second query.

Moreover, log_duration or log_min_duration_statement shows that each
query took 2 or 3 seconds of course, which is not very consistent with
the statement timeout IMO.

Attached patch tries to change the behavior, by checking statement
timeout against each phase of an extended query.

To test the patch, I have created a small tool called "pgproto", which
can issue arbitrary sequence of frontend/backend message, reading from a
text file.
(to build the program, you need C compiler and libpq)

A test data is here:
# Test case for statement timeout patch.
'Q' "SET statement_timeout = '4s'"

# Receive response from backend

# Execute statement which takes 3 seconds.
'P' "S1" "SELECT pg_sleep(3)" 0
'B' "" "S1" 0 0 0
'E' "" 0
'C' 'S' "S1"

# Execute statement which takes 2 seconds.
'P' "S2" "SELECT pg_sleep(2)" 0
'B' "" "S2" 0 0 0
'E' "" 0
'C' 'S' "S2"

# Issue Sync message

# Receive response from backend

# Send terminate message

In each row, the first column corresponds to the message type defined
in frontend/backend protocol (except 'Y', which asks pgproto to
collect responses from backend). Each column is separated with a tab

To run the test:

pgproto -f data_file -p port_number -d database_name

With the attached patch, "SELECT pg_sleep(3)" and "SELECT pg_sleep(2)"
does not trigger the statement timeout as expected, while existing
code triggers the statement timeout after the sync message is sent.

Best regards,
Tatsuo Ishii
SRA OSS, Inc. Japan

Attachment Content-Type Size
statement_timeout.diff text/x-patch 4.1 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2017-02-22 03:17:22 Re: "may be unused" warnings for gcc
Previous Message Robert Haas 2017-02-22 02:16:00 Re: Documentation improvements for partitioning