pg_reload_conf()

一个系统函数,指示 PostgreSQL 重新加载其配置

pg_reload_conf() 是一个系统函数,通过发送 SIGHUP 信号来指示 PostgreSQL 重新加载其配置。

pg_reload_conf() 函数添加于 PostgreSQL 8.1

用法

pg_reload_conf() → boolean

请注意,pg_reload_conf() 返回的布尔值仅表示 PostgreSQL 是否能够成功收到信号,而不是配置是否已成功重新加载。

查询 pg_file_settingspg_hba_file_rules 视图,以检查 postgresql.confpg_hba.conf 文件中可能存在的错误。

替代方案

您还可以通过以下任一方法指示 PostgreSQL 重新加载其配置:

  • 直接向 postmaster 进程发送 SIGHUP 信号
  • 执行 pg_ctl reload 命令

当然,完全重启 PostgreSQL 实例也会导致读取新的配置。

变更历史

示例

关于 pg_reload_conf() 的基本用法示例

postgres=# SELECT pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

使用无效配置项执行 pg_reload_conf()

postgres=# SELECT * FROM pg_file_settings WHERE applied IS FALSE;
           sourcefile           | sourceline | seqno | name | setting | applied |            error
--------------------------------+------------+-------+------+---------+---------+------------------------------
 /var/lib/pgsql/postgresql.conf |          3 |    22 | port | foo     | f       | setting could not be applied
(1 row)

postgres=# SELECT pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

在这种情况下,您将在 PostgreSQL 日志文件中看到类似以下的错误消息:

[2021-04-14 09:02:13 UTC]    LOG:  00000: received SIGHUP, reloading configuration files
[2021-04-14 09:02:13 UTC]    LOG:  22023: invalid value for parameter "port": "foo"
[2021-04-14 09:02:13 UTC]    LOG:  F0000: configuration file "/var/lib/pgsql/postgresql.conf" contains errors; unaffected changes were applied

分类

配置, 管理/行政, 系统函数

另请参阅

pg_conf_load_time(), pg_file_settings, pg_hba_file_rules, pg_ctl

反馈

有关“pg_reload_conf()”的任何评论、建议或更正,请点击 此处提交。