Recently, I faced up the same problem. And the true problem is how to tell the postmaster its real configuration file location. All we have to do is to add -c config_file <configuration/filename/location>
as commandline option to postgres process. And issue is: how to do that...?
Long time ago, in a galaxy far, far away, we had System V initscripts and we could configure command line options within certain file located somewhere in; /etc/sysconfig dir. But now, we have systemd - robust, advanced and... hard configurable machinery to do all and even more. So, the only way to split configuration files and data files is to configure postgresql systemd init system. How to achieve this? This is what I have done:
First of all I moved configuration files:postgresql.conf, pg_hba.conf ang pg_ident.conf into external directory, let's say: /var/lib/pgsql/config
I configured new location of above files in postgresql.conf:
hba_file = '/var/lib/pgsql/config/pg_hba.conf'
ident_file = '/var/lib/pgsql/config/pg_ident.conf'
I edited systemd postgresql.service by overriding existing (system) configuration:
systemctl edit postgresql.service
This causes creation of new, empty systemd service file: /etc/systemd/system/postgresql.service.d/override.conf and opens it in $EDITOR editor.
I put there:
[Service]
ExecStart=
ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT} -c config_file=/var/lib/pgsql/config/postgresql.conf" -w -t 300
As we see - I added: "-c config_file /var/lib/pgsql/config/postgresql.conf" string into -o argument. Another interesting point is empty: "ExecStart" directive. Though it's called: "overriding", we have to first of all zeroed this directive, otherwise, we will have error: "postgresql.service has more than one ExecStart= setting...".
Restarted service:
systemctl restart postgresql
And I enjoyed the Postgresql with data files in $PGDATA and configuration files, everywhere else:
/usr/bin/postgres -D /var/lib/pgsql/data -p 5432 -c config_file=/var/lib/pgsql/config/postgresql.conf
I have made this with CentOS 7 and RHEL7, but hope it should be working in any systemd based OS.
Hope, this story will be helpful for someone.
Regards.