首页数据库postgresql 中的几个 timeout参数 用法说明

postgresql 中的几个 timeout参数 用法说明

时间2024-02-29 19:11:03发布访客分类数据库浏览403
导读:收集整理的这篇文章主要介绍了postgresql 中的几个 timeout参数 用法说明,觉得挺不错的,现在分享给大家,也给大家做个参考。 今天整理了下 postgreSQL 几个 ti...
收集整理的这篇文章主要介绍了postgresql 中的几个 timeout参数 用法说明,觉得挺不错的,现在分享给大家,也给大家做个参考。

今天整理了下 postgreSQL 几个 timeout 参数

select version();
                             version                         --------------------------------------------------------------------------------------------------------- PostgreSQL 10.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (red hat 4.4.7-18), 64-bIT(1 row)select *From pg_settings pswhere 1=1and ps.name like '%timeout%';
            name         | setting | unit |              category              |                    short_desc                     |       extra_desc       | context | VARtyPE | source | min_val | max_val  | enumvals | boot_val | reset_val | sourcefile | sourceline | pending_restart -------------------------------------+---------+------+--------------------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------+-----------+---------+---------+---------+------------+----------+----------+-----------+------------+------------+----------------- Archive_timeout           | 0    | s  | Write-Ahead LOG / Archiving                 | Forces a switch to the next WAL file if a new file has not been started within N seconds. |                   | sighup  | integer | default | 0    | 1073741823 |     | 0    | 0     |      |      | f authentication_timeout       | 60   | s  | Connections and Authentication / Security and Authentication | Sets the maximum Allowed time to complete client authentication.             |                   | sighup  | integer | default | 1    | 600    |     | 60    | 60    |      |      | f checkpoint_timeout         | 300   | s  | Write-Ahead Log / Checkpoints                | Sets the maximum time between automatic WAL checkpoints.                 |                   | sighup  | integer | default | 30   | 86400   |     | 300   | 300    |      |      | f deadlock_timeout          | 1000  | ms  | Lock Management                       | Sets the time to wait on a lock before checking for deadlock.               |                   | superuser | integer | default | 1    | 2147483647 |     | 1000   | 1000   |      |      | f  idle_in_transaction_session_timeout | 0    | ms  | Client Connection defaults / statement Behavior       | Sets the maximum allowed duration of any idling transaction.               | A value of 0 turns off the timeout. | user   | integer | default | 0    | 2147483647 |     | 0    | 0     |      |      | f lock_timeout            | 0    | ms  | Client Connection Defaults / Statement Behavior       | Sets the maximum allowed duration of any wait for a lock.                 | A value of 0 turns off the timeout. | user   | integer | default | 0    | 2147483647 |     | 0    | 0     |      |      | f statement_timeout          | 0    | ms  | Client Connection Defaults / Statement Behavior       | Sets the maximum allowed duration of any statement.                    | A value of 0 turns off the timeout. | user   | integer | default | 0    | 2147483647 |     | 0    | 0     |      |      | f wal_receiver_timeout        | 60000  | ms  | Replication / Standby Servers                | Sets the maximum wait time to receive data from the Primary.               |                   | sighup  | integer | default | 0    | 2147483647 |     | 60000  | 60000   |      |      | f wal_sender_timeout         | 60000  | ms  | Replication / Sending Servers                | Sets the maximum time to wait for WAL replication.                    |                   | sighup  | integer | default | 0    | 2147483647 |     | 60000  | 60000   |      |      | f(9 rows)

下面简单介绍下这几个参数

archive_timeout

控制服务器周期性地切换到一个新的 WAL 段文件,通俗的讲,就是定时归档。

authentication_timeout

完成服务器认证的最长时间,如果在这个时间内没有完成认证,服务器将关闭连接。

checkpoint_timeout

自动 WAL 检查点之间的最长时间,增大这个参数会使数据库崩溃后恢复的时间加长。

deadlock_timeout

进行死锁检测之前在一个锁上等待的总时间

idle_in_transaction_session_timeout

空闲事务超时。终止任何已经闲置超过这个参数所指定的时间(以毫秒计)的打开事务的会话。 这使得该会话所持有的任何锁被释放,并且其所持有的连接槽可以被重用, 它也允许只对这个事务可见的元组被清理。

lock_timeout

锁等待超时。语句在试图获取表、索引、行或其他数据库对象上的锁时等到超过指定的毫秒数,该语句将被中止。不推荐在Postgresql.conf中设置。

statement_timeout

控制语句执行时长,单位是ms。超过设定值,该语句将被中止。

不推荐在postgresql.conf中设置,如非要设置,应该设置一个较大值。

wal_receiver_timeout

中止处于非活动状态超过指定毫秒数的复制链接。这对于正在接收的后备服务器检测主服务器崩溃或网络断开有用。设置为0会禁用超时机制。这个参数只能在postgresql.conf文件中或在服务器命令行上设置。默认值是 60 秒。

wal_sender_timeout

中断那些停止活动超过指定毫秒数的复制连接。这对发送服务器检测一个后备机崩溃或网络中断有用。设置为0将禁用该超时机制。这个参数只能在postgresql.conf文件中或在服务器命令行上设置。默认值是 60 秒。

补充:Postgresql数据库修改deadlock_timeout参数

某产品线提出要将Postgresql测试库中 deadlock_timeout 参数 修改为1s

该库平时不在自己手中维护,故实际操作步骤如下

(1)确定数据库安装所属用户

查看下都有哪些账户,可能是postgresql使用的

bash-4.1$ cd /homebash-4.1$ lsaquota.user Enterprisedb lost+found PRouser Puppet

(2)确定数据库安装路径:

bash-4.1$ ps -ef | grep post 查看服务进程,找到应用安装目录 /opt/app/PostgresPlus/9.2AS/

500 1891 1 0 2018 ? 01:01:47 /opt/app/PostgresPlus/9.2AS/bin/edb-postgres -D /DATA/data_utl

(3)切换到 enterprisedb 用户,并登陆数据库

bash-4.1$ su - enterprisedbbash-4.1$ psql -U enterprisedbpsql (9.2.14.31)Type “help” for help.

查看当前该参数配置 3s

edb=# show deadlock_timeout;
    

deadlock_timeout

3s(1 row)

(4)查看该参数

pending_restart —boolean— true if the value has been changed in the configuration file but needs a restart;
     or false otherwise.

即该参数为实时生效型参数

(5)尝试使用

test=# alter System set deadlock_timeout=‘1s';
    

报错如下:

ERROR: syntax error at or near “system”LINE 1: alter system set deadlock_timeout=‘1s';
    

查询到解释:

alter system 命令 只对 9.4以后的版本 的版本有效,

(6)尝试执行

set deadlock_timeout=‘1s'edb=# show deadlock_timeout;
    

显示为1s

但是其余用户登录路,发现该参数依然为 3s

----即该方法为session级别设置,类似于oracle的alter session set

(7) 尝试修改 pg配置文件,进入/DATA/data_utl 路径修改

bash-4.1$ pwd/DATA/data_utlbash-4.1$ lsbase pgbin pg_ident.conf pg_notify pg_stat_tmp pg_twophase postgresql.conf postmaster.optsdbms_pipe pg_clog pg_log pg_serial pg_suBTrans PG_VERSION postgresql.conf.20191119 postmaster.pidglobal pg_hba.conf pg_multixact pg_snapshots pg_tblspc pg_xlog postgresql.conf.bak utlp.sqlvi postgresql.conf

将其中 deadlock_timeout 配置修改为1s

(8)重新加载数据库

bash-4.1$ ./pg_ctl reloadserver signaled

(9)查看该参数已生效

edb=# show deadlock_timeout;
    deadlock_timeout1s(1 row)

退出

edb=# \q

第9步也可通过重启数据库生效

停止指令:

./pg_ctl stop -m fast

启动指令:

./pg_ctl -D /DATA/data_utl start

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。

您可能感兴趣的文章:
  • postgreSql分组统计数据的实现代码
  • Postgresql 存储过程(plpgsql)两层for循环的操作
  • postgresql 循环函数的简单实现操作
  • 浅谈PostgreSQL和SQLServer的一些差异
  • 解决PostgreSQL 执行超时的情况
  • PostgreSQL完成按月累加的操作

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: postgresql 中的几个 timeout参数 用法说明
本文地址: https://pptw.com/jishu/633268.html
c语言怎么统计指定数字的个数 postgresql 循环函数的简单实现操作

游客 回复需填写必要信息