I am generating postgresql configuration files via ansible, and putting them in /etc/postgresql/XX/main/conf.d/whatever.conf. I accidentally made a syntax error and broke my postgresql, requiring manual fixing.

Is there any postgresql command to validate that a file is a valid postgresql.conf file?

sudoers files can be validates with /usr/sbin/visudo -cf path/to/file. Is there anything for postgresql?

I'm currently running Ubuntu 18.04 & 20.04, with PostgreSQL 10, 12 etc (yes several different versions).

2 Answers 2



At least as of version 10 there is a mechanism to check the config file from within postgres.

This is the result of adding a fubar to my config file, didn't reload it.

postgres=# select sourcefile, name, sourceline, error from 
           pg_file_settings where error is not null;
               sourcefile                | name | sourceline |    error
 /etc/postgresql/12/main/postgresql.conf |      |         33 | syntax error
(1 row)

Docs will be: https://www.postgresql.org/docs/10/view-pg-file-settings.html, also, you might be interested in https://www.postgresql.org/docs/10/view-pg-hba-file-rules.html

  • But you have to start PG for this.. Jan 17 at 16:18
  • Oh, great, I have learned something new! Jan 18 at 11:31
  • @StanislavBashkyrtsev If it is not running, then start it. If it starts, the file is valid. I think the problem he wants to solve is not shutting down the running server until he knows it will be able to start again. If it is already down, that isn't much of an issue.
    – jjanes
    Jan 18 at 17:08

The only program that I know is postgres, the database server.

I have two approaches to deal with that problem:

  • After you edit postgresql.conf and reload, examine the PostgreSQL log file. If there was a problem, you will see that in the log, an the server will keep running with the previous configuration (no outage). Fix the file and try again until it the reload is successful.

  • Use ALTER SYSTEM rather than postgresql.conf to change configuration parameters. That works just as well, and ALTER SYSTEM will catch most of the possible syntax errors. Of course, you should still look at the PostgreSQL log after reloading.

As an alternative to checking the log file, you may use the pg_file_settings view as described in the other answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.