为了防止默认情况下 psql 中的空闲事务,我想我应该idle_in_transaction_session_timeout
在我的.psqlrc
.
这最初有效,但是,当连接被终止并且 psql 自动尝试重新连接时,它不会重新运行.psqlrc
,这意味着在我重新运行SET SESSION idle_in_transaction_timeout
. 出于我的目的,我不想在psqlrc
每次由 psql 重新构建 conn 时手动重新运行命令,尤其是因为我可能会忘记。
.psqrc
有没有办法在 psql 尝试重新建立连接时重新运行?或者,如果连接被终止,是否有一种方法可以完全终止 psql 会话,作为重新运行的强制函数.psqlrc
?
psql版本:14.8
例子:
psql -h localhost -W -U postgres -d postgres
SET
psql (14.8 (Homebrew), server 14.6 (Debian 14.6-1.pgdg110+1))
Type "help" for help.
postgres=# SHOW idle_in_transaction_session_timeout;
idle_in_transaction_session_timeout
-------------------------------------
2s
(1 row)
postgres=# BEGIN;
BEGIN
postgres=*# SELECT * FROM bla;
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.
The connection to the server was lost. Attempting reset: Succeeded.
psql (14.8 (Homebrew), server 14.6 (Debian 14.6-1.pgdg110+1))
postgres=# SHOW idle_in_transaction_session_timeout;
idle_in_transaction_session_timeout
-------------------------------------
0
(1 row)
postgres=#