最近一个月以来我一直在处理这个问题。每当我尝试在生产环境访问我的Django Admin页面时,就会出现以下错误:
OperationalError at /admin/login/
FATAL: password authentication failed for user "vpusr"
FATAL: password authentication failed for user "vpusr"
我的production.py设置文件如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'vpdb',
'USER': 'vpusr',
'PASSWORD': os.environ["VP_DB_PASS"],
'HOST': 'localhost',
}
}
注意:环境变量正在正常工作。即使我将普通密码硬编码在其中,它也无法正常工作。
以下是数据库列表及其所有者:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
vpdb | vpusr | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/vpusr +
| | | | | vpusr=CTc/vpusr
这里是用户列表:
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
vpusr | Superuser, Create DB | {}
正如您所看到的,我也尝试将Superuser和Create DB的角色添加到vpusr中,但没有任何效果。
即使我像这样通过终端连接,我仍然会收到相同的错误:
sudo -u postgres psql -U vpusr vpdb
我仍然会遇到以下错误:psql:FATAL:用户“vpusr”的对等身份验证失败
当我执行以下命令时:
psql -U vpusr -h localhost vpdb
我已经以vpusr身份成功连接到psql。
还有一些注意事项:我删除了数据库、用户并重新创建它们。我确保密码是正确的。 我在Digital Ocean的Ubuntu服务器上使用Gunicorn、Nginx、Virtualenv、Django和Postgres。
非常感谢您抽出时间阅读并帮助我解决问题!
编辑:我注意到我的应用程序迁移文件夹中没有迁移!难道是django或我的用户或postgres没有权限写入文件吗?
编辑:注意:我已将用户更改为Tony 在我的postgres日志文件中发现以下错误:
2017-09-09 18:09:55 UTC [29909-2] LOG: received fast shutdown request
2017-09-09 18:09:55 UTC [29909-3] LOG: aborting any active transactions
2017-09-09 18:09:55 UTC [29914-2] LOG: autovacuum launcher shutting down
2017-09-09 18:09:55 UTC [29911-1] LOG: shutting down
2017-09-09 18:09:55 UTC [29911-2] LOG: database system is shut down
2017-09-09 18:09:56 UTC [2711-1] LOG: database system was shut down at 2017-09-09 18:09:55 UTC
2017-09-09 18:09:56 UTC [2711-2] LOG: MultiXact member wraparound protections are now enabled
2017-09-09 18:09:56 UTC [2710-1] LOG: database system is ready to accept connections
2017-09-09 18:09:56 UTC [2715-1] LOG: autovacuum launcher started
2017-09-09 18:09:57 UTC [2717-1] [unknown]@[unknown] LOG: incomplete startup packet
2017-09-09 18:10:17 UTC [2740-1] tony@vpdb LOG: provided user name (tony) and authenticated user name (postgres) do not match
2017-09-09 18:10:17 UTC [2740-2] tony@vpdb FATAL: Peer authentication failed for user "tony"
2017-09-09 18:10:17 UTC [2740-3] tony@vpdb DETAIL: Connection matched pg_hba.conf line 90: "local all all peer"
编辑:
pg_hba.conf 文件:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
这个句子的意思是什么?
production.pyc
文件。尝试删除所有.pyc
文件和__pycache__
目录。(b) 你正在运行与你认为自己正在运行的应用程序不同的安装。三重检查,确保你没有在同一台机器上的第二个目录中克隆了你的应用程序。 - Antonis Christofides