如何配置postgresql以便它接受登录+密码验证?

时间:2010-12-01 20:17:52

标签: postgresql ubuntu

我有一个新的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起作用?

3 个答案:

答案 0 :(得分:41)

将“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

答案 1 :(得分:2)

我认为您的pg_ident.conf文件配置错误。还有,你试过吗

psql -U postgres -W

答案 2 :(得分:0)

可能导致此问题的另一件事是过期的凭据。我不认为这发生在版本8中,但是在版本9中,当您在pgadmin中创建新角色时,它是在过期状态下创建的,您需要更改或清除角色的过期日期才能登录它