Error role username does not exist

The easiest way to get started with PostgreSQL on the Mac - PostgresApp/troubleshooting.md at master · PostgresApp/PostgresApp
layout title

documentation

Troubleshooting

Troubleshooting & Support

Warnings

Reindexing required / Reindexing recommended

See this dedicated page.

Common errors

The following list contains all errors which may occur while you’re using Postgres.app.

PostgreSQL version not installed

Postgres.app includes the PostgreSQL binaries inside the application package. Each version
is available bundled with either a single or all currently supported versions of
PostgreSQL.

This error means that the binaries for this server are not included in the installed
bundle. If the required version is still supported, you can download a different bundle
from this page. If the version is no longer supported, you can find the
last release supporting that version under legacy downloads.
Please note that these releases are no longer maintained and you should
migrate your data to a new version as soon as possible.

After the first start of Postgres.app, it is possible to alter the available versions of
PostgreSQL by copying the wanted versions out of the application package of other releases
to the directory /Applications/Postgres.app/Contents/Versions/.

Port [number] is already in use

This error usually means that you already have a PostgreSQL server running on your Mac.
If that is running within Postgres.app, expand the sidebar and stop that other server or
alter the ‘Port’ under the button ‘Database Settings’.

If there isn’t an other server running within Postgres.app, you likely have a different
installation of PostgreSQL running on your machine. To uninstall this, see the
instructions on this page

It can also happen when a different user on your Mac is already running Postgres.app.
Only a single server can run on each port.

If you want to use multiple PostgreSQL servers simultaneously, configure them to use a different port.

There is already a PostgreSQL server running in this data directory

This can happen if you’ve configured Postgres.app to use a data directory that is used by a different PostgreSQL installation.
Stop the other server before starting Postgres.app.
In general, it is not recommended to just use a data directory created by another version of PostgreSQL, since it might have been configured differently.

The data directory contains an old postmaster.pid file / The data directory contains an unreadable postmaster.pid file

PostgreSQL puts a file named postmaster.pid in the data directory to store the process id of the PostgreSQL server process.
If PostgreSQL crashes, this file can contain an old pid that confuses PostgreSQL.
You can fix this issue by deleting the postmaster.pid file. However, you must make sure that PostgreSQL is really not running.
Open Activity Monitor and make sure that there are no processes named ‘postgres’ or ‘postmaster’.

If you delete the postmaster.pid file while PostgreSQL is running, bad things will happen.

Could not initialize database cluster

This error means that the initdb command failed.
This should not happen. If it does, please open an issue on Github.
For troubleshooting, try executing the following command manually:

/Applications/Postgres.app/Contents/Versions/latest/bin/initdb -D "DATA DIRECTORY" -U postgres --encoding=UTF-8 --locale=en_US.UTF-8

Could not create default user / Could not create user database

After the data directory is initialized, Postgres.app creates a default user and database.
This error means that creating the user has failed. Check the server log (inside the data directory) for details.

You can try creating a default user and database manually:

/Applications/Postgres.app/Contents/Versions/latest/bin/createuser -U postgres -p PORT --superuser USERNAME
/Applications/Postgres.app/Contents/Versions/latest/bin/createdb -U USERNAME -p PORT DATABASENAME

Postgres.app uses your system user name for USERNAME and DATABASENAME by default.

File [or Folder] not found. It will be created the first time you start the server

Data directories and all its contents are only created when you start a server the first time.
This error occurs when you attempt to open a data directory (or file) which doesn’t exist yet.
Start the server first and try again.

Unknown Error

This error should not occur.
Please open an issue on Github and provide a detailed description what lead to this error.

Errors in the server log

The server log is inside the data directory in a file named postgres-server.log.

Here are some errors that could appear:

Could not create listen socket for «localhost»

Usually this error is caused by broken /etc/hosts file.
The problem could be a missing localhost entry, syntax errors or incorrect whitespace.

For reference, here is what this file should look like by default on macOS:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 

database files are incompatible with server: The database cluster was initialized with PG_CONTROL_VERSION x, but the server was compiled with PG_CONTROL_VERSION y

This error usually happens when you try to start a server that was initialized with a prerelease version of PostgreSQL.
The on disk data format sometimes changes between pre-release versions.
You need to start the server with the version you initialized it with, then dump the database, then create a new server with the new version and restore.

Errors when connecting to the PostgreSQL server

psql: FATAL: role «USERNAME» does not exist

By default, Postgres.app creates a PostgreSQL user with the same user as your system user name.
When this error occurs, it means that this user does not exist.
You can create it by executing the following command in the Terminal:

  1. Make sure your $PATH is configured correctly
  2. Execute the command createuser -U postgres -s $USER
  • -U postgres tells createuser to connect with the postgres user name
  • -s tells createuser to create a super user
  • $USER is a variable containing your system user name, and tells createuser the name of the postgres user you want to create

psql: FATAL: database «USERNAME» does not exist

By default, psql tries to connect to a database with the same name as your local user.
This error means that this database does not exist. This can have several possible reasons:

  • Postgres.app failed to create the default database when initializing the server
  • You deleted the default database
  • Your user name is different from the user name that initialized the server

There are multiple ways to fix this problem:

  1. Make sure your $PATH is configured correctly
  2. You can create the missing database using the command createdb $USER, or
  3. You can connect to a different database, eg. psql postgres to connect to the other default database

Could not translate host name «localhost», service «5432» to address: nodename nor servname provided, or not known

Usually this error is caused by broken /etc/hosts file.
The problem could be a missing localhost entry, syntax errors or incorrect whitespace.

For reference, here is what this file should look like by default on macOS:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 

psql: FATAL: could not open relation mapping file «global/pg_filenode.map»: No such file or directory

This error can occur when you delete the data directory while the PostgreSQL server is still running.
To fix it, kill all PostgreSQL processes or restart your computer.
Then start a new PostgreSQL server.

Starting the server manually

For debugging, it is often useful to try starting the server manually:

  1. Quit Postgres.app
  2. Open the Terminal and type /Applications/Postgres.app/Contents/Versions/latest/bin/postgres -D "DATA DIRECTORY" -p PORT (replace DATA DIRECTORY with your data directory, make sure to include the quotes because the path might contain spaces)
  3. Now you should see a more detailed error message why the server failed to start

Resetting Postgres.app

If you somehow mess up your Postgres.app installation, here’s how to start fresh.
CAUTION: This will delete all your databases, tables and data!

  1. Quit Postgres.app
  2. Open Activity Monitor, see if any processes name postgres are running. If so, kill them. Kill the process with the lowest pid first; child processes are respawned automatically after killing them.
  3. Delete the Folder ~/Library/Application Support/Postgres
  4. Delete all settings using the command: defaults delete com.postgresapp.Postgres2
  5. Open Postgres.app again

Technical Support

If you run into any issues using Postgres.app, your first stop should be the issue tracker on Github.
You can also ask @PostgresApp on Twitter.

Help others

If you encounter an issue and find a way to fix it, consider contributing to this documentation. This page is hosted on Github.

Let’s first try to create this error here. I’m going to generate a new rails project, so I’m going to say rails new MyPgProject -T --database=postgressql. I’m going to have it skip the test, so it loads a little bit faster. Then I’m also going to make sure that I am using the database of PostgreSQL.

Now, this assumes that you already have Postgres installed on your system, so I’m going to run this. It’s going to go install all the dependencies, and bundle install and everything like that. Now, if I type ls, you can see that we have MyPgProject right there.

large

Let’s switch into that, cd MyPgProject/ and you may think that we’d be able to type rails db:create just like this, and usually that will work. If you run into the rule does not exist bug, like we’re going to right here, then this is going to break.

If I run this then you’re going to see that we get this giant very scary looking error message. Scroll all the way up to the top. Then you’re going to see where it says PG::ConnectionBad Fatal role "jordan" does not exist.

large

Now, do not let this intimidate you. All it means is that that Postgres was looking for the username JORDAN. It says role, but it’s actually looking for a username Jordan, and it was not able to find it. That is what the entire issue is related to.

I’m going to show you that we can fix it just like this. The very first thing that we have to do is we have to switch in and use our Postgres user. To do that type sudo su. That stands for super user. Then sudo su - postgres. What this means is right now we’re logged in as Jordan, well, I am.

Yours is going to say whatever your name is, but you can see right here I’m logged in as Jordan into this version of Linux. I want to be logged in as a Postgres user. If I hit enter. It’s going to ask me for my system password. Now you can see that it says postgres@jordan. Now I am logged in as the Postgres user.

large

Now what I can do is create that user, so I can say create user -s -r jordan. Most likely, unless your name is Jordan, and you gave Jordan as your system role or your system name, then this is going to be your name is.

Whenever you have that error and it says «role does not exist» for mine it says Jordan. Yours is going to say whatever your name is. That is what you want to type in. So createuser - s -r jordan. Hit enter, and that’s it.

Now hit control + d. That’s going to switch you back into your default user. Assuming that you’re still in the project. Now let’s try rails db:create once again, and you’re going to see that this is actually working. We no longer get that error message.

large

You can do a really quick scaffold, so you can say rails g scaffold Blog title:string, just like this. Then it’s going to generate all this for us. Then we’re going to be able to update the database. Now I can say rails db:migrate.

This is going to update the database tables that we already created. Type rails s to start the rails server. Now we should be able to go to localhost 3000 in our browser, and update everything.

We can actually type different titles in for blogs and different things like that just to make sure that we actually have persistence. That what we’re typing into the screen is going to be able to be saved in the database.

If I type localhost3000/blogs, you can see that now we have our blogs showing up. I can type new title My test, hit create blog, and that is stored.

large

That means that this is stored in the database, which means that our database configuration is working perfectly. That is how you can fix the role not found, and fix that fatal Postgres error when you’re working on Linux.

I’m setting up my PostgreSQL 9.1. I can’t do anything with PostgreSQL: can’t createdb, can’t createuser; all operations return the error message

Fatal: role h9uest does not exist

h9uest is my account name, and I sudo apt-get install PostgreSQL 9.1 under this account.
Similar error persists for the root account.

16 Answers

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 running initdb) it
will have the same name as the operating system user that initialized
the database cluster. Customarily, this role will be named postgres.
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.

After trying many other people’s solutions, and without success, this answer finally helped me.

https://stackoverflow.com/a/16974197/2433309

In short, running

sudo -u postgres createuser owning_user

creates a role with name owning_user (in this case, h9uest). After that you can run rake db:create from the terminal under whatever account name you set up without having to enter into the Postgres environment.

sudo su - postgres

psql template1

creating role on pgsql with privilege as «superuser»

CREATE ROLE username superuser;
eg. CREATE ROLE demo superuser;

Then create user

CREATE USER username; 
eg. CREATE USER demo;

Assign privilege to user

GRANT ROOT TO username;

And then enable login that user, so you can run e.g.: psql template1, from normal $ terminal:

ALTER ROLE username WITH LOGIN;

This works for me:

psql -h localhost -U postgres

Installing postgres using apt-get does not create a user role or a database.

To create a superuser role and a database for your personal user account:

sudo -u postgres createuser -s $(whoami); createdb $(whoami)

psql postgres

postgres=# CREATE ROLE username superuser;
postgres=# ALTER ROLE username WITH LOGIN;

For version Postgres 9.5 use following comand:

psql -h localhost -U postgres

Hope this will help.

Working method,

  1. vi /etc/postgresql/9.3/main/pg_hba.conf
  2. local all postgres peer
    here change peer to trust
  3. restart, sudo service postgresql restart

  4. now try, psql -U postgres

In local user prompt, not root user prompt, type

sudo -u postgres createuser <local username>

Then enter password for local user.

Then enter the previous command that generated «role ‘username’ does not exist.»

Above steps solved the problem for me.
If not, please send terminal messages for above steps.

For Windows users : psql -U postgres

You should see then the command-line interface to PostgreSQL: postgres=#

Manually creating a DB cluster solved it in my case.

For some reason, when I installed postgres, the «initial DB» wasn’t created. Executing initdb did the trick for me.

This solution is provided in the PostgreSQL Wiki — First steps:

initdb

Typically installing postgres to your OS creates an «initial DB» and starts the postgres server daemon running. If not then you’ll need to run initdb

dump and restore with --no-owner --no-privileges flags

e.g.

dump — pg_dump --no-owner --no-privileges --format=c --dbname=postgres://userpass:[email protected]:5432/schemaname > /tmp/full.dump

restore — pg_restore --no-owner --no-privileges --format=c --dbname=postgres://userpass:[email protected]:5432/schemaname /tmp/full.dump

Something as simple as changing port from 5432 to 5433 worked for me.

Follow these steps to get postgres working.

  1. In your terminal, locate the Application Support folder with the following command.
    /Users/[name of the user]/library/application support
  2. Delete the application, Postgres.
  3. Reinstall the app and it should work just fine.

Follow These Steps and it Will Work For You :

  1. run msfconsole
  2. type db_console
  3. some information will be shown to you chose the information who tell you to make: db_connect user:[email protected]:port.../database sorry I don’t remember it but it’s like this one then replace the user and the password and the host and the database with the information included in the database.yml in the emplacement: /usr/share/metasploit-framework/config
  4. you will see. rebuilding the model cache in the background.
  5. Type apt-get update && apt-get upgrade after the update restart the terminal and lunch msfconsole and it works you can check that by typing in msfconsole: msf>db_status you will see that it’s connected.

Понравилась статья? Поделить с друзьями:
  • Error retrieving credentials from the instance profile metadata service
  • Error retrieving character list pob
  • Error repair professional rus скачать бесплатно на русском языке
  • Error reference to non static member function must be called
  • Error reading the license file could not parse certificate java io ioexception odis