I installed PostgreSQL 9.1.2 on my fedora 16 in a method similar to mentioned here, and tested it, which means that my installation is working fine.

But when I do: service postgresql initdb or even service postgresql-9.0 initdb I get the error:

Redirecting to /bin/systemctl  initdb postgresql.service
Unknown operation initdb

And because of this, I am unable to start pgAdmin3 too.

What am I missing?

link|improve this question
feedback

3 Answers

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
link|improve this answer
1  
And here is the page explaining why. – James O'Gorman Jan 15 at 10:45
Data directory not empty. <-- Got this error... :( I must be doing something horribly wrong. – c0da Jan 15 at 14:45
Yes - you already have a database and initdb is refusing to overwrite it. If you want to replace it then you need to delete the old one by hand, though renaming it is probably safer until you're really sure you want to get rid of it. – TomH Jan 15 at 18:45
feedback

You need to start the postgresql service using the command:

service postgresql start

The initdb tool should be used only when you need to initialise the data directory of the database server, and this should have been done automatically when you install your postgresql server using a package manager like yum on centos or apt-get on ubuntu.

You can use it as indicated in the link you provided as:

initdb -D /usr/local/pgsql/data
link|improve this answer
I logged in as root and did: service postgresql start. The output was: Redirecting to /bin/systemctl start postgresql.service Job failed. See system logs and 'systemctl status' for details. when I did systemctl status, the output was Too few arguments.. – c0da Jan 15 at 9:31
Have you checked the system logs as indicated in the error message? – Khaled Jan 15 at 9:48
Which log should I check? There are a tonne of them. :( – c0da Jan 15 at 9:58
feedback

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"

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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