目录
一、参数类型
1、显式:在文件中对参数进行设置
2、隐式:文件中没有设置,使用Postgres的缺省值
二、参数文件
静态参数文件:postgresql.conf
动态参数文件:postgresql.auto.conf
可选参数文件:postgresql.conf.user
读取顺序:postgresql.conf -> postgresql.auto.conf -> postgresql.conf.user
1、查看参数文件路径
默认位置$PGDATA
postgres=# show config_file;
config_file
---------------------------------------
/data/postgresql/data/postgresql.conf
(1 行记录)
2、查看所有的pg参数
可以使用数据字典pg_settings查看数据库参数信息,例如:
postgres=# select name,setting,context from pg_settings limit 10;
name | setting | context
----------------------------+--------------------------------------------+------------
allow_in_place_tablespaces | off | superuser
allow_system_table_mods | off | superuser
application_name | psql | user
archive_cleanup_command | | sighup
archive_command | cp %p /data/postgresql/data/pg_wal/arch/%f | sighup
archive_mode | on | postmaster
archive_timeout | 0 | sighup
array_nulls | on | user
authentication_timeout | 60 | sighup
autovacuum | on | sighup
(10 行记录)
3、修改参数
(1)修改postgresql.conf参数文件
文本文件,使用操作系统编辑器 手动修改(vim);
仅在实例启动期间读取,更改后重启生效。
(2)修改postgresql.auto.conf文件
文本文件,由postgres服务维护;
能够在关闭和启动期间持续进行更改,可以实现自我调整参数值;
支持文本编辑器修改但不推荐;
alter system命令修改的参数保存在该文件
postgres=# \h alter system set
命令: ALTER SYSTEM
描述: 更改服务器的配置参数
语法:
ALTER SYSTEM SET 配置参数 { TO | = } { 值 | '值' | DEFAULT }
ALTER SYSTEM RESET 配置参数
ALTER SYSTEM RESET ALL
URL: https://www.postgresql.org/docs/14/sql-altersystem.html
(3)参数生效条件(context)
可以根据pg_settings表中context的内容来判断参数修改生效的条件
postgres=# select name,setting,context from pg_settings limit 10;
name | setting | context
----------------------------+--------------------------------------------+------------
allow_in_place_tablespaces | off | superuser
allow_system_table_mods | off | superuser
application_name | psql | user
archive_cleanup_command | | sighup
archive_command | cp %p /data/postgresql/data/pg_wal/arch/%f | sighup
archive_mode | on | postmaster
archive_timeout | 0 | sighup
array_nulls | on | user
authentication_timeout | 60 | sighup
autovacuum | on | sighup
(10 行记录)
###
sighup:需要超级管理员修改,reload生效
superuser:用超级管理员可以为普通用户、数据库、超级管理员自己修改。有些参数可以针对用户、数据库、实例。
postmaster:需要超级管理员修改,重启生效
user:普通用户可以修改,立即生效