我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。

我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:

psql: FATAL:  Ident authentication failed for user "postgres"

现在有人知道如何解决这个问题吗?


当前回答

这招对我很管用: http://tecadmin.net/fatal-ident-authentication-failed-for-user-postgres/#

local   all             postgres                                trust
local   all             myapp_usr                               trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
#host    all             all             ::1/128                 trust

其他回答

对于Windows,如果您不想编辑pb_gba.conf,即保留MD5方法(默认),请在PGadmin的查询工具中运行此查询,创建一个新用户

CREATE USER admin WITH PASSWORD 'secret'

然后在CMD中

psql "dbname=Main_db host=127.0.0.1 user=admin password=secret port=5432

哪里dbname是你的db在postgresql

我花了更多的时间来解决这个我愿意承认的错误。

我认为pg_hba.conf中的身份验证配置顺序与您的情况相关。默认配置文件在普通安装中包含几行。这些默认值可以匹配身份验证尝试的条件,从而导致身份验证失败。不管在.conf文件末尾添加了什么额外的配置,它都会失败。

要检查使用的是哪一行配置,请确保查看消息的默认日志文件。你可能会看到这样的东西

LOG:  could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL:  Ident authentication failed for user "acme" 
DETAIL:  Connection matched pg_hba.conf line 82: "host     all             all             127.0.0.1/32            ident"

结果是这条默认行导致了拒绝。

host    all             all             127.0.0.1/32            ident

试着把它注释掉。

在Ubuntu 12.04中为Rails开发设置PostgreSQL之后,我也遇到了同样的问题

我尝试了其他答案,但我所要做的就是:“config/database.yml”

development:
  adapter: postgresql
  encoding: unicode
  database: (appname)_development
  pool: 5
  username: (username you granted appname database priviledges to)
  password:

我在Mac OSX的PostgreSQL 9.3上的解决方案是在bash shell中使用sudo进入数据文件夹,然后将必要的行追加到pg_hba.conf文件,以允许所有用户都是可信的,并能够登录。这就是我所做的:

# in bash_profile edit PGDATA environmental variable
open ~/.bash_profile

# append this line to bash_profile
export PGDATA="/Library/PostgreSQL/9.3/data"

# reload bash_profile
source ~/.bash_profile

# open pg_hba.conf in vim
sudo vi /Library/PostgreSQL/9.3/data/pg_hba.conf

# append these two lines to the end of the pg_hba.conf file
local   all   all                  trust
host    all   all   127.0.0.1/32   trust

# can now login as user in bash
psql -d <db_name> -U <user_name> -W

解决这个问题的一个方法是编辑pg_hba.conf

sudo vi /etc/postgresql/9.3/main/pg_hba.conf

暂时

# Database administrative login by Unix domain socket
local   all             postgres                                   trust

至此,您就完成了。为了安全,那就去吧

sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';

然后返回,将pg_hba.conf设置为

# Database administrative login by Unix domain socket
local   all             postgres                                   md5