mirror of https://github.com/postgres/postgres
This commit adds timeout that is expected to be used as a prevention of long-running queries. Any session within the transaction will be terminated after spanning longer than this timeout. However, this timeout is not applied to prepared transactions. Only transactions with user connections are affected. Discussion: https://postgr.es/m/CAAhFRxiQsRs2Eq5kCo9nXE3HTugsAAJdSQSmxncivebAxdmBjQ%40mail.gmail.com Author: Andrey Borodin <amborodin@acm.org> Author: Japin Li <japinli@hotmail.com> Author: Junwang Zhao <zhjwpku@gmail.com> Reviewed-by: Nikolay Samokhvalov <samokhvalov@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com> Reviewed-by: bt23nguyent <bt23nguyent@oss.nttdata.com> Reviewed-by: Yuhang Qiu <iamqyh@gmail.com>pull/157/head
parent
5c9f2f9398
commit
51efe38cb9
@ -0,0 +1,69 @@ |
||||
Parsed test spec with 3 sessions |
||||
|
||||
starting permutation: s7_begin s7_sleep s7_commit_and_chain s7_sleep s7_check s7_abort |
||||
step s7_begin: |
||||
BEGIN ISOLATION LEVEL READ COMMITTED; |
||||
SET transaction_timeout = '1s'; |
||||
|
||||
step s7_sleep: SELECT pg_sleep(0.6); |
||||
pg_sleep |
||||
-------- |
||||
|
||||
(1 row) |
||||
|
||||
step s7_commit_and_chain: COMMIT AND CHAIN; |
||||
step s7_sleep: SELECT pg_sleep(0.6); |
||||
pg_sleep |
||||
-------- |
||||
|
||||
(1 row) |
||||
|
||||
step s7_check: SELECT count(*) FROM pg_stat_activity WHERE application_name = 'isolation/timeouts/s7'; |
||||
count |
||||
----- |
||||
0 |
||||
(1 row) |
||||
|
||||
step s7_abort: ABORT; |
||||
|
||||
starting permutation: s8_begin s8_sleep s8_select_1 s8_check checker_sleep checker_sleep s8_check |
||||
step s8_begin: |
||||
BEGIN ISOLATION LEVEL READ COMMITTED; |
||||
SET transaction_timeout = '900ms'; |
||||
|
||||
step s8_sleep: SELECT pg_sleep(0.6); |
||||
pg_sleep |
||||
-------- |
||||
|
||||
(1 row) |
||||
|
||||
step s8_select_1: SELECT 1; |
||||
?column? |
||||
-------- |
||||
1 |
||||
(1 row) |
||||
|
||||
step s8_check: SELECT count(*) FROM pg_stat_activity WHERE application_name = 'isolation/timeouts/s8'; |
||||
count |
||||
----- |
||||
0 |
||||
(1 row) |
||||
|
||||
step checker_sleep: SELECT pg_sleep(0.3); |
||||
pg_sleep |
||||
-------- |
||||
|
||||
(1 row) |
||||
|
||||
step checker_sleep: SELECT pg_sleep(0.3); |
||||
pg_sleep |
||||
-------- |
||||
|
||||
(1 row) |
||||
|
||||
step s8_check: SELECT count(*) FROM pg_stat_activity WHERE application_name = 'isolation/timeouts/s8'; |
||||
count |
||||
----- |
||||
0 |
||||
(1 row) |
||||
|
@ -0,0 +1,35 @@ |
||||
# Tests for transaction timeout that require long wait times |
||||
|
||||
session s7 |
||||
step s7_begin |
||||
{ |
||||
BEGIN ISOLATION LEVEL READ COMMITTED; |
||||
SET transaction_timeout = '1s'; |
||||
} |
||||
step s7_commit_and_chain { COMMIT AND CHAIN; } |
||||
step s7_sleep { SELECT pg_sleep(0.6); } |
||||
step s7_abort { ABORT; } |
||||
|
||||
session s8 |
||||
step s8_begin |
||||
{ |
||||
BEGIN ISOLATION LEVEL READ COMMITTED; |
||||
SET transaction_timeout = '900ms'; |
||||
} |
||||
# to test that quick query does not restart transaction_timeout |
||||
step s8_select_1 { SELECT 1; } |
||||
step s8_sleep { SELECT pg_sleep(0.6); } |
||||
|
||||
session checker |
||||
step checker_sleep { SELECT pg_sleep(0.3); } |
||||
step s7_check { SELECT count(*) FROM pg_stat_activity WHERE application_name = 'isolation/timeouts/s7'; } |
||||
step s8_check { SELECT count(*) FROM pg_stat_activity WHERE application_name = 'isolation/timeouts/s8'; } |
||||
|
||||
# COMMIT AND CHAIN must restart transaction timeout |
||||
permutation s7_begin s7_sleep s7_commit_and_chain s7_sleep s7_check s7_abort |
||||
# transaction timeout expires in presence of query flow, session s7 FATAL-out |
||||
# this relatevely long sleeps are picked to ensure 300ms gap between check and timeouts firing |
||||
# expected flow: timeouts is scheduled after s8_begin and fires approximately after checker_sleep (300ms before check) |
||||
# possible buggy flow: timeout is schedules after s8_select_1 and fires 300ms after s8_check |
||||
# to ensure this 300ms gap we need minimum transaction_timeout of 300ms |
||||
permutation s8_begin s8_sleep s8_select_1 s8_check checker_sleep checker_sleep s8_check |
Loading…
Reference in new issue