背景
如果会话在事务中停留的时间过长,则允许自动终止空闲会话。可以由配置参数idle_in_transaction_session_timeout 事务处于空闲状态的时长,它有助于防止被遗忘的交易事务,避免长期持有锁,防止vacuum清理时间很长。
而且对于长时间不释放的连接会话,它所占用的本地内存也不会释放。所以,如果这类会话很多就会对服务器内存造成耗尽的风险。
实验
idle_in_transaction_session_timeout = 10000,参数单位为毫秒,这里设置 idle in transaction 空闲事务超时时间为 10 秒。
开启会话一:
test=# begin;
BEGIN
test=# select 2;
?column?
----------
2
(1 row)
开启会话二:
select * from pg_stat_activity where pid<>pg_backend_pid();
datid | 16052
datname | test
pid | 13447
usesysid | 10
usename | system
application_name | kingbase_*&+_
client_addr |
client_hostname |
client_port | -1
backend_start | 2022-10-18 11:04:31.894706+08
xact_start | 2022-10-18 11:06:48.877390+08
query_start | 2022-10-18 11:06:56.214833+08
state_change | 2022-10-18 11:06:56.214963+08
wait_event_type | Client
wait_event | ClientRead
state | idle in transaction
backend_xid |
backend_xmin |
query | select 2;
backend_type | client backend
过10秒钟以后,就查不到这个事务了,再回到会话1执行某个查询会看到:
FATAL: terminating connection due to idle-in-transaction timeout
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
You have mail in /var/spool/mail/kingbase
这就说明参数生效了,超过10S的空闲事务会话超时中断。
数据库日志可以查看到:
2022-10-18 11:17:28.940 CST,"system","test",13447,"[local]",634e1ab2.4b42,1,"idle in transaction",2022-10-18 11:17:06 CST,10/324,0,FATAL,25P03,"terminating connection due to idle-in-transaction timeout",,,,,,,,,"kingbase_*&+_"
13447进程连接超时被中断。
总结:
以上演示了参数idle_in_transaction_session_timeout参数的功能。由此引申出另外一个参数,client_idle_timeout,这两个参数的区别在于client_idle_timeout规定了空闲会话超时中断时间,它不存在于事务里,默认是0,表示关闭。两个参数应该根据实际应用情况配合使用。
标签:10,transaction,V8R6,会话,idle,timeout,超时,KingbaseES,backend From: https://www.cnblogs.com/kingbase/p/16854926.html