【发布时间】:2013-05-02 08:15:42
【问题描述】:
我经常编辑 pg_hda.conf 文件,我只是想知道是否有办法确保我刚刚写的内容是正确的。
到目前为止,我正在使用测试服务器来检查我的更改。
就像 Apache 有它的 apache2ctl -t 命令一样,Postgres 有类似的东西吗?
【问题讨论】:
标签: postgresql syntax configuration-files
我经常编辑 pg_hda.conf 文件,我只是想知道是否有办法确保我刚刚写的内容是正确的。
到目前为止,我正在使用测试服务器来检查我的更改。
就像 Apache 有它的 apache2ctl -t 命令一样,Postgres 有类似的东西吗?
【问题讨论】:
标签: postgresql syntax configuration-files
好久不见,现在可以检查pg_hba.conf文件了:
select pg_hba_file_rules();
另外,您可以使用 pg_file_settings 视图在 postgresql.conf 中定义错误:
select sourcefile, name,sourceline,error from pg_file_settings where error is not null;
示例输出:
postgres=# select sourcefile, name,sourceline,error from pg_file_settings where error is not null;
sourcefile | name | sourceline | error
----------------------------------------+--------+------------+--------------------------------------
/var/lib/pgsql/11/data/postgresql.conf | lalala | 1 | unrecognized configuration parameter
这里我放了一些不好的东西来检查它是否是真的:)
【讨论】:
没有类似于apache2ctl 的方法。如果你重新加载配置文件并且出现语法错误,PostgreSQL 服务器将在日志中抱怨并拒绝加载新文件。因此,由于语法错误而搞砸的风险很小。 (当然,这不能防止你写出语义错误的东西,但apache2ctl 也不会这样做。)除此之外,在测试服务器中测试更改并拥有一个系统可能是个好主意以受控方式将这些更改传播到生产环境。
【讨论】:
参考:https://dba.stackexchange.com/a/151457/177071
您有另一种方法来测试配置文件是否正确。
进入命令行,输入select pg_reload_conf();
postgres=# select pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
这表明您的文件是正确的。否则会失败。
【讨论】: