postgresql參數的設置


#服務配置文件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文件

 

 

postgresql參數的設置

 +

 

set shared_buffers='15GB';

 

  1. [postgres@fnddb data]$ cat postgresql.auto.conf
  2. # Do not edit this file manually!
  3.   # It will be overwritten by the ALTER SYSTEM command.

#如何讓剛修改的配置文件生效.
服務器進程收到SIGHUP信號,就會觸發讀取這兩個配置文件.並且會把此信號傳播到其他運行中的服務進程去.
pg自帶的重載配置文件功能如下:

  1.   [postgres@fnddb data]$ pg_ctl reload
  2.   server signaled
  3.   [postgres@fnddb data]$ psql
  4.   psql ( 9.4.0)
  5.   Type "help" for help.
  6.   
  7.   postgres= # select pg_reload_conf();
  8.   pg_reload_conf
  9.   ----------------
  10.   t
  11.  
    ( 1 row)

#通過sql來修改參數配置 不是所有的參數都可以在數據庫運行的時候進行修改

###數據庫級別參數設置###

  1.   postgres= # create user u01 password 'postgres';
  2.   CREATE ROLE
  3.   postgres= # create database db01 owner u01;
  4.   CREATE DATABASE
  5.   postgres= # alter database postgres set enable_indexscan=off;
  6.   ALTER DATABASE
  7.   postgres= # \d pg_settings
  8.   View "pg_catalog.pg_settings"
  9.   Column | Type | Modifiers
  10.   ------------+---------+-----------
  11.   name | text |
  12.   ......
  13.   postgres= # \x
  14.   Expanded display is on.
  15.   postgres= # select * from pg_settings where name='enable_indexscan';
  16.   -[ RECORD 1 ]----------------------------------------------
  17.   name | enable_indexscan
  18.   setting | off
  19.   ......

換個用戶

  1.   postgres= # \c postgres u01
  2.   You are now connected to database "postgres" as user "u01".
  3.   postgres= # \x
  4.   Expanded display is off.
  5.   postgres=> select current_setting('enable_indexscan');
  6.   current_setting
  7.   -----------------
  8.   off
  9.   ( 1 row)

切換到db01數據庫去

  1.   postgres=> \c db01
  2.   You are now connected to database "db01" as user "u01".
  3.   db01=> select current_setting('enable_indexscan');
  4.   current_setting
  5.   -----------------
  6.   on
  7.   ( 1 row)

###用戶級別的參數設置###

  1.   db01=> \c
  2.   You are now connected to database "db01" as user "u01".
  3.   db01=> select current_setting('enable_indexscan');
  4.   current_setting
  5.   -----------------
  6.   on
  7.   ( 1 row)
  8.   
  9.   db01=> \c postgres
  10.   You are now connected to database "postgres" as user "u01".
  11.   postgres=> select current_setting('enable_indexscan');
  12.   current_setting
  13.   -----------------
  14.   off
  15.   ( 1 row)
  16.   
  17.   postgres=> alter role u01 set enable_indexscan=off;
  18.   ALTER ROLE
  19.   postgres=> \c db01
  20.   You are now connected to database "db01" as user "u01".
  21.   db01=> select current_setting('enable_indexscan');
  22.   current_setting
  23.   -----------------
  24.   off
  25.   ( 1 row)

###會話級別的參數設置###

  1.   db01=> set enable_indexscan=off;
  2.   SET
  3.   db01=> select current_setting('enable_indexscan');
  4.   current_setting
  5.   -----------------
  6.   off
  7.   ( 1 row)
  8.   
  9.   db01=> \c
  10.   You are now connected to database "db01" as user "u01".
  11.   db01=> select current_setting('enable_indexscan');
  12.   current_setting
  13.   -----------------
  14.   on
  15.   ( 1 row)

###可以通過update pg_setting 來設置會話級參數

  1.   db01=> update pg_settings set setting='on' where name = 'enable_indexscan';
  2.   -[ RECORD 1 ]--
  3.   set_config | on
  4.   
  5.   UPDATE 0
  6.   db01=> select * from pg_settings where name='enable_indexscan';
  7.   -[ RECORD 1 ]----------------------------------------------
  8.   name | enable_indexscan
  9.   setting | on
  10.   ......

#參數還原

  1.   db01=> set enable_indexscan to default;
  2.   SET
  3.   db01=> alter role u01 set enable_indexscan to default;
  4.   ALTER ROLE
  5.   db01=> alter database db01 set enable_indexscan to default;
  6.   ALTER DATABASE

#結論:

  1. ALTER DATABASE --影響范圍是數據庫級別
  2. ALTER ROLE --影響范圍是用戶級別
  3. SET --影響范圍是會話級別
  4. pg_settings,current_setting 查看的都是會話級別的

優先級: 會話級別 -> 用戶級別 -> 數據庫級別


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM