PostgreSQL error: Fatal: role "username" does not exist
Use the operating system user postgres
to create your database - as long as you haven't set up a database role with the necessary privileges that corresponds to your operating system user of the same name (h9uest
in your case):
sudo -u postgres -i
As recommended here or here.
Then try again. Type exit
when done with operating as system user postgres
.
Or execute the single command createuser
as postgres
with sudo
, like demonstrated by drees in another answer.
The point is to use the operating system user matching the database role of the same name to be granted access via ident
authentication. postgres
is the default operating system user to have initialized the database cluster. The manual:
In order to bootstrap the database system, a freshly initialized
system always contains one predefined role. This role is always a
“superuser”, and by default (unless altered when runninginitdb
) it
will have the same name as the operating system user that initialized
the database cluster. Customarily, this role will be namedpostgres
.
In order to create more roles you first have to connect as this
initial role.
I have heard of odd setups with non-standard user names or where the operating system user does not exist. You'd need to adapt your strategy there.
Read about database roles and client authentication in the manual.
POSTGRES: FATAL: role "USERNAME" does not exist
A standard installation of Postgres has peer
authentication enabled in pg_hba.conf
. If you start psql
without parameters it looks to connect with a DB role of the same name as the current OS user - obviously "edac" in your case.
Either you create such a role in the database (and grant desired privileges to it), or you connect with a different (existing) role. In a fresh installation, at least the database role "postgres" exists, which is a superuser.
Either you log in with username and password. Or simpler, connect as OS user "postgres" to allow peer authentication with the DB role of the same name. Like:
sudo -u postgres psql
Then you may want to create a DB role named "edac" (without superuser privileges):
CREATE ROLE edac;
Or, to just do that in one step with the shell command createuser:
sudo -u postgres createuser edac
See:
- PostgreSQL error: Fatal: role "username" does not exist
- Login Failed with Existing User on PostgreSQL
psql: FATAL: role "postgres" does not exist
NOTE: If you installed postgres using homebrew, see the comment from @user3402754 below.
Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.
But the first step is to check the missing role: What is the output within psql
of the command \du
? On my Ubuntu system the relevant line looks like this:
List of roles
Role name | Attributes | Member of
-----------+-----------------------------------+-----------
postgres | Superuser, Create role, Create DB | {}
If there is not at least one role with superuser
, then you have a problem :-)
If there is one, you can use that to login. And looking at the output of your \l
command: The permissions for user
on the template0
and template1
databases are the same as on my Ubuntu system for the superuser postgres
. So I think your setup simple uses user
as the superuser. So you could try this command to login:
sudo -u user psql user
If user
is really the DB superuser you can create another DB superuser and a private, empty database for him:
CREATE USER postgres SUPERUSER;
CREATE DATABASE postgres WITH OWNER postgres;
But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.
"Role" does not exists in Postgresql
You have first to login in a linux shell as the user postgres
and than create new postgres user with the command createuser
. The system user postgres
is created automatically by the Postgres installer.
Execute this code in the console (change your_username
with a username of your choice):
sudo -u postgres -i
createuser -l -d -P your_username
Better you create a database with the same name too (this makes the login later easier):
createdb your_username -O your_username
Then you should be able to connect in psql with
psql -h localhost -U your_username
PostgreSQL error Fatal: role “username” does not exist
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 <user-name>
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:
- connecting to the database
- create user
- create database
PostgreSQL: "psql: error: FATAL: role "postgres" does not exist" error
If you ran initdb.exe as OS user "friazsa" and didn't specify the -U
option, then the name of the superuser is "friazsa". If you want it to be "postgres", then delete your database (assuming you haven't yet put in any data you need to keep) and repeat initdb this time using -U postgres
psql fatal role does not exist
As pointed out in the comments, your pg_hba.conf seems fine.
Usually, the database will run as the postgres user (check ps aux | grep postgres
to find out the username postgres is running under).
Log in as that user, for example sudo su - postgres
, then create a user matching your normal Ubuntu user account (createuser username
), and finally create a database with that same name and set the owner (-O
) to that database user, like this: createdb -O username username
).
That should make calling psql
work, and pgadmin - as long as you start it as your default user, username - should work as well.
Edit: By default, psql
will use your Linux username as default value for both the database-username and the database-name. You can override the username by using -U someotherusername
, and connect to a different database by adding that DB name to the command line, such as psql someotherdbname
. You might also find psql -l
useful for listing the existing databases.
Related Topics
Better Techniques for Trimming Leading Zeros in SQL Server
How to Replace Empty String With Value That Is Not Empty for the Same Policynumber
How to Get Last 7 Days Data from Current Datetime to Last 7 Days in SQL Server
Mysql - Trigger for Updating Same Table After Insert
How to Store Multiple Values in Single Field in SQL Database
H2 Database. How to Convert Date to Seconds in SQL
Row Numbers in Query Result Using Microsoft Access
Splitting String into Multiple Rows in Oracle
Sql Select Last N Rows, Sort Them Reversed
Phpmyadmin Says No Privilege to Create Database, Despite Logged in as Root User
How to Include Results of SQL Count If Count=0
Check If a Column Contains Text Using SQL
How to Add a Space Between Two Text in SQL Code
Select All Dates Between First Day of Month and Current Date
Oracle Sql, Concatenate Multiple Columns + Add Text
Sql - Sum of Positive and Negative Numbers Using Subquery
How to Use Return Value of Insert...Returning in Another Insert