chatuur
chatuur

Reputation: 1287

psql: FATAL: role "vimarshchaturvedi" does not exist. Postgres.app installation

I am working on OS X El Capitan version 10.11.3 I downloaded the Postgres app and ran the app.

The elephant icon on the top says Version 9.6.1.0(9.6.1.0)

When I click on 'Open psql' I get the following output on my terminal.

$ '/Applications/Postgres.app/Contents/Versions/9.6/bin'/psql -p5432
psql: FATAL:  role <username> does not exist

where is my username. As far as I understand the app should create a role with my username and no password.

I tried doing:

psql -h localhost -U <username>

which gave the same error.

Following are the various output I got for trying out answers posted on SO.

$ which psql
/Applications/Postgres.app/Contents/Versions/latest/bin/psql

After searching a bit more I ran the following command:

psql -h localhost -U postgres
postgres=# 

The postgres shell opened up. Can anyone explain what's happening?

Upvotes: 2

Views: 1087

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 657777

Starting psql without any given username (-U ...) tries to log in with a db user of the same name as the current OS user. Obviously that DB user has not yet been created.

The default superuser created with every DB cluster is named postgres. Don't confuse this with the name of the RDBMS or the system DB named postgres other other uses.

The fact that you can log in with user postgres and no PW indicates 2 things:

  1. The user `postgres exists (duh).
  2. It's set up for password-less access, either with a .pgpass file or in pg_hba.conf with one of the authentication methods peer , ident or trust. peer most likely.

If so, as quick fix from the shell:

createuser -h localhost -U postgres vimarshchaturvedi

vimarshchaturvedi obviously being your OS username.

Once logged in, you can check which login roles (= users) exit:

SELECT rolname FROM pg_roles;

Upvotes: 1

Related Questions