postgresql更改配置生效问题

补充:如何确定psql配置文件的路径

①切换至psql用户,此处为thunisoft。

    ②确定路径方法很多,此处介绍常用的几种。

<1>ps –ef  |grep base 输出结果中 –D后几位数据目录。

 

 

      <2>切换中thunisoft用户后默认在thunisoft的家目录/home/thunisoft下。使用公司提供的安装包,自动安装psql时会在家目录下自动生成启动或停止脚本。

 

    使用命令 more startup.sh或stop.sh。就可看到如下内容。其中-D指明了数据目录。

 

    <3>第三种一步到位的方法:直接使用工具连接数据库执行。可以看到sourcefile对应了两个不同的配置文件。分别是postgresql.conf和postgresql.auto.conf,后者优先级更高。在更改配置前需要在数据库总先确认其对应的配置文件是哪一个。例如我们自动安装的abase会有postgresql.auto.conf,而max_connections就在此配置。

 

一:如何使修改的配置项生效?

1、在查看postgresql.conf配置文件可以看到,port配置后有# (change requires restart),代表使用重载配置并不能使配置生效,需要重启数据库。

 

那么是否所有的配置都需要重启才生效?该如何确定何种操作才能使配置生效?

 

2、配置如何生效在pg_settings中可以查找,context共有七个不同字段分别如下。

 

context

操作

backend  

 可以在postgresql.conf中对这些设置进行更改,而无需重新启动服务器。 但新的配置值只会出现在这之后的连接中,在已有的连接中,这些值不会改变。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

user 

该类参数表示,普通用户可以通过set命令来更改参数的配置值。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

internal 

该类参数是内部参数,也就是说,不可以进行修改,除非重新initdb。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

postmaster 

该类参数更改配置项后,需要重启PostgreSQL实例才能生效。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

superuser 

该类参数可以由超级用户来改变,改变时,只会影响到自身的session,不会影响到其他的用户。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

sighup 

在postgresql.conf配置文件中更改这种类型的参数无须重启实例,只需要向postmaster进程发送一 个SIGHUP信号,让其重新读取配置文件即可。postmaster进程收到信号后,也会向其他子进程发送SIGHUP信号, 让新的参数值在其他子进程中也生效。该类参数区别于backend类参数。                                                                                                                                                                                                                                                                                                                                                                               

superuser-backend

 该类参数可以由超级用户来改变,可以在postgresql.conf中对这些设置进行更改,而无需 重新启动服务器。但新的配置值只会出现在这之后的连接中,在已有的连接中,这些值不会改变。                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

 

 

 

 

补充:

1、sighup即不重启服务器直接重载配置即可,重载配置的方法如下

①执行命令:pg_ctl reload [-D DATADIRT]

②在数据库中使用sql:select pg_reload_conf();

2、postmaster。需要重启数据库。

例如修改max_connections(最大连接数)

 

posted on 2019-07-09 14:38  HowOldAreYou  阅读(4133)  评论(0编辑  收藏  举报

导航