Problem Installing and configuring PostgreSQL

Answering my own question. This is kinda annoying, the first question on any StackExchange site doesn't go well for me.

I had already done this, but somehow worked this time. Did this:

  1. sudo apt-get update && sudo apt-get upgrade
  2. sudo apt-get purge postgresql*
  3. sudo apt-get -f install
  4. sudo apt-get install postgresql

Works like a charm.

Note: adding the * in the purge command will purge all packages that begin with postgresql


I too faced this problem with Hetzner and very annoying. Here is how I solved it Tip: Looked at some pg package scripts

sudo apt-get purge postgresql* # ending * is important

sudo apt-get install postgresql

I suspect either Hetzner's 11.04 image is buggy or it's Ubuntu's .deb (unlikely though).


I have not seen this error on launchpad in associtiation with Natty. The same issue has been raised as a bug on launchpad for Hardy and got a fix. So following that logic I would expect it to be a bug and it is probably best practice to file a bug on launchpad.

Looking further into it I found 2 interesting (yet old) topics showing the exact same error that seem worth looking into:

This topic from 2006 is talking about the exact same problem and claims that

sudo /etc/init.d/postgresql-8.1 stop

sudo /etc/init.d/postgresql-8.1 start

psql template1

works.

On ubuntuforums there is a topic from 2008 about the same error and has a status 'solved'. Please have a look at the many suggestions in that topic.


psql is the cli client, it does not start the PostgreSQL server. To start the server, you should use:

/etc/init.d/postgresql start

then you can connect to it using psql.

To have PostgreSQL start on boot, you should do the following:

update-rc.d postgresql enable

You might also take a look at this:

http://www.cyberciti.biz/tips/how-to-controlling-access-to-linux-services.html