no pg_hba.conf entry for host / Connect call failed / Invalid data directory for cluster 12 main - Postgresql Ubuntu

丶灬走出姿态 提交于 2021-01-29 15:40:28

问题


I'm trying to move my bot to an Ubuntu virtual server from Vultr but it's having a problem connecting to the postgres database. I've tried editing the config from md5 to true, and host to local, etc. But those only give me different errors and also make it stop working on my original machine too. It's working perfectly fine on my Windows machine. Here is the error I'm facing:

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

So I've tried to change this line:

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

to this:

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

and that gives me this error:

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

So I don't know what else to try. I've been stuck on this for a while. If it's relevant, it connects at the bottom of the bot.py file like this:

bot.loop.run_until_complete(create_db_pool())

Whether ssl is True or not, the database seems to still function on my Windows machine. But I can't get it to work on my Ubuntu virtual server.

If I edit my config to this:

# 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

Then I get a call error like this:

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

This is really driving me crazy. I have no idea what to do. I bought this virtual server to host my bot on but I can't even get it to connect to the database.

When I simply type psql in the terminal, I get this error:

Error: Invalid data directory for cluster 12 main

Postgres is not working as intended in basically any way. I'm using Vultr.com to host the Ubuntu server, if that matters. And connecting with PuTTy.


回答1:


Your pg_hba.conf has multiple syntax errors. The "localhost" connection type is not allowed at all, and the "local" connection type does not accept an IP address field. The server would refuse to start/restart with the file you show, and if you try to reload a running server it will just keep using the previous settings.

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


来源:https://stackoverflow.com/questions/63310926/no-pg-hba-conf-entry-for-host-connect-call-failed-invalid-data-directory-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!