PostgreSQL error Fatal: role “username” does not exist

Abhishek picture Abhishek · Feb 2, 2015 · Viewed 45.8k times · Source

I'm setting up my PostgreSQL 9.1 in windows.

I can't do anything with PostgreSQL: can't createdb, can't createuser; all operations return the error message

Fatal: role root does not exist
root is my account name, which I created while installing Postgresql

But I am able to connect using:

 username : postgres  

How can I connect to postgres using role root?
There is a solution mentioned for linux platforms using su command here but not able to figure out solution for windows7

Thanks in Advance

Answer

a_horse_with_no_name picture a_horse_with_no_name · Feb 2, 2015

If you want to login to Postgres using the username root you need to first create such a user.

You first need to login as the Postgres super user. This is typically postgres (and is specified during installation):

psql -U postgres ....

then you can create roles and databases:

psql (9.4.0)
Type "help" for help.

postgres=# create user root with password 'verysecret';
CREATE ROLE
postgres=# \q

c:\
c:\>psql -U root postgres
psql (9.4.0)
Type "help" for help.

postgres=>

Logged in as the superuser you can also grant the root user the necessary privileges.

All parameters for psql are documented in the manual.

Creating users and databases is also documented in the manual: