我的印象是,Postgres 使用了一些本地套接字魔法来允许本地用户无需密码即可访问 postgres,而传递 host ( -h
) 选项将强制它使用 TCP,从而提示输入密码。事实似乎并非如此:
$ command psql -h 127.0.0.1 -W -U sim mydb
Password:
Timing is on.
Line style is unicode.
Border style is 2.
Null display is "[NULL]".
Expanded display is used automatically.
psql (15.3 (Homebrew))
Type "help" for help.
127.0.0.1 sim@mydb=>
我强制输入密码提示,将 localhost 作为主机,但我仍然可以提供我喜欢的任何密码:我总是能进入。我不确定这里会发生什么,但这不是我所期望的。
我的目的是测试我的密码是否正确,调试一些应用程序错误,因此这种行为没有帮助。
在 macOS 13 上安装自制程序
看看
pg_hba.conf
。它大概有这样的东西:或这个:
只要有一个名为
sim
:peer
让名为 connect 的 MacOS 用户sim
,并且trust
sim
无论如何,让我们连接。摘自pg_hba.conf 的文档:
使用 Homebrew 时的典型位置
pg_hba.conf
: