pg_settings
是一个 系统目录 视图,显示当前会话的 配置设置;此外,它还可以更新,使其在功能上等同于会话本地 SET
命令。
pg_settings
添加于 PostgreSQL 7.3。
按 PostgreSQL 版本定义
pg_settings (PostgreSQL 17)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 16)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 15)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 14)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 13)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 12)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 11)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 10)
View "pg_catalog.pg_settings" Column | Type | Collation | Nullable | Default -----------------+---------+-----------+----------+--------- name | text | | | setting | text | | | unit | text | | | category | text | | | short_desc | text | | | extra_desc | text | | | context | text | | | vartype | text | | | source | text | | | min_val | text | | | max_val | text | | | enumvals | text[] | | | boot_val | text | | | reset_val | text | | | sourcefile | text | | | sourceline | integer | | | pending_restart | boolean | | |
文档: pg_settings
pg_settings (PostgreSQL 9.6)
View "pg_catalog.pg_settings" Column | Type | Modifiers -----------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer | pending_restart | boolean |
文档: pg_settings
pg_settings (PostgreSQL 9.5)
View "pg_catalog.pg_settings" Column | Type | Modifiers -----------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer | pending_restart | boolean |
文档: pg_settings
pg_settings (PostgreSQL 9.4)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer |
文档: pg_settings
pg_settings (PostgreSQL 9.3)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer |
文档: pg_settings
pg_settings (PostgreSQL 9.2)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer |
文档: pg_settings
pg_settings (PostgreSQL 9.1)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer |
文档: pg_settings
pg_settings (PostgreSQL 9.0)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer |
文档: pg_settings
pg_settings (PostgreSQL 8.4)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+---------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | enumvals | text[] | boot_val | text | reset_val | text | sourcefile | text | sourceline | integer | View definition: SELECT a.name, a.setting, a.unit, a.category, a.short_desc, a.extra_desc, a.context, a.vartype, a.source, a.min_val, a.max_val, a.enumvals, a.boot_val, a.reset_val, a.sourcefile, a.sourceline FROM pg_show_all_settings() a(name, setting, unit, category, short_desc, extra_desc, context, vartype, source, min_val, max_val, enumvals, boot_val, reset_val, sourcefile, sourceline); Rules: pg_settings_n AS ON UPDATE TO pg_settings DO INSTEAD NOTHING pg_settings_u AS ON UPDATE TO pg_settings WHERE new.name = old.name DO SELECT set_config(old.name, new.setting, false) AS set_config
文档: pg_settings
pg_settings (PostgreSQL 8.3)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | View definition: SELECT a.name, a.setting, a.unit, a.category, a.short_desc, a.extra_desc, a.context, a.vartype, a.source, a.min_val, a.max_val FROM pg_show_all_settings() a(name text, setting text, unit text, category text, short_desc text, extra_desc text, context text, vartype text, source text, min_val text, max_val text); Rules: pg_settings_n AS ON UPDATE TO pg_settings DO INSTEAD NOTHING pg_settings_u AS ON UPDATE TO pg_settings WHERE new.name = old.name DO SELECT set_config(old.name, new.setting, false) AS set_config
文档: pg_settings
pg_settings (PostgreSQL 8.2)
View "pg_catalog.pg_settings" Column | Type | Modifiers ------------+------+----------- name | text | setting | text | unit | text | category | text | short_desc | text | extra_desc | text | context | text | vartype | text | source | text | min_val | text | max_val | text | View definition: SELECT a.name, a.setting, a.unit, a.category, a.short_desc, a.extra_desc, a.context, a.vartype, a.source, a.min_val, a.max_val FROM pg_show_all_settings() a(name text, setting text, unit text, category text, short_desc text, extra_desc text, context text, vartype text, source text, min_val text, max_val text); Rules: pg_settings_n AS ON UPDATE TO pg_settings DO INSTEAD NOTHING pg_settings_u AS ON UPDATE TO pg_settings WHERE new.name = old.name DO SELECT set_config(old.name, new.setting, false) AS set_config
文档: pg_settings
更改历史记录
- PostgreSQL 9.5
- 添加了列
pending_restart
(提交 a486e357)
- 添加了列
- PostgreSQL 8.4
- PostgreSQL 8.2
- 添加了列
unit
(提交 b517e653)
- 添加了列
- PostgreSQL 8.0
- 添加了以下列 (提交 66989aa2)
category
short_desc
extra_desc
- 添加了以下列 (提交 66989aa2)
- PostgreSQL 7.3
- 添加 (提交 45e25445)
pg_settings
最初通过 contrib 模块 tablefunc
作为函数 show_all_settings()
提供。
源代码
pg_settings
来自内部函数 pg_show_all_settings()
(src/backend/catalog/system_views.sql)
CREATE VIEW pg_settings AS SELECT * FROM pg_show_all_settings() AS A; CREATE RULE pg_settings_u AS ON UPDATE TO pg_settings WHERE new.name = old.name DO SELECT set_config(old.name, new.setting, 'f'); CREATE RULE pg_settings_n AS ON UPDATE TO pg_settings DO INSTEAD NOTHING; GRANT SELECT, UPDATE ON pg_settings TO PUBLIC;
示例
pg_settings
中 port
参数的记录
postgres=# SELECT * FROM pg_settings WHERE name = 'port'; -[ RECORD 1 ]---+----------------------------------------------------- name | port setting | 5433 unit | category | Connections and Authentication / Connection Settings short_desc | Sets the TCP port the server listens on. extra_desc | context | postmaster vartype | integer source | configuration file min_val | 1 max_val | 65535 enumvals | boot_val | 5432 reset_val | 5433 sourcefile | /var/lib/pgsql/postgresql.local.conf sourceline | 3 pending_restart | f
pg_settings
中 log_statement
参数的记录,该参数已在当前会话中修改
postgres=# SET log_statement TO mod; SET postgres=# SELECT * FROM pg_settings WHERE name = 'log_statement'; -[ RECORD 1 ]---+------------------------------------ name | log_statement setting | mod unit | category | Reporting and Logging / What to Log short_desc | Sets the type of statements logged. extra_desc | context | superuser vartype | enum source | session min_val | max_val | enumvals | {none,ddl,mod,all} boot_val | none reset_val | none sourcefile | sourceline | pending_restart | f
直接更新 pg_settings
视图
postgres=# UPDATE pg_settings SET setting = 'all' WHERE name = 'log_statement'; set_config ------------ all (1 row) UPDATE 0
尝试更新无法修改的设置
postgres=# UPDATE pg_settings SET setting = '9999' WHERE name = 'port'; ERROR: parameter "port" cannot be changed without restarting the server
参考文献
- PostgreSQL 文档: pg_settings