#服務配置文件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文件
+
set shared_buffers='15GB';
-
[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=
-
You are now connected to database "postgres" as user "u01".
-
postgres=
-
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 查看的都是會話級別的
優先級: 會話級別 -> 用戶級別 -> 數據庫級別