PG14中的idle_session_timeout

简介: PG14中的idle_session_timeout

PG14中的idle_session_timeout


新添加的配置参数idle_session_timeout和idle_in_transaction_session_timeout类似,一个客户端等待查询时间太长,此时可通过这个时间超时杀死该客户端会话。但是该参数不在事务中生效。关于邮件列表讨论:https://postgr.es/m/763A0689-F189-459E-946F-F0EC4458980B@hotmail.com。描述很清晰。该参数信息:


    $ SELECT * FROMpg_settings WHERE name = 'idle_session_timeout' \gx
    -[ RECORD 1]---+-------------------------------------------------------------------------------
    name            | idle_session_timeout
    setting         | 0
    unit            | ms
    category        | Client Connection Defaults /Statement Behavior
    short_desc      | Sets the maximum allowed idle TIMEBETWEEN queries, WHEN NOT IN a TRANSACTION.
    extra_desc      | A VALUE OF 0 turns off the timeout.
    context         | USER
    vartype         | INTEGER
    SOURCE          | DEFAULT
    min_val         | 0
    max_val         | 2147483647
    enumvals        | [NULL]
    boot_val        | 0
    reset_val       | 0
    sourcefile      | [NULL]
    sourceline      | [NULL]
    pending_restart | f
    //设置该参数后:
    $ SELECT pg_reload_conf();
     pg_reload_conf
    ----------------
     t
    (1 ROW)
    $ SELECT 1;
     ?COLUMN?
    ----------
            1
    (1 ROW)
    $ SELECT * FROMpg_settings WHERE name = 'idle_session_timeout' \gx
    -[ RECORD 1 ]---+-------------------------------------------------------------------------------
    name            | idle_session_timeout
    setting         | 10000
    unit            | ms
    category        | Client Connection Defaults /Statement Behavior
    short_desc      | Sets the maximum allowed idle TIMEBETWEEN queries, WHEN NOT IN a TRANSACTION.
    extra_desc      | A VALUE OF 0 turns offthe timeout.
    context         | USER
    vartype         | INTEGER
    SOURCE         | configuration file
    min_val         | 0
    max_val         | 2147483647
    enumvals        | [NULL]
    boot_val        | 0
    reset_val       | 10000
    sourcefile      | /home/pgdba/DATA/postgresql.auto.conf
    sourceline      | 3
    pending_restart | f

    之后,不做任何操作,10s后,错误日志中可以看到:



    2021-01-1211:33:38.892 CET depesz@depesz 61973 [local] LOG:  duration: 2.827 ms  statement: select * from pg_settings wherename = 'idle_session_timeout'
    2021-01-1211:33:48.892 CET depesz@depesz 61973 [local] FATAL:  terminating connection due to idle-sessiontimeout
    2021-01-1211:33:48.892 CET depesz@depesz 61973 [local] LOG:  disconnection: session time: 0:01:59.743user=depesz database=depesz host=[local]

    Psql会话不会看到任何东西,当执行一个查询时会看到断开:

      $ SELECT 1;
      FATAL:  terminating connection due TO idle-SESSIONtimeout
      server closed theconnection unexpectedly
              This probably means the server TERMINATEDabnormally
              BEFORE OR whileprocessing the request.
      The connection TOthe server was lost. Attempting reset: Succeeded.

      为了增加说服力,在事务中操作:

        $ BEGIN;
        BEGIN
        *$ SELECT now();
                      now              
        -------------------------------
         2021-01-12 11:36:32.131091+01
        (1 ROW)
        ...
        *$ SELECT clock_timestamp(), now(), clock_timestamp() - now();
                clock_timestamp        |              now              |    ?COLUMN?     
        -------------------------------+-------------------------------+-----------------
         2021-01-12 11:37:23.368718+01 | 2021-01-12 11:36:32.131091+01 | 00:00:51.237627
        (1 ROW)

         

        正如所见,50s后还没断开。该值最大值未2147483647,单位毫秒,意味着最大空闲会话超时可以时24天、20小时、31分钟和23秒,有足够长时间检测空闲连接。


        原文


        https://www.depesz.com/2021/01/12/waiting-for-postgresql-14-add-idle_session_timeout/

        目录
        相关文章
        |
        6月前
        |
        关系型数据库 MySQL Java
        MySQL中wait_timeout与interactive_timeout详解
        MySQL中wait_timeout与interactive_timeout详解
        1450 0
        |
        关系型数据库 MySQL 数据库
        MySQL报错:Lock wait timeout exceeded; try restarting transaction
        MySQL报错:Lock wait timeout exceeded; try restarting transaction
        609 0
        |
        SQL 关系型数据库 MySQL
        MySQL报错:1205 Lock wait timeout exceeded; try restarting transaction处理
        MySQL报错:1205 Lock wait timeout exceeded; try restarting transaction处理
        318 0
        |
        SQL 关系型数据库 MySQL
        mysql Lock wait timeout exceeded; try restarting transaction解决方案
        在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
        167 0
        |
        关系型数据库 MySQL
        jdbs学习中的错误总结1(MySql Lock wait timeout exceeded)
        错误原因: 两个事物之间出现死锁,导致另外一个事物超时 某一种表频繁被锁表,导致其他事物无法拿到锁,导致事物超时
        jdbs学习中的错误总结1(MySql Lock wait timeout exceeded)
        |
        关系型数据库 MySQL 数据库
        MySQL - Lock wait timeout exceeded; try restarting transaction
        MySQL - Lock wait timeout exceeded; try restarting transaction
        460 0
        MySQL - Lock wait timeout exceeded; try restarting transaction
        |
        关系型数据库 MySQL
        [Err] 1205 - Lock wait timeout exceeded; try restarting transaction Mysql 报错
        Mysql 报错: [Err] 1205 - Lock wait timeout exceeded; try restarting transaction
        483 0
        |
        SQL Java 关系型数据库
        MySQL之wait_timeout和interactive_timeout参数
        MySQL支持的最大连接数是有上限的,如果你的MySQL Server有大量的闲置连接,不仅会白白消耗内存,而且如果连接一直在累加而不断开,最终会达到MySQL Server的连接上限数,报‘to many connections’错误。
        4865 0
        |
        关系型数据库 MySQL 测试技术
        【MySQL】浅析interactive_timeout和wait_timeout
        一 前言   这篇文章源于自己一个无知的提问,作为一个DBA 老鸟,实在汗颜 。如图,修改wait_timeout参数之后 并没有及时生效,于是乎去跑到技术支持群里问了。
        5022 1