PostgreSQL - 用户“postgres”的对等身份验证失败

PostgreSQL - 用户“postgres”的对等身份验证失败

我有一个在 Windows 机器上运行的机器人,最近我买了一个 Ubuntu 虚拟服务器。在经历了一系列类似无限的错误之后,我完全重置了服务器并从头开始重试。您可以在此处查看我之前的一些错误的另一篇文章:https://stackoverflow.com/questions/63310926/no-pg-hba-conf-entry-for-host-connect-call-failed-invalid-data-directory-for?noredirect=1#comment111984138_63310926

所以现在当我尝试启动我的机器人时,它给了我这个错误:

Traceback (most recent call last):
  File "bot.py", line 950, in <module>
    bot.loop.run_until_complete(create_db_pool())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "bot.py", line 160, in create_db_pool
    bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???')
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/pool.py", line 398, in _async__init__
    await self._initialize()
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/pool.py", line 426, in _initialize
    await first_ch.connect()
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/pool.py", line 125, in connect
    self._con = await self._pool._get_new_connection()
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/pool.py", line 468, in _get_new_connection
    con = await connection.connect(
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/connection.py", line 1718, in connect
    return await connect_utils._connect(
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/connect_utils.py", line 663, in _connect
    con = await _connect_addr(
  File "/usr/local/lib/python3.8/dist-packages/asyncpg/connect_utils.py", line 642, in _connect_addr
    await asyncio.wait_for(connected, timeout=timeout)
  File "/usr/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
    return fut.result()
asyncpg.exceptions.InvalidAuthorizationSpecificationError: Peer authentication failed for user "postgres"

但数据库、用户和密码都是正确的。它现在仍在运行,因为机器人正在我的 Windows 机器上运行,这就是为什么我认为这是 Ubuntu 特有的问题。我的监听地址设置为“

listen_addresses = '*'

并且我的 pg_hba.conf 设置为:

# TYPE  DATABASE        USER            ADDRESS             METHOD

# IPv4 local connections:
host    all             all             0.0.0.0/0            md5
# IPv6 local connections:
host    all             all             ::/0                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host    replication     all             0.0.0.0/0            md5
host    replication     all             ::/0                 md5

它曾经有默认 IP,但我尝试使用密码打开它以进行任何连接,但 Ubuntu 服务器仍然无法连接到它。另外,目前我的 Ubuntu 系统上似乎没有这个文件。我可以从我的 Windows 机器上编辑它,但我不知道这是否会影响两者。我不完全了解数据库,但我很确定它由我自己的 PC 托管?我也可以将文件本身手动带到 Ubuntu 服务器,但我不想再把事情搞砸,甚至陷入更困境。更改hostlocal似乎只会使数据库在我的 Windows 机器上停止工作。

我被这个问题困扰了很长时间,不知道该怎么办。我真的希望有人知道这个问题,希望我已经提供了足够的信息。谢谢。

相关内容