I have installed PostgreSQL on my Mac OS Lion, and am working on a rails app. I use RVM to keep everything separate from my other Rails apps.
For some reason when I try to migrate the db for the first time rake cannot find the postgres user. I get the error
FATAL: role "postgres" does not exist
I have pgAdmin so I can clearly see there is a postgres user in the DB - the admin account in fact - so I'm not sure what else to do.
I read somewhere about people having issues with PostgreSQL because of which path it was installed in, but then I don't think I would have gotten that far if it couldn't find the db.
My answer was much more simple. Just went to the db folder and deleted the id column, which I had tried to forcefully create, but which is actually created automagically. I also deleted the USERNAME in the database.yml file (under the config folder).
I was on OSX 10.8, and everything I tried would give me the
FATAL: role "USER" does not exist
. Like many people said here, runcreateuser -s USER
, but that gave me the same error. This finally worked for me:The
createuser -s --username=postgres
creates a superuser (-s flag) by connecting as postgres (--username=postgres flag).I see that your question has been answered, but I want to add this answer in for people using OSX trying to install PostgreSQL 9.2.4.
In Ubuntu local user command prompt, but not root user, type
sudo -u postgres createuser username
username above should match the name indicated in the message "FATAL: role 'username' does not exist."
Enter password for username.
Then re-enter the command that generated role does not exist message.
In the Heroku documentation; Getting started whit rails 4, they say:
Then you just delete that line in "development:", if you don't pg tells to the database that works under role "myapp"
Also remember to create the database for development:
Repleace "myapp" for your app name
Actually, for some unknown reason, I found the issue was actually because the postgresql role hadn't been created.
Try running:
Note that roles are the way that PostgreSQL maintains database permissions. If there is no role for the postgres user, then it can't access anything. The createuser command is a thin wrapper around the commands CREATE USER, CREATE ROLE, etc.
Recently i got this problem immediately after installing postgres. If it comes immediately after installation, you might be missing the default user, postgres. In that case, you can create default user postgres using below command.
createuser -s -U $USER
It will prompt you to enter required database role name and password Once you complete the process, you can login to the postgres console using below command
Ex: psql -U postgres
Here, You need to enter the password if you have given any, while creating the user.
Hope it helps :)