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

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

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

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


当前回答

我只需要简单地添加-h localhost位就可以工作了

其他回答

您得到这个错误是因为您没有通过客户端身份验证。根据错误消息,您可能有默认的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的位置取决于操作系统。

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

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

在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:

在以上所有的答案中,没有一个对我有用。我不得不手动更改数据库中的用户密码,它突然工作了。

psql -U postgres -d postgres -c "alter user produser with password 'produser';"

我使用了以下设置:

pg_hba.conf

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

以下命令连接成功:

psql -U produser -d dbname -h localhost -W 

关于PostgreSQL安装的配置问题:

在下面提到的conf文件中配置# TYPE数据库用户地址方法部分

查找并编辑/var/lib/pgsql/10/data/pg_hba.conf或根据您的文件位置更新方法(md5)。如果你的配置中不存在,更新文件中的条目,如下所示:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     trust
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

在下面提到的conf文件中配置连接和验证部分

查找并编辑/var/lib/pgsql/10/data/postgresql.conf或根据您的文件位置 更新监听地址和端口

listen_addresses = '*' // # what IP address(es) to listen on;
                                    # comma-separated list of addresses;
                                    # defaults to 'localhost'; use '*' for all
port = 5432 // Set port as 5432

重新启动PostgreSQL:

sudo systemctl restart postgresql-10 # Update service name based on your installation