How To Fix – FATAL: Peer authentication failed for user “postgres” Error

在django切换postgressql数据库时遇到一个问题

/home/secur1ty/anaconda3/envs/SOAR_TEST/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py:105: RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': FATAL:  Peer authentication failed for user "postgres"

国内csdn和国外stakover上都没有得到满意的解答,所以翻了官方文档。
简单机器翻译到下面
当您尝试登录到PostgreSQL用户时,会出现对等身份验证失败错误,但身份验证失败,因为默认情况下,psql使用对等身份验证而不是密码身份验证通过UNIX套接字连接。
在本文中,我们将学习如何通过在Unix套接字对等方法上强制进行密码身份验证来消除致命的:用户“postgres”错误的对等身份验证失败,
首先,导航到/etc/postgresql/10/main目录。

cd /etc/postgresql/10/main

请注意,10是PostgreSQL版本,您可以选择不同的版本。
此处驻留pg_hba.conf文件。我们需要在此处进行一些更改。您可能需要sudo访问权限才能执行此操作。

sudo nano pg_hba.conf

向下滚动文件,直到找到以下内容——

# Database administrative login by Unix domain socket
local   all             postgres                                peer

这里将对等点更改为md5,如下所示。

# Database administrative login by Unix domain socket
local   all             postgres                                md5

对等意味着它将信任UNIX用户的真实性,因此不会提示输入密码。
md5意味着它将始终请求密码,并在使用md5进行哈希运算后验证密码。

Peer authentication failed error arrives when you try to login to your PostgreSQL user but authentication fails because by default psql connects over UNIX sockets using peer authentication instead of password authentication.

In this article we will learn how to get rid of FATAL: Peer authentication failed for user “postgres” error by enforcing password authentication over Unix sockets peer method,

First, navigate to the /etc/postgresql/10/main directory.

cd /etc/postgresql/10/main
Note that 10 is the PostgreSQL version it can be different for you.

Here resides the pg_hba.conffile we need to do some changes here you may need sudo access for this.

sudo nano pg_hba.conf
Scroll down the file till you find this –

Database administrative login by Unix domain socket

local all postgres peer
Here change the peer to md5 as follows.

Database administrative login by Unix domain socket

local all postgres md5
peer means it will trust the authenticity of UNIX user hence does not prompt for the password.
md5 means it will always ask for a password, and validate it after hashing with MD5.
Now save the file and restart the Postgres server.

sudo service postgresql restart
And that’s it!

Try to log in now.

sudo -u postgres psql
Password:
postgres=#

参考
https://djangocentral.com/how-to-fix-fatal-peer-authentication-failed-for-user-postgres-error/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值