Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to create user postgres: role "postgres" does not exists

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

like image 244
Kaushik Thirthappa Avatar asked Mar 23 '13 20:03

Kaushik Thirthappa


People also ask

Does not Exist role Postgres?

According to the message, there's no user named postgres in the DB. So, let's try to create it with the createuser command installed together with postgres. Make sure the postgres user have admin permissions by providing the --superuser operator.

How do I create a role in PostgreSQL?

After you connect with the psql client, run the following command to create a role that has the LOGIN attribute and a non-empty, MD5-encrypted password: postgres=#CREATE ROLE demorole1 WITH LOGIN ENCRYPTED PASSWORD 'password1'; Note: The trailing semicolon ( ; ) at the end of the SQL statement is required.

Is role same as user in Postgres?

Users, groups, and roles are the same thing in PostgreSQL, with the only difference being that users have permission to log in by default. The CREATE USER and CREATE GROUP statements are actually aliases for the CREATE ROLE statement.

How do you check Postgres is installed or not in Mac?

psql -c "SELECT 1" -d {dbname} > /dev/null || postgres -D /usr/local/var/postgres >postgres. log 2>&1 & if you want to check and start postgres in one go (handy for automation scripts).


2 Answers

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.

like image 174
Kaushik Thirthappa Avatar answered Sep 22 '22 17:09

Kaushik Thirthappa


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.

like image 21
1ac0 Avatar answered Sep 24 '22 17:09

1ac0