#服务配置文件postgresql.conf [postgres@fnddb data]$ ls -l postgresql.* -rw-------. 1 postgres postgres 88 Feb 4 22:20 postgresql.auto.conf -rw-------. 1 postgres postgres 21253 Feb 5 00:10 postgresql.conf postgresql.conf是默认的服务配置文件.因此大多数的修改参数都是在此文件中修改 postgresql.auto.conf是通过ALTER SYSTEM命令修改的参数,这里的参数值生效会覆盖postgresql.conf文件中的值. 手动不要修改postgresql.auto.conf文件
[postgres@fnddb data]$ cat postgresql.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
#如何让刚修改的配置文件生效.
服务器进程收到SIGHUP信号,就会触发读取这两个配置文件.并且会把此信号传播到其他运行中的服务进程去.
pg自带的重载配置文件功能如下:
[postgres@fnddb data]$ pg_ctl reload
server signaled
[postgres@fnddb data]$ psql
psql (9.4.0)
Type "help" for help.
postgres=# select pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
#通过sql来修改参数配置 不是所有的参数都可以在数据库运行的时候进行修改
###数据库级别参数设置###
postgres=# create user u01 password 'postgres';
CREATE ROLE
postgres=# create database db01 owner u01;
CREATE DATABASE
postgres=# alter database postgres set enable_indexscan=off;
ALTER DATABASE
postgres=# \d pg_settings
View "pg_catalog.pg_settings"
Column | Type | Modifiers
------------+---------+-----------
name | text |
......
postgres=# \x
Expanded display is on.
postgres=# select * from pg_settings where name='enable_indexscan';
-[ RECORD 1 ]----------------------------------------------
name | enable_indexscan
setting | off
......
换个用户
postgres=# \c postgres u01
You are now connected to database "postgres" as user "u01".
postgres=# \x
Expanded display is off.
postgres=> select current_setting('enable_indexscan');
current_setting
-----------------
off
(1 row)
切换到db01数据库去
postgres=> \c db01
You are now connected to database "db01" as user "u01".
db01=> select current_setting('enable_indexscan');
current_setting
-----------------
on
(1 row)
###用户级别的参数设置###
db01=> \c
You are now connected to database "db01" as user "u01".
db01=> select current_setting('enable_indexscan');
current_setting
-----------------
on
(1 row)
db01=> \c postgres
You are now connected to database "postgres" as user "u01".
postgres=> select current_setting('enable_indexscan');
current_setting
-----------------
off
(1 row)
postgres=> alter role u01 set enable_indexscan=off;
ALTER ROLE
postgres=> \c db01
You are now connected to database "db01" as user "u01".
db01=> select current_setting('enable_indexscan');
current_setting
-----------------
off
(1 row)
###会话级别的参数设置###
db01=> set enable_indexscan=off;
SET
db01=> select current_setting('enable_indexscan');
current_setting
-----------------
off
(1 row)
db01=> \c
You are now connected to database "db01" as user "u01".
db01=> select current_setting('enable_indexscan');
current_setting
-----------------
on
(1 row)
###可以通过update pg_setting 来设置会话级参数
db01=> update pg_settings set setting='on' where name = 'enable_indexscan';
-[ RECORD 1 ]--
set_config | on
UPDATE 0
db01=> select * from pg_settings where name='enable_indexscan';
-[ RECORD 1 ]----------------------------------------------
name | enable_indexscan
setting | on
......
#参数还原
db01=> set enable_indexscan to default;
SET
db01=> alter role u01 set enable_indexscan to default;
ALTER ROLE
db01=> alter database db01 set enable_indexscan to default;
ALTER DATABASE
#结论:
- ALTER DATABASE --影响范围是数据库级别
- ALTER ROLE --影响范围是用户级别
- SET --影响范围是会话级别
- pg_settings,current_setting 查看的都是会话级别的
优先级: 会话级别 -> 用户级别 -> 数据库级别
//END