3

I've created a new role and Database in the following way (with postgres user):

CREATE ROLE xxx LOGIN
  PASSWORD 'CHOOSEAPASSWORD'
  NOSUPERUSER INHERIT NOCREATEDB CREATEROLE REPLICATION;

CREATE DATABASE xxx
  WITH OWNER = xxx
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       CONNECTION LIMIT = -1;

\connect xxx
GRANT ALL ON DATABASE xxx TO xxx;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO xxx;

In the pg_hba.conf I've the following entries:

local   all             postgres                                trust
local   all             all                                     peer
# IPv4 local connections:
host    all             xxx             127.0.0.1/32            trust
host    all             all             127.0.0.1/32            ident

Nevertheless I can't connect with

psql -U xxx -h localhost -W

and get the error

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

Any ideas where I could have a mistake? (I use PostgreSQL 9.4 and CentOS 6.7)

Benedikt Bock
  • 1,007
  • 15
  • 37

2 Answers2

4

Try to use 127.0.0.1 instead of localhost

despotbg
  • 740
  • 6
  • 12
3

You haven't defined a rule for IPv6's localhost address ::1. Your host's resolver prefers the IPv6 address ::1 to the IPv4 address 127.0.0.1. So the IPv4 rule with trust never gets matched.

Add another rule for ::1

Another common issue, though already ruled out for you, is not having reloaded the config.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778