You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL 13用户postgres密码认证失败,求有效解决方案

Fixing PostgreSQL 13 Password Authentication Failure & GSSAPI Error

Hey there, I’ve run into this exact issue before—let’s get you connected properly. The root cause here is how your pg_hba.conf is configured, and it’s why your password isn’t being recognized at all.

Why Your Password Isn’t Working

Looking at your pg_hba.conf, all local connections (Unix socket, IPv4/IPv6 localhost) are set to use the peer authentication method. This method doesn’t care about passwords at all—it only checks if your system username matches the PostgreSQL username you’re trying to log in as. So even if you enter the correct password, PostgreSQL ignores it, leading to the "password authentication failed" error. The GSSAPI context error is a side effect of the client trying alternative auth methods that the server isn’t configured to accept.

Step-by-Step Fix

  1. Update your pg_hba.conf file
    Open /Library/PostgreSQL/13/data/pg_hba.conf in a text editor (you’ll need sudo privileges, e.g., sudo nano /Library/PostgreSQL/13/data/pg_hba.conf). Change all instances of peer to scram-sha-256 (PostgreSQL 13’s recommended secure auth method) or md5 if you prefer:

    # "local" is for Unix domain socket connections only
    local all all scram-sha-256
    # IPv4 local connections:
    host all all 127.0.0.1/32 scram-sha-256
    # IPv6 local connections:
    host all all ::1/128 scram-sha-256
    # Allow replication connections from localhost, by a user with the
    # replication privilege.
    local replication all scram-sha-256
    host replication all 127.0.0.1/32 scram-sha-256
    host replication all ::1/128 scram-sha-256
    
  2. Restart PostgreSQL to apply changes
    On macOS, you can restart the service using the PostgreSQL app’s built-in restart button, or run this command in the terminal:

    sudo /Library/PostgreSQL/13/bin/pg_ctl restart -D /Library/PostgreSQL/13/data
    
  3. Verify/reset your postgres user password (if needed)
    If you’re still unsure about your password, you can reset it easily using the peer auth method while it’s still active (before restarting, or temporarily revert if you already restarted):

    • Open a terminal and run: sudo -u postgres psql (this logs you into PostgreSQL as the postgres user without a password, thanks to peer auth)
    • Reset the password with:
      ALTER USER postgres WITH ENCRYPTED PASSWORD 'your-secure-password-here';
      
    • Exit with \q, then restart PostgreSQL as before.

Why This Works

By switching to scram-sha-256 or md5, PostgreSQL will now prompt for and validate the password you set. The GSSAPI error will disappear because the client will use the password-based auth method you’ve configured instead of trying to initiate a GSSAPI context that the server doesn’t support.

内容的提问来源于stack exchange,提问作者roe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 20:53:16