Fedora 17 not so easy PostgreSQL configuration

I don't usually post rants here, but this one might be actually helpful to others, so let's make an exception. It will be related to installing PostgreSQL from distro-specific packages. I usually prefer setting PostgreSQL from sources, unlike the majority of users; nevertheless, I'm familiar with how popular distros, like Debian or Fedora, manage their PostgreSQL layouts. Or so I thought until today.

My task was simple: install PostgreSQL instance for testing on a fresh Linux box, use a non-standard port. The catch: the box was running a relatively new Fedora 17.

Normally, I run a single database instance per each host, so I find Fedora's PostgreSQL layout much more straightforward then Debian's: all configuration files are stored in $PGDATA (/var/lib/pgsql/data by default), just like in a source-based installation. Everything you need to change should be there.

I launched vim on /var/lib/psql/data/postgresql.conf, uncommented listen_address, setting it to '*' to allow the server to listen on TCP sockets and modified the port line to 5552. Afterwards, I did

service postgresql restart
Nothing happened. By examining
ps ax|grep postgresql
I confirmed my guess that the port number is embedded into the PostgreSQL command-line. So, let's check /etc/rc.d/init.d/postgresql.service.

Alas, there were no postgresql related files there. At that moment I started to have my suspicions. I did

find / -name 'postgresql*'
and found a bunch of files called postgresql.service. The most promising of them was /usr/lib/systemd/system/postgresql.service, so I pointed my editor there. The file indeed contained the setting for PostgreSQL port, along with a warning, stating the changes would be overwritten during package. There was a suggestion to create /etc/systemd/system/postgresql.service and include the current postgresql.service there before adding a line that changes PGPORT.

I did the suggestion above and issued service postgresql restart once again. My custom postgresql.service looked like this:

.include /usr/lib/systemd/system/postgresql.service
[Service]
Environment=PGPORT=5552
Guess what - nothing had changed. Before giving up and going to google for answers I had tried on last thing - changing the /usr/lib/systemd/system/postgresql.service directly, despite the warning, and doing service restart. Amusingly, nothing changed even then, but I got another warning suggesting to run systemctl --system daemon-reload.

Finally, I reverted my /usr/lib/systemd/system/postgresql.service changes, did

systemctl --system daemon-reload
restarted postgresql service one last time and the changes in /etc/systemd/system/postgresql.service finally came into effect. Ran netstat and confirmed that PostgreSQL instance was listening on port 5552 at last. It took no less than 10 steps to figure this out.

In a conclusion, I totally understand that every distro packagers have a right to make PostgreSQL configuration process as complex as they want, but with a such popular one as Fedora and the trend to make PostgreSQL easier for new users I find the whole procedure ridiculously complicated. Pushing the changes to the Fedora layout might be hard, but here's one small thing that will make the configuration easier right away: just add a comment to the postgresql.conf shipped with Fedora, describing the process to change the port parameter.

Now off to do actual work :-)