Search code examples
postgresqlpgadminpgadmin-4

Unable to connect to server: FATAL: Ident authentication failed for user "postgres"


I got message: Unable to connect to server: FATAL: Ident authentication failed for user "postgres" when I tried to create a connection in pgAdmin.

pgAdmin parameters:
-------------------
Hostname/address: localhost
Port: 5432
Maintenance database: postgres
Username: postgres
Password: postgres

The package is install on a Linux machine. I tried web mode and desktop mode, the problem appeared on both.

Below are the setup steps I follow after installing the package:

# vi /opt/pgdata/pg_hba.conf
host    all all all md5

# vi /opt/pgdata/postgresql.conf
listen_addresses = '*'
port = 5432

# postgresql-setup --initdb 
 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

# cp /opt/pgdata/pg_hba.conf /var/lib/pgsql/pg_hba.conf 
# cp /opt/pgdata/postgresql.conf /var/lib/pgsql/postgresql.conf

# systemctl enable postgresql
# systemctl start postgresql

# su - postgres
$ psql postgres
psql (10.6)
Type "help" for help.

  postgres=# \password postgres
  Enter new password: postgres
  Enter it again: postgres
  postgres=# \q

# systemctl stop postgresql
# systemctl start postgresql
# systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) (thawing) since Tue 2022-07-26 21:23:49 EDT; 28min ago
  Process: 40022 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
 Main PID: 40025 (postmaster)
    Tasks: 8 (limit: 72897)
   Memory: 19.3M
   CGroup: /system.slice/postgresql.service
           ├─40025 /usr/bin/postmaster -D /var/lib/pgsql/data
           ├─40026 postgres: logger process   
           ├─40028 postgres: checkpointer process   
           ├─40029 postgres: writer process   
           ├─40030 postgres: wal writer process   
           ├─40031 postgres: autovacuum launcher process   
           ├─40032 postgres: stats collector process   
           └─40033 postgres: bgworker: logical replication launcher   

Jul 26 21:23:49 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.641 EDT [40025] LOG:  listening on IPv6 address "::1", port 5432
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.641 EDT [40025] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.642 EDT [40025] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.645 EDT [40025] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

I can see the status is "active (running) (thawing) since Tue 2022-07-26 21:23:49 EDT; 28min ago"

is that normal?

How to connect to the instance successfully?


Solution

  • There's a copy of pg_hba.conf under: /var/lib/pgsql/data which is the actual version used by the instance. Put the configuration in this file resolved the issue