Introduction
When using Postgres.app on MacOS it is quite possible that you will encounter the folling exception:
FATAL: role “postgres” does not exist
As it states you are trying to connect to Postgres with a role unknown to the database. The easies solution for this is to create one. You can achieve this by running the following command:
╭─me@myMachine /Applications/Postgres.app/Contents/Versions/YOUR_VERSION/bin
╰─$ ./createuser -s missingRoleName
With the -s
flag you are creating a superuser.
Have you changed your MacOS username?
A little background for Postgres.app: When you start the app the first time, it will create a superuser
with the current MacOS username in your application.
In my case I migrated my system to a new MacBook and changed my MacOS username.
If you know your old superuser
role name, create a new superuser corresponding to your current MacOS username:
╭─me@myMachine /Applications/Postgres.app/Contents/Versions/YOUR_VERSION/bin
╰─$ ./createuser -s missingRoleName --username=OldSuperUserRoleName