Databases

Fix PostgreSQL "Peer authentication failed"

On Linux, PostgreSQL checks your system user name. Connect as the matching user, or over localhost with a password.

Fill these in once

Peer authentication is a Linux setting. On macOS, see Fix PostgreSQL role does not exist.

  1. Option 1: run psql as the matching Linux userNeeds sudo
    Terminal · Ubuntu / Debian
    sudo -u postgres psql
  2. Option 2: connect over localhost with a password
    Terminal · Ubuntu / Debian
    psql -h localhost -U postgres -d postgres

    Adding -h localhost switches from peer checks to a password. Set one with Change a PostgreSQL user's password if needed.

  3. Option 3: find the settings file to change the rule for goodNeeds sudo
    Terminal · Ubuntu / Debian
    sudo -u postgres psql -c "SHOW hba_file;"

    In that file, change peer to scram-sha-256 on the local line, then run sudo systemctl reload postgresql.

Peer authentication is a Linux setting. On Windows, connect with psql -U postgres.