PostgreSQL 中三个常用的 timeout 参数
最近在浏览 guc_table.c 时注意到 PostgreSQL 有很多与超时相关的参数可供用户设置,在这些参数中,我想介绍三个我认为最常用的参数: statement_timeout: Sets the maximum allowed duration of any statement. idle_in_transaction_session_timeout: Sets the maximum allowed idle time between queries, when in a transaction. idle_session_timeout: Sets the maximum allowed idle time between queries, when not in a transaction. statement_timeout PostgreSQL 中长事务往往会带来一些问题,比如 table bloat(由于旧版本记录不能及时回收)、占用资源(锁、内存)等,因此有些实例会设置一个合理的 statement_timeout 来自动杀死运行时间过长的查询。 postgres=# set session statement_timeout = '10s'; SET postgres=# select pg_sleep(1000); ERROR: canceling statement due to statement timeout postgres=# 但这个参数对于 idle in transaction 的 session 不起作用,比如:...