【问题标题】:How to syntax check PostgreSQL config files?如何语法检查 PostgreSQL 配置文件?
【发布时间】:2013-05-02 08:15:42
【问题描述】:

我经常编辑 pg_hda.conf 文件,我只是想知道是否有办法确保我刚刚写的内容是正确的。

到目前为止,我正在使用测试服务器来检查我的更改。

就像 Apache 有它的 apache2ctl -t 命令一样,Postgres 有类似的东西吗?

【问题讨论】:

    标签: postgresql syntax configuration-files


    【解决方案1】:

    好久不见,现在可以检查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
    

    这里我放了一些不好的东西来检查它是否是真的:)

    【讨论】:

    • 这很有趣。我一找到工作就去看看!
    • 第二个选项对我检查 postgresql.conf 非常有用。谢谢!
    【解决方案2】:

    没有类似于apache2ctl 的方法。如果你重新加载配置文件并且出现语法错误,PostgreSQL 服务器将在日志中抱怨并拒绝加载新文件。因此,由于语法错误而搞砸的风险很小。 (当然,这不能防止你写出语义错误的东西,但apache2ctl 也不会这样做。)除此之外,在测试服务器中测试更改并拥有一个系统可能是个好主意以受控方式将这些更改传播到生产环境。

    【讨论】:

      【解决方案3】:

      参考:https://dba.stackexchange.com/a/151457/177071

      您有另一种方法来测试配置文件是否正确。

      进入命令行,输入select pg_reload_conf();

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

      这表明您的文件是正确的。否则会失败。

      【讨论】:

      • 这不是真的。在结果中使用“t”重新加载conf后,我在postgres日志中有这一行:[9692]LOG:配置文件“/var/lib/pgsql/data/postgresql.conf”包含错误;应用了未受影响的更改
      猜你喜欢
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      相关资源
      最近更新 更多