Postgresql – Cannot create PostgreSQL user

postgresqlpostgresql-9.1

I'm using PostrgreSQL 9.1.9 on Ubuntu 13.04.

Using the following StackOverflow question, I tried to create a user/role in postgressql:

giladnaaman@giladnaaman-Lenovo-G550:~/Programming/Eclipse/Hephaestus$ createuser --version
createuser (PostgreSQL) 9.1.9

giladnaaman@giladnaaman-Lenovo-G550:~/Programming/Eclipse/Hephaestus$ createuser f4
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
createuser: could not connect to database postgres: FATAL:  role "giladnaaman" does not exist

How can I solve this problem?

Best Answer

You are trying to connect to the database as your user but that use doesn't exists. The best way to execute administrative commands on PostgreSQL is to issue them as the "postgres" user. Change user with:

sudo su -  postgres

The user postgres exists and has administrative privileges (it is a superuser) so can connect the database and create new users (just do a createuser after the sudo).