To prevent idle transactions in psql by default, I thought I should just set an aggressive idle_in_transaction_session_timeout
in my .psqlrc
.
This works initially, however, when the connection is killed and psql automatically attempts to re-connect, it doesn't re-run the .psqlrc
, meaning the shell has no longer has this added layer of safety until I re-run the SET SESSION idle_in_transaction_timeout
. For my purposes, I don't want to have to re-run manually re-run the commands in my psqlrc
every time a conn is re-built by psql, especially because I might forget.
Is there a way to re-run the .psqrc
whenever psql attempts to re-establish a connection? Alternatively, is there a way to just completely kill the psql session if the connection is killed, as a forcing function to re-run the .psqlrc
?
psql version: 14.8
Example:
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=#