I'm installing a Postgresql-9.4 HA environment in RHEL 7, when I initialize postgres db - it creates a data directory and within the data directory goes postgresql.conf & pg_hba.conf files. Here, I anticipate the creation of config files in data directory creates a collision, as it gets overridden during the master replication.

So, I'm trying to relocate the postgres.conf and pg_hba.conf files from the data directory and make postgres service to use the relocated config files. Where do I updated the path of the config files?

Update: I've updated the PGDATA in /usr/lib/systemd/system/postgresql-9.4.service to point the relocated conf files. In the new postgres.conf file, updated data directory and hba_file paths. And I tried to restart the service, then it returns an error

Job for postgresql-9.4.service failed. See 'systemctl status postgresql-9.4.service' and 'journalctl -xn' for details.

I've found this page in Postgresql official website, in detail :

If you wish to keep the configuration files elsewhere than the data directory, the postgres -D command-line option or PGDATA environment variable must point to the directory containing the configuration files, and the data_directory parameter must be set in postgresql.conf (or on the command line) to show where the data directory is actually located. Notice that data_directory overrides -D and PGDATA for the location of the data directory, but not for the location of the configuration files.

If you wish, you can specify the configuration file names and locations individually using the parameters config_file, hba_file and/or ident_file. config_file can only be specified on the postgres command line, but the others can be set within the main configuration file. If all three parameters plus data_directory are explicitly set, then it is not necessary to specify -D or PGDATA.

When setting any of these parameters, a relative path will be interpreted with respect to the directory in which postgres is started.

What's the output of echo $PGDATA on your host?

  • I've updated my post (following the instructions) echo $PGDATA shows empty line, – GIRI Oct 15 '15 at 20:22
  • Check if this post can help, right now I can't test unfortunately – lese Oct 15 '15 at 20:30
  • Yeah, I've updated the data directory location. But when tried to start the postgresql, the logs says, there is no such directory. I modified the permissions to postgres user and rebooted the system, which is of no use. It returns the same error. – GIRI Oct 19 '15 at 17:43
  • Looked into the post, it only specifies the location of the postgresql-9.4.service file. – GIRI Oct 19 '15 at 17:44
  • Does echo $PGDATA still return empty line? mmmm how can it return the error "no such directory", it must be reading the value from somewhere else, we need to understand from where. It seems he say he has set the env variable in both files /usr/lib/systemd/system/postgresql-9.3.service and /etc/systemd/system/postgresql-9.3.service and reloaded the service. – lese Oct 19 '15 at 18:52

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.