我经常编辑pg_hda.conf文件,我想知道是否有一种方法可以确保我刚刚写的内容是正确的。
目前我使用测试服务器来检查我的更改。
就像Apache有其apache2ctl -t
命令一样,Postgres是否有类似的东西?
我经常编辑pg_hda.conf文件,我想知道是否有一种方法可以确保我刚刚写的内容是正确的。
目前我使用测试服务器来检查我的更改。
就像Apache有其apache2ctl -t
命令一样,Postgres是否有类似的东西?
很长时间以来,现在可以检查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)
这表示您的文件是正确的,否则它将失败。
选择 sourcefile, name, sourceline, error from
pg_file_settings where error is not null;
- Keith Brings选择 sourcefile、name、sourceline、error from
pg_file_settings where error is not null;
- Keith Brings