在postgresql.conf中設置 statement_timeout 就可以實現對所有的查詢都能超過指定的時間后就斷開查詢:
會話中使用:
SET statement_timeout = 10000;
SET
test=# SELECT pg_sleep(15);
ERROR: canceling statement due to statement timeout
事務中使用:
begin;
set local statement_time='1000ms';
select count(*) from mytable;
end;
指定數據庫中使用:
ALTER DATABASE mydatabase SET statement_timeout = 60s';
整庫設置超時:單位是ms 下面設置為10秒
vi postgresql.conf
statement_timeout = 10000