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

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

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

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


当前回答

我有类似的问题,我在pg_hba.conf中修复了它,当删除所有识别方法时,即使是IP6地址(尽管我在机器上只有IP4)。

host all all 127.0.0.1/32 password
host all all ::1/128 password
#for pgAdmin running at local network
host all all 192.168.0.0/24 md5

其他回答

您得到这个错误是因为您没有通过客户端身份验证。根据错误消息,您可能有默认的postgres配置,它将所有PostgreSQL连接的客户端身份验证方法设置为“IDENT”。

你一定要阅读PostgreSQL手册中的19.1节客户端身份验证,以更好地理解可用的身份验证设置(对于pg_hba.conf中的每条记录),但下面是相关的代码片段,以帮助解决你遇到的问题(来自版本9.5手册):

trust Allow the connection unconditionally. This method allows anyone that can connect to the PostgreSQL database server to login as any PostgreSQL user they wish, without the need for a password or any other authentication. See Section 19.3.1 for details. reject Reject the connection unconditionally. This is useful for "filtering out" certain hosts from a group, for example a reject line could block a specific host from connecting, while a later line allows the remaining hosts in a specific network to connect. md5 Require the client to supply a double-MD5-hashed password for authentication. See Section 19.3.2 for details. password Require the client to supply an unencrypted password for authentication. Since the password is sent in clear text over the network, this should not be used on untrusted networks. See Section 19.3.2 for details. gss Use GSSAPI to authenticate the user. This is only available for TCP/IP connections. See Section 19.3.3 for details. sspi Use SSPI to authenticate the user. This is only available on Windows. See Section 19.3.4 for details. ident Obtain the operating system user name of the client by contacting the ident server on the client and check if it matches the requested database user name. Ident authentication can only be used on TCP/IP connections. When specified for local connections, peer authentication will be used instead. See Section 19.3.5 for details. peer Obtain the client's operating system user name from the operating system and check if it matches the requested database user name. This is only available for local connections. See Section 19.3.6 for details. ldap Authenticate using an LDAP server. See Section 19.3.7 for details. radius Authenticate using a RADIUS server. See Section 19.3.8 for details. cert Authenticate using SSL client certificates. See Section 19.3.9 for details. pam Authenticate using the Pluggable Authentication Modules (PAM) service provided by the operating system. See Section 19.3.10 for details.

所以…要解决您正在经历的问题,您可以执行以下操作之一:

Change the authentication method(s) defined in your pg_hba.conf file to trust, md5, or password (depending on your security and simplicity needs) for the local connection records you have defined in there. Update pg_ident.conf to map your operating system users to PostgreSQL users and grant them the corresponding access privileges, depending on your needs. Leave the IDENT settings alone and create users in your database for each operating system user that you want to grant access to. If a user is already authenticated by the OS and logged in, PostgreSQL won't require further authentication and will grant access to that user based on whatever privileges (roles) are assigned to it in the database. This is the default configuration.

注意:pg_hba.conf和pg_identity .conf的位置取决于操作系统。

在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

以防以上方法都不适合你: 我已经安装了不少Postgres,但今天在RedHat 6.5系统上(安装Postgres 9.3)却被搞糊涂了。Aron在上面展示的典型hba.conf配置不起作用。原来我的系统使用的是IPV6,而忽略了IPV4配置。添加一行:

host    all             all             ::1/128                 password

允许我成功登录。

在pg_hba.conf中设置正确了吗?

参见https://ubuntu.com/server/docs/databases-postgresql如何做。