PostgreSQL service initdb doesn't work

Solution 1:

On systems where postgres has been converted to use a native systemd unit you need to use postgresql-setup for things like initdb. So what you want is:

postgresql-setup initdb

Solution 2:

Run the "su - postgres -c ..." command as root

I found the answer here: https://bugzilla.redhat.com/show_bug.cgi?id=771496

Description of problem: After initial install of a postgresql server rpm, you are left with an unstartable service until you run the following command as root

su - postgres -c "initdb -D /var/lib/pgsql/data"

Version-Release number of selected component (if applicable):

[root@oscar]# rpm -q postgresql-server postgresql-server-9.1.2-1.fc16.x86_64

How reproducible: Always

Backstory

Several places had instructed me to use this command for Fedora 16, rather than following the prior instructions (new command: su - postgres -c "PGDATA=/var/lib/pgsql/data initdb" ), but upon seeing 'su' at the front of that, I assumed it would switch me to root when I ran the command. It kept prompting me for a password, but nothing was working.

I tried the root passwd, my own (as if sudo'ing), "postgres" and "pgsql" in case I was somehow supposed to be doing this as the postgres user, even leaving the password blank. I tried su'ing to root, and then running the command without the initial 'su -' (starting with "postgres -c ..."), but that errored as well, telling me that:

"The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server."

Finally, I tried running the full command "su - postgres -c ..." as root, but still using the "su", and wow- it worked. Now the service starts. Thanks Redhat bug tracking!

Summary

su to root, then enter:

su - postgres -c "PGDATA=/var/lib/pgsql/data initdb"