前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PG生效参数的演进过程

PG生效参数的演进过程

作者头像
bisal
发布2019-12-10 19:01:32
7730
发布2019-12-10 19:01:32
举报

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://cloud.tencent.com/developer/article/1551926

我们用的EDB数据库,其实就是商业版PostgreSQL,用的9.2版本,测试有个需求,需要修改deadlock_timeout参数,但是不知道需不需要重启。

这个参数的含义,并不是重点,从官方手册,可以检索到,

deadlock_timeout (integer)This is the amount of time, in milliseconds, to wait on a lock before checking to see if there is a deadlock condition. The check for deadlock is relatively expensive, so the server doesn't run it every time it waits for a lock. We optimistically assume that deadlocks are not common in production applications and just wait on the lock for a while before checking for a deadlock. Increasing this value reduces the amount of time wasted in needless deadlock checks, but slows down reporting of real deadlock errors. The default is one second (1s), which is probably about the smallest value you would want in practice. On a heavily loaded server you might want to raise it. Ideally the setting should exceed your typical transaction time, so as to improve the odds that a lock will be released before the waiter decides to check for deadlock. Only superusers can change this setting. When log\_lock\_waits is set, this parameter also determines the length of time to wait before a log message is issued about the lock wait. If you are trying to investigate locking delays you might want to set a shorter than normal deadlock\_timeout.

从数据库看,当前deadlock_timeout值是1秒,

代码语言:javascript
复制
edb=# show deadlock_timeout;
 deadlock_timeout 
------------------
 1s
(1 row)

如果执行set指令,确实更改了,

代码语言:javascript
复制
edb=# set deadlock_timeout='2s';
SET

edb=# show deadlock_timeout;        
 deadlock_timeout 
------------------
 2s
(1 row)

但是换个会话,发现值没变,还是1秒,

代码语言:javascript
复制
edb=# show deadlock_timeout;
 deadlock_timeout 
------------------
 1s
(1 row)

这是因为PG中set操作,相当于Oracle中alter session操作,让当前会话生效,退出重登录,或者换个会话,参数值未变,如果在9.5之前,需要永久生效,唯一的做法,就是改postgresql.conf配置文件,

代码语言:javascript
复制
vi postgresql.conf
...
#deadlock_timeout = 1s 改为2s
...

再使用pg_ctl指令,重新加载生效,

代码语言:javascript
复制
-bash-4.1$ pg_ctl reload
server signaled

此时检索参数,值改成了2秒,

代码语言:javascript
复制
edb=# show deadlock_timeout;    
 deadlock_timeout 
------------------
 2s
(1 row)

这种操作其实很不方便,需要改配置文件,重新加载,而且需要show指令,确认更改效果。

从PG 9.5以后,增加了alter system命令,并且在pg_settings视图中增加了pending_restart(boolean)列,该列标识了是否在重启之后才生效,使得修改参数和查看参数是否生效都方便了很多。

alter system语法,

ALTER SYSTEM SET configuration_parameter { TO | = } { value | 'value' | DEFAULT } ALTER SYSTEM RESET configuration_parameter ALTER SYSTEM RESET ALL

例如,检索pg_settings,pending_restart是f,表示不用重启,即可生效,

代码语言:javascript
复制
edb=# select name, unit, context, pending_restart from pg_settings
      where name='deadlock_timeout';        
       name       | setting | unit |  context  | pending_restart |
------------------+---------+------+-----------+------------------
 deadlock_timeout | 1000    | ms   | superuser          f
(1 row)

使用alter system,修改deadlock_timeout值,

代码语言:javascript
复制
edb=# alter system set deadlock_timeout='2s';
ALTER SYSTEM

此时,使用pg_ctl reload或SELECT pg_reload_conf();,就可以生效,

代码语言:javascript
复制
edb=# select pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

通过ALTER SYSTEM配置的参数都会保存在postgresql.auto.conf文件中,因此,需要清除这些配置的时候,只需要一条指令就可以很方便的处理完成,

代码语言:javascript
复制
edb=# alter system reset all;
ALTER SYSTEM

其实各种数据库、各种技术之间,是可以相互借鉴,互相促进的,设计好的地方,吸收进来,取长补短,但之所以滞后,很可能是产品需求有限度的问题,或者技术实现的问题,没毛病。

参考,

https://www.postgresql.org/docs/current/sql-altersystem.html

https://blog.hackroad.com/operations-engineer/linux_server/13212.html

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档