Databases

Fix PostgreSQL "role does not exist"

You're connecting as a user PostgreSQL doesn't know. Create that role, or connect as one that exists.

  1. Create the missing postgres role
    Terminal
    createuser -s postgres

    Homebrew's PostgreSQL only creates a role named after your Mac user.

Check it worked

  1. Connect as postgres
    Terminal
    psql -U postgres -c "SELECT current_user;"
  1. Create a role for your Linux userNeeds sudo
    Terminal · Ubuntu / Debian
    sudo -u postgres createuser --superuser $USER
  2. And a database with the same name (psql looks for it)
    Terminal · Ubuntu / Debian
    createdb $USER

Check it worked

  1. Connect as yourself
    Terminal · Ubuntu / Debian
    psql -c "SELECT current_user;"
  1. Connect as the postgres user instead
    PowerShell
    psql -U postgres

    On Windows, psql tries your Windows user name unless you say otherwise.