0

我正在尝试将我的机器人从 Vultr 移动到 Ubuntu 虚拟服务器,但在连接到 postgres 数据库时出现问题。我已经尝试将配置从 md5 编辑为 true,并将主机编辑为本地等。但这些只会给我不同的错误,也让它停止在我原来的机器上工作。它在我的 Windows 机器上运行良好。这是我面临的错误:

asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host "[local]", user "postgres", database "xxx", SSL off

所以我试图改变这一行:

async def create_db_pool():
    bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???')

对此:

async def create_db_pool():
    bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???', ssl=True)

这给了我这个错误:

asyncpg.exceptions._base.InterfaceError: `ssl` parameter can only be enabled for TCP addresses, got a UNIX socket path: '/run/postgresql/.s.PGSQL.5432'

所以我不知道还能尝试什么。我已经坚持了一段时间。如果相关,它将连接到 bot.py 文件的底部,如下所示:

bot.loop.run_until_complete(create_db_pool())

无论 ssl 是否为 True,数据库似乎仍在我的 Windows 机器上运行。但我无法让它在我的 Ubuntu 虚拟服务器上运行。

如果我将配置编辑为此:

# 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

然后我收到这样的调用错误:

OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 5432, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 5432)

这真的让我发疯。我不知道该怎么做。我购买了这个虚拟服务器来托管我的机器人,但我什至无法让它连接到数据库。

当我简单地psql在终端中输入时,我得到了这个错误:

Error: Invalid data directory for cluster 12 main

Postgres 基本上没有按预期工作。我正在使用 Vultr.com 来托管 Ubuntu 服务器,如果这很重要的话。并与 PuTTy 连接。

4

1 回答 1

0

您的 pg_hba.conf 有多个语法错误。根本不允许“localhost”连接类型,“local”连接类型不接受 IP 地址字段。服务器将拒绝使用您显示的文件启动/重新启动,如果您尝试reload运行服务器,它将继续使用以前的设置。

LOG:  invalid connection type "localhost"
CONTEXT:  line 4 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG:  invalid authentication method "127.0.0.1/32"
CONTEXT:  line 5 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG:  invalid authentication method "::1/128"
CONTEXT:  line 9 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG:  invalid connection type "localhost"
CONTEXT:  line 10 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG:  invalid authentication method "127.0.0.1/32"
CONTEXT:  line 102 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
FATAL:  could not load pg_hba.conf
LOG:  database system is shut down
于 2020-08-08T06:36:01.643 回答