【发布时间】:2020-09-05 13:09:25
【问题描述】:
我完全无法访问 postgres 中的任何内容,因为它要求输入默认 postgres 用户和我的 mac 用户名的密码。我都没有密码,对于postgres,我什至不明白为什么有密码,因为默认情况下它不应该有密码。
在浏览了有关该主题的许多其他答案之后:
如果我运行psql:
$ psql
Password for user <MY_USERNAME>:
psql: error: could not connect to server: FATAL: password authentication failed for user "<MY_USERNAME>"
如果我使用sudo 运行它:
$ sudo psql
Password for user root:
psql: error: could not connect to server: FATAL: password authentication failed for user "root"
如果我使用postgres 用户运行它:
$ sudo -u postgres psql
Password for user postgres:
psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"
另外在我的pg_hba.conf所有方法都设置为trust,也试过改成ident和md5。
根据@jjanes 的建议,我搜索了其他pg_hba.conf 文件,这就是我发现的:
/usr/local/var/postgres.old/pg_hba.conf
/usr/local/var/postgres/pg_hba.conf
/usr/local/var/postgresql@10/pg_hba.conf
/Library/PostgreSQL/12/data/pg_hba.conf
最后一个是空的(并且是只读的),其他三个都是这样的:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
有人有什么建议吗?
【问题讨论】:
-
听起来您正在查看错误的 pg_hba.conf 文件。如果该方法确实设置为 trust 或 ident,您将不会收到该错误消息。
-
@jjanes 所以它在 /usr/local/var/postgres 但我也有一些 Postgres 文件存储在 /usr/local/Cellar/postgresql/12.1 中,由 homebrew 提供。我真的不太了解这东西,有没有可能是问题所在?
-
我还检查了那个目录,有一个 pg_hba.conf.samlple 文件,但就是这样
-
*.sample 文件不是那个。可能 postgresql.conf 为要使用的 HBA 文件设置了一个不同于 pg_hba.conf 的名称,但这不太可能。你可以使用 Linux 的
find命令之类的工具来搜索系统上的任何 pg_hba.conf 吗? -
我正要上飞机,但我会在另一边检查一下,看看我的系统上是否还有其他 pg_hba.conf 苍蝇。谢谢
标签: postgresql