首页 > 解决方案 > 如何使用 django postgres 和 docker-compose 调试密码身份验证失败

问题描述

你如何解决下面的问题

不知道我是如何搞砸我的postgresql配置(角色 + 密码等...)

我正在使用docker-compose django postgres13.3

db          | 2021-07-23 13:05:23.221 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db          | 2021-07-23 13:05:23.222 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db          | 2021-07-23 13:05:23.222 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db          | 2021-07-23 13:05:23.226 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db          | 2021-07-23 13:05:23.233 UTC [27] LOG:  database system was shut down at 2021-07-23 12:59:50 UTC
db          | 2021-07-23 13:05:23.252 UTC [1] LOG:  database system is ready to accept connections
db          | 2021-07-23 13:05:27.817 UTC [34] FATAL:  password authentication failed for user "postgres"
db          | 2021-07-23 13:05:27.817 UTC [34] DETAIL:  Password does not match for user "postgres".
db          |   Connection matched pg_hba.conf line 99: "host all all all md5"
db          | 2021-07-23 13:05:34.672 UTC [35] FATAL:  password authentication failed for user "postgres"
db          | 2021-07-23 13:05:34.672 UTC [35] DETAIL:  Password does not match for user "postgres".
db          |   Connection matched pg_hba.conf line 99: "host all all all md5"

...

backend     | Traceback (most recent call last):
backend     |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
backend     |     self.connect()
backend     |   File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
backend     |     return func(*args, **kwargs)
backend     |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
backend     |     self.connection = self.get_new_connection(conn_params)
backend     |   File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
backend     |     return func(*args, **kwargs)
backend     |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
backend     |     connection = Database.connect(**conn_params)
backend     |   File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
backend     |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
backend     | psycopg2.OperationalError: FATAL:  password authentication failed for user "postgres"

我试图手动编辑设置.py


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': "postgres",
        'USER': "postgres",
        'PASSWORD': "postgres",
        'HOST': 'db',
        'PORT': 5432,
    }
}

通常的用户详细信息似乎没有任何作用postgres,我访问了数据库psql postgres,尝试更新密码,创建新角色,表和权限,但当我开始docker-compose up -d --build并检查docker-compose logs它仍然无法正常工作

这是我尝试首次亮相的第二天,请帮助

标签: pythondjangodatabasepostgresqldocker

解决方案


任何遇到同样问题的人

你所要做的就是docker-compose down --volumes

然后

docker-compose up -d --build --force-recreate

:)


推荐阅读