错误:用户身份验证失败

7 postgresql centos node.js pgadmin

我无法通过 Nodejspg模块连接 postgres 或者pgAdmin3\n下面是我的配置和错误消息,我找不到如何修复

\n\n

用户、密码、角色权限、数据库创建

\n\n
su - postgres\n\npsql\n\nALTER USER db_admin WITH PASSWORD \xe2\x80\x98aaee11\xe2\x80\x99;\n\nALTER ROLE db_admin SUPERUSER CREATEDB CREATEROLE;\n\n\nCREATE DATABASE \xe2\x80\x9ctestdb\xe2\x80\x9d WITH OWNER = db_admin ENCODING = \'UTF8\' TABLESPACE = pg_default LC_COLLATE = \'en_GB.UTF-8\' LC_CTYPE = \'en_GB.UTF-8\' CONNECTION LIMIT = -1 TEMPLATE template0;\n
Run Code Online (Sandbox Code Playgroud)\n\n

听所有

\n\n
vi /var/lib/pgsql/9.4/data/postgresql.conf\n\n#listen_addresses = \'localhost\'\nlisten_addresses = \'*\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

重新开始

\n\n
service postgresql-9.4 restart\n
Run Code Online (Sandbox Code Playgroud)\n\n

nodejs pg 连接和错误消息

\n\n
var conString = \'postgres://db_admin: aaee11@localhost/testdb\';\nvar dbClient = new pg.Client(conString);\ndbClient.connect(function(error) {\n  if (error) {\n    console.log(error);\n  }\n});\n\n[root@li61-123 app]# node --harmony app.js staging\nExpress server listening on port 8002\n{ [error: Ident authentication failed for user "db_admin"]\n  name: \'error\',\n  length: 94,\n  severity: \'FATAL\',\n  code: \'28000\',\n  detail: undefined,\n  hint: undefined,\n  position: undefined,\n  internalPosition: undefined,\n  internalQuery: undefined,\n  where: undefined,\n  schema: undefined,\n  table: undefined,\n  column: undefined,\n  dataType: undefined,\n  constraint: undefined,\n  file: \'auth.c\',\n  line: \'285\',\n  routine: \'auth_failed\' }\n
Run Code Online (Sandbox Code Playgroud)\n\n

pg_hba.conf 配置

\n\n
vi /var/lib/pgsql/9.4/data/pg_hba.conf\n\n# TYPE  DATABASE        USER            ADDRESS                 METHOD\n\n# "local" is for Unix domain socket connections only\nlocal   all             all                                     peer\n# IPv4 local connections:\nhost    all             all             127.0.0.1/32            ident\n# IPv6 local connections:\nhost    all             all             ::1/128                 ident\n# Allow replication connections from localhost, by a user with the\n# replication privilege.\n#local   replication     postgres                                peer\n#host    replication     postgres        127.0.0.1/32            ident\n#host    replication     postgres        ::1/128                 ident\n
Run Code Online (Sandbox Code Playgroud)\n\n

更新

\n\n

编辑后将pg_hba.conf所有方法切换为 md5 ,它可以在 NodeJS 中连接,但在 pgadmin 中仍然无法显示如下错误消息:

\n\n
Server doesn\'t listen\nThe server doesn\'t accept connections: the connection library reports \ncould not connect to server: Operation timed out Is the server running on host "xx.xxx.xxx.xxx" and accepting TCP/IP connections on port 5432? \nIf you encounter this message, please check if the server you\'re trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly? \nFor security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first. \nFor PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use \'*\' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you\'ll need to set the "tcpip_socket" parameter to \'true\'. \nYou can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart \n
Run Code Online (Sandbox Code Playgroud)\n\n

管理管理员

\n\n
[Properties]\nName: xx.xxx.xxx.xxx\nHost: xx.xxx.xxx.xxx\nPort: 5432\nMaintenance: postgres\nUsername: db_admin\nPassword: ........\n
Run Code Online (Sandbox Code Playgroud)\n

Dmi*_*kov 5

根据 Postgresql pg_hba.conf 文档 identauth-method 如下:

通过联系客户端上的ident服务器获取客户端的操作系统用户名,并检查是否与请求的数据库用户名匹配。身份验证只能在 TCP/IP 连接上使用。当为本地连接指定时,将使用对等身份验证。

您需要切换到md5,然后在 psql 中运行select pg_reload_conf();或重新启动 postgres 服务。