Statement timeout behavior in extended queries
Tatsuo Ishii <ishii@sraoss.co.jp>
From: Tatsuo Ishii <ishii@sraoss.co.jp>
To: pgsql-hackers@postgresql.org
Date: 2017-02-22T02:50:44Z
Lists: pgsql-hackers
Attachments
- statement_timeout.diff (text/x-patch) patch
Last year I have proposed an enhancement regarding behavior of the statement timeout in extended queries. https://www.postgresql.org/message-id/20160528.220442.1489791680347556026.t-ishii%40sraoss.co.jp 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. https://github.com/tatsuo-ishii/pgproto (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 'Y' # 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 'S' # Receive response from backend 'Y' # Send terminate message 'X' ---------------------------------------------------------- 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 character. 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 English: http://www.sraoss.co.jp/index_en.php Japanese:http://www.sraoss.co.jp
Commits
-
Rearm statement_timeout after each executed query.
- f8e5f156b30e 11.0 landed