我安装了全新的 ubuntu 10.10,其中包含所有更新和 postgresql 8.4
为了让 postgresql 接受登录名+密码连接,我通过以下方式配置了它:
sudo su postgres
psql
ALTER USER postgres WITH PASSWORD 'password';
CREATE DATABASE myapp;
\q
exit
sudo vi /etc/postgresql/8.4/main/pg_hba.conf
change "local all all indent" to "local all all trust"
但是,令人惊讶的是,这不起作用!命令
psql -U postgres password
计算错误:
psql: FATAL: Ident authentication failed for user "postgres"
有什么提示可以让 psql -U
正常工作吗?
最佳答案
为“postgres”用户保留身份验证可能是个好主意。默认情况下,我相信 Ubuntu 使用“postgres”用户来执行升级、备份等,这要求它能够在没有指定密码的情况下登录。
我建议创建另一个用户(可能使用您自己的用户名)并赋予其管理员权限。然后您可以在本地连接上使用该用户和密码。
这是我的 pg_hba.conf 的相关部分:
# allow postgres user to use "ident" authentication on Unix sockets
# (as per recent comments, omit "sameuser" if on postgres 8.4 or later)
local all postgres ident sameuser
# allow all other users to use "md5" authentication on Unix sockets
local all all md5
# for users connected via local IPv4 or IPv6 connections, always require md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
另请注意,psql -U postgres password
不会执行您想要的操作。绝不能在命令行中指定密码。这将尝试以用户“postgres”身份登录名为“password”的数据库。
您应该改用 psql -U postgres myapp
。如果 Postgres 正确配置为需要密码,它将自动提示您输入密码。
如果我们希望自动填写密码,place it in $HOME/.pgpass file
关于postgresql - 如何配置 postgresql 使其接受登录名+密码身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4328679/