8

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?

c0da
  • 181
  • 1
  • 1
  • 2

4 Answers4

7

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
TomH
  • 1,290
  • 7
  • 10
  • 3
    And [here](http://docs.fedoraproject.org/en-US/Fedora/16/html/Release_Notes/sect-Release_Notes-Changes_for_Sysadmin.html) is the page explaining why. – James O'Gorman Jan 15 '12 at 10:45
  • 1
    `Data directory not empty.` <-- Got this error... :( I must be doing something horribly wrong. – c0da Jan 15 '12 at 14:45
  • 1
    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 '12 at 18:45
3

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"

Dannid
  • 131
  • 2
2

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
Khaled
  • 36,533
  • 8
  • 72
  • 99
  • 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 '12 at 09:31
  • Have you checked the system logs as indicated in the error message? – Khaled Jan 15 '12 at 09:48
  • Which log should I check? There are a tonne of them. :( – c0da Jan 15 '12 at 09:58
0

This is answering a little late, but may be helpful for someone out there... On Fedora 18, with postgresql 9.2, I ended up having to add /usr/pgsql-9.2/bin to my PATH in my shell, and from there I had to run:

postgresql92-setup initdb

in order to get the configuration files and all that in /var/lib/pgsql/9.2/data going. Hope that's helpful to someone else out there!

Dmitri DB
  • 113
  • 5