pg_reload_conf() 是一个系统函数,通过发送 SIGHUP 信号来指示 PostgreSQL 重新加载其配置。
pg_reload_conf() 函数添加于 PostgreSQL 8.1。
用法
pg_reload_conf() → boolean
请注意,pg_reload_conf() 返回的布尔值仅表示 PostgreSQL 是否能够成功收到信号,而不是配置是否已成功重新加载。
查询 pg_file_settings 和 pg_hba_file_rules 视图,以检查 postgresql.conf 和 pg_hba.conf 文件中可能存在的错误。
替代方案
您还可以通过以下任一方法指示 PostgreSQL 重新加载其配置:
- 直接向 postmaster 进程发送
SIGHUP信号 - 执行
pg_ctl reload命令
当然,完全重启 PostgreSQL 实例也会导致读取新的配置。
变更历史
- PostgreSQL 8.1
- 添加(提交 b609695b)
示例
关于 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
参考资料
- PostgreSQL documentation: Server Signaling Functions
