11

i am on ubuntu 12.04 server and i am trying to install postgresql. As of now, i have successfully installed it but unable to configure it. I need to create a role to move ahead and i ran this command in terminal :

root@hostname: createuser -s -r postgres

and it said :

createuser: could not connect to database postgres: FATAL: role "root" does not exist

Fine, so i did :

su - postgres

and then tried again

postgres@hostname: createuser -s -r postgres

and i got the error

createuser: could not connect to database postgres: FATAL: role "postgres" does not exist

and i get the same error when i do

psql -d dbname

Its like a loop, i am unable to create a role postgres because a role postgres does not already exist.

How do i fix this ?

The postgres version seems to be 9.1.x and the ubuntu version is 12.10

2
  • What is the output of sudo pg_lsclusters ?
    – A.H.
    Commented Mar 24, 2013 at 10:00
  • @A.H. The command pg_lsclusters was not found. It asked me to install postgresql-common package. I tried doing as root user and i got an error. Its tried removing postgres-xc and dpkg: error processing postgres-xc (--remove): and then it exit. Commented Mar 24, 2013 at 12:11

2 Answers 2

9

Turns out i had installed postgres-xc and postgresql on my machine. I had to knock off postgres-xc completely. And it was a little difficult to do that because, there was always an error --purge remove postgres-xc and the uninstallation could not continue.

There seems to be some kind of a packaging bug. (details on launchpad).

Eventually, i ended up doing this to make it work.

After that i uninstalled postgresql and installed it back to make it work.

3
  • I had a similar issue. When uninstalling postgresql, make sure to stop all postgres processes, delete the unix user postgres, and also delete the lock files in /var/run/postgresql. Commented May 29, 2014 at 23:21
  • @SergeyOrshanskiy thanks for that. I remember i had eventually solved by doing pretty much what you said. :) Commented May 30, 2014 at 13:06
  • 1
    postgres-xc apparently messed up my postgres setup as well. Same fix worked for me!
    – Dan Burton
    Commented Sep 20, 2014 at 20:20
1

Read postgresql tutorial it doesn't matter if it's Ubuntu or other Linux.

EDIT before creating role or anything else on fresh install you need to create database cluster: have you created it?

initdb -D /usr/local/pgsql/data

You need to be logged as user postgres on linux machine. Here is more info.

5
  • yeah. I am following the steps but i am unable to create a user. The role postgres does not exist to create the role postgres. Thats what is confusing me. any idea ? Commented Mar 24, 2013 at 5:49
  • @Ladislav: Debian (and therefore also Ubuntu) has custom scripts and conventions for managing PostgreSQL databases and clusters. Using the plain PG-commands will do more harm than it is good. Especially for non-experts.
    – A.H.
    Commented Mar 24, 2013 at 9:58
  • @A.H. not know about debian and ubuntu, i'm using slackware. with initdb you won't harm your instalation, it's for creating database cluster. it will create files in /usr/local/pgsql/data, if something goes wrong you can remove it and go from start.
    – 1ac0
    Commented Mar 24, 2013 at 10:09
  • The problem: This new database might not be picked up at reboot. And having multiple database versions in parallel will not work. Multiple clusters will not work. And so on. Do you want to sort out the mess via chat if anything will not work?
    – A.H.
    Commented Mar 24, 2013 at 10:18
  • @A.H.i would love to chat and seek help ! Commented Mar 24, 2013 at 11:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.