postgresql - 如何允许在本地连接上没有密码提示的情况下登录 postgres?

标签 postgresql

如何配置 PostgreSQL 以允许默认的 postgres 用户从本地主机无密码登录?

还有几个类似的问题,比如thisthis ,但是修改 pg_hba.conf 的建议对我都没有用。但是,根据我对 pg_hba.conf 规则的理解,我应该能够使用 peertrust 选项来完成此操作。

我正在尝试运行如下命令:

sudo psql --user=postgres --no-password --command="blah;" -h 127.0.0.1

如果我在我的 pg_hba.conf 中尝试这一行:

local   all             postgres                                trust

我的命令因错误而失败:

psql: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", SSL on
FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", SSL off

如果我尝试这一行:

local   all             postgres                                peer

我的命令因同样的错误而失败。

我该如何解决这个问题?

最佳答案

当您指定 -h 127.0.0.1 时,不是“本地”连接 - 它是主机(=基于 TCP)连接。因此,以 local 开头的行将不匹配此类连接。

要使该条目有效,请psql 指定主机名或端口,然后它将通过命名管道使用“本地”连接。

或者,您可以使用 host local,然后将 127.0.0.1 作为(客户端)IP 地址添加到“信任”。

关于postgresql - 如何允许在本地连接上没有密码提示的情况下登录 postgres?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46736894/

相关文章:

sql - rails 种子 : How to truncate DB table?

sql - 针对 jsonb 数组中的特定对象

java - 在jpql中使用 "similar to"或 "~*"

python - 将带有 jsonb_each 的 Postgresql 查询转换为 sqlalchemy

java - JDBC executeBatch() 在 PostgreSQL 中无错误地挂起

sql - 如何连接两个表,同时删除一个表的一列中的重复条目

postgresql - 为什么我的Flask服务器无法使用docker-compose与postgres数据库对话?

database - 创建一个包含其他类型的自定义 PostgreSQL 类型?

postgresql - 在 docker 和 OSX 中保存 PostgreSQL 数据

postgresql - postgres 中排除约束的要点