postgres=# SELECT * FROM pg_settings WHERE name = 'transaction_timeout' \gx -[ RECORD 1 ]---+-------------------------------------------------------------------------------------------- name | transaction_timeout setting | 0 unit | ms category | Client Connection Defaults / Statement Behavior short_desc | Sets the maximum allowed time in a transaction with a session (not a prepared transaction). extra_desc | A value of 0 turns off the timeout. context | user vartype | integer source | default min_val | 0 max_val | 2147483647 enumvals | boot_val | 0 reset_val | 0 sourcefile | sourceline | pending_restart | f
接着我们连接数据库并尝试设置 transaction_timeout 的值。
1 2 3 4 5 6 7 8 9 10 11 12
postgres=# SET transaction_timeout to '10s'; SET postgres=# BEGIN; BEGIN postgres=*# SELECT pg_sleep(20); FATAL: terminating connection due to 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. postgres=# \! cat log | grep timeout 2024-02-18 15:46:37.018 CST [87421] FATAL: terminating connection due to transaction timeout