psql: FATAL: database "<user>" does not exist
- Login as default user:
sudo -i -u postgres
- Create new User:
createuser --interactive
- When prompted for role name, enter linux username, and select Yes to superuser question.
- Still logged in as postgres user, create a database:
createdb <username_from_step_3>
- Confirm error(s) are gone by entering:
psql
at the command prompt. - Output should show
psql (x.x.x) Type "help" for help.
From the terminal, just Run the command on your command prompt window. (Not inside psql).
createdb <user>
And then try to run postgres again.
It appears that your package manager failed to create the database named $user for you. The reason that
psql -d template1
works for you is that template1 is a database created by postgres itself, and is present on all installations. You are apparently able to log in to template1, so you must have some rights assigned to you by the database. Try this at a shell prompt:
createdb
and then see if you can log in again with
psql -h localhost
This will simply create a database for your login user, which I think is what you are looking for. If createdb fails, then you don't have enough rights to make your own database, and you will have to figure out how to fix the homebrew package.
By default, postgres tries to connect to a database with the same name as your user. To prevent this default behaviour, just specify user and database:
psql -U Username DatabaseName