[英]Postgresql psql: error: FATAL: Peer authentication failed for user "userrole"
[英]PostgreSQL - Peer authentication failed for user “postgres”
我有一個在我的 Windows 機器上運行的機器人,我最近購買了 Ubuntu 虛擬服務器。 在一系列類似的無限錯誤之后,我只是完全重置服務器並從頭開始重試。 您可以在這里查看我以前的一些錯誤的另一篇文章: 主機沒有 pg_hba.conf 條目/連接調用失敗/集群 12 主的數據目錄無效 - Postgresql Ubuntu
所以現在當我嘗試啟動我的機器人時,它給了我這個錯誤:
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 = '*'
本地 windows 服務器上的 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
我在 Ubuntu 服務器上的 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 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
如果我將第一行從peer
更改為md5
,我會得到:
asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "postgres"
並更改為trust
表示沒有數據庫xxx
,這是我本地 Windows 機器上的數據庫。 打字ps ax | grep postgres
ps ax | grep postgres
顯示:
9929 ? Ss 0:02 /usr/lib/postgresql/12/bin/postgres -D /var/lib/pos tgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf
9931 ? Ss 0:00 postgres: 12/main: checkpointer
9932 ? Ss 0:01 postgres: 12/main: background writer
9933 ? Ss 0:01 postgres: 12/main: walwriter
9934 ? Ss 0:01 postgres: 12/main: autovacuum launcher
9935 ? Ss 0:01 postgres: 12/main: stats collector
9936 ? Ss 0:00 postgres: 12/main: logical replication launcher
21821 pts/0 S+ 0:00 grep --color=auto postgres
我已經堅持了很長時間,我不知道該怎么做。 我真的希望有人知道這個問題,我希望我已經提供了足夠的信息。 謝謝你。
我認為它試圖連接到 Ubuntu 服務器上的數據庫,而不是我的 Windows 機器上的數據庫。 如何使其針對 Windows 機器?
client.pg_con = await asyncpg.create_pool(database=database, user=user, password=password, host="127.0.0.1")
也添加 host="127.0.0.1" ,這解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.