idle_in_transaction_session_timeout
一个配置参数,用于确定具有开放事务的会话将被终止的时间长度。
idle_in_transaction_session_timeout 是一个 配置参数,用于确定具有开放事务的会话将被终止的时间长度。默认情况下它是禁用的。
idle_in_transaction_session_timeout 于 PostgreSQL 9.6 中添加。
默认值
idle_in_transaction_session_timeout 的默认值为:0(禁用)。
按 PostgreSQL 版本详细信息
idle_in_transaction_session_timeout (PostgreSQL 19)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置在事务中,查询之间的最大允许空闲时间。 |
| 扩展描述 |
0 表示禁用超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 18)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置在事务中,查询之间的最大允许空闲时间。 |
| 扩展描述 |
0 表示禁用超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 17)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置在事务中,查询之间的最大允许空闲时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 16)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置在事务中,查询之间的最大允许空闲时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 15)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置在事务中,查询之间的最大允许空闲时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 14)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置在事务中,查询之间的最大允许空闲时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 13)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置任何空闲事务的最大允许持续时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 12)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置任何空闲事务的最大允许持续时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 11)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置任何空闲事务的最大允许持续时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 10)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置任何空闲事务的最大允许持续时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
idle_in_transaction_session_timeout (PostgreSQL 9.6)
| 设置 |
0 |
| 单位 |
毫秒 |
| 类别 |
客户端连接默认值 / 语句行为 |
| 简短描述 |
设置任何空闲事务的最大允许持续时间。 |
| 扩展描述 |
值为 0 将关闭超时。 |
| 上下文 |
user |
| 变量类型 |
整数 |
| 来源 |
默认 |
| 最小值 |
0 |
| 最大值 |
2147483647 |
| 枚举值 |
|
| 启动值 |
0 |
| 重置值 |
0 |
| 源文件 |
|
| 源行 |
|
| 需要重启 |
false |
文档:idle_in_transaction_session_timeout
变更历史
源代码
GUC 变量在 src/backend/storage/lmgr/proc.c
int IdleInTransactionSessionTimeout = 0;
GUC 配置在 src/backend/utils/misc/guc.c
{
{"idle_in_transaction_session_timeout", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("Sets the maximum allowed duration of any idling transaction."),
gettext_noop("A value of 0 turns off the timeout."),
GUC_UNIT_MS
},
&IdleInTransactionSessionTimeout,
0, 0, INT_MAX,
NULL, NULL, NULL
},
超时在 PostgresMain() 中启动和执行(src/backend/tcop/postgres.c)。
示例
演示 idle_in_transaction_session_timeout 的效果,设置了一个不切实际的短时间 5s
postgres=# SET idle_in_transaction_session_timeout = '5s';
SET
postgres=# SHOW idle_in_transaction_session_timeout;
idle_in_transaction_session_timeout
-------------------------------------
5s
(1 row)
postgres=# SELECT clock_timestamp();
clock_timestamp
----------------------------
2019-08-06 16:32:44.603+01
(1 row)
postgres=# BEGIN ;
BEGIN
...空闲至少 5 秒...
postgres=*# SELECT 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.
The connection to the server was lost. Attempting reset: Succeeded.
postgres=# SELECT clock_timestamp();
clock_timestamp
------------------------------
2019-08-06 16:32:52.92625+01
(1 row)
服务器的日志文件中会出现类似以下的条目
[2019-08-06 16:32:50 CET] psql postgres postgres FATAL: 25P03: terminating connection due to idle-in-transaction timeout