21
votes

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

3
Did you copy my question over and make it a new one ... ?h9uest

3 Answers

48
votes

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:

0
votes

In some cases, when you install postgres the initial DB is not created.

You need to execute initdb.

0
votes

Same issue appeared while restoring DB/table on postgres docker container .

  • . When you connect to Postgres DB(psql shell) from inside the docker container, the default user would be a "root" (unless you specify psql -U "some-user-name") [Manjunath-MacBook-Air:$ sudo docker exec -it a2ff6075344e bash

    bash-5.0# psql -U postgres postgres < testdb_pg_dump

  • So, the issue gets resolved, by logging to psql shell with appropriate username

Here , -U postgres specifies that user connecting to DB is "postgres"