使用密码进行PostgreSQL身份验证

时间:2013-10-27 14:33:59

标签: database linux postgresql authentication

我使用PostgreSQL 9.2并拥有命令:

psql -h localhost -U testdb -d postgis

此命令可以在没有密码的情况下连接数据库。我想输入密码。

我的pg_hba.cconf是:

local   all             all                                     password
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

1 个答案:

答案 0 :(得分:1)

无密码访问要求相应地配置多个authentication methods中的一个。这些相关答案的更多细节:
pgadmin gives me the error: no password supplied
Run batch file with psql command without password

特别是,localhost不是第二个pg_hba.conf文件中的“本地连接”。由于您与-h localhost相关联,因此只有host文件中以pg_hba.conf开头的行才适用,因此需要输入密码。

剩下的解释:

  • You did not reload因为配置文件已更改。

  • 您没有显示正确(或完整)pg_hba.conf(或无意中连接到错误的数据库集群。端口5432?),实际上有一行peer或{其他ident行之前的{1}}身份验证。

  • 您的安装具有.pgpass file,用于授予您运行该命令的系统用户的访问权限。有关详细信息,请参阅the second linked answer

最后一个似乎很有可能。

相关问题