Hi everyone,
I’m trying to connect DHIS2 to a PostgreSQL database named test, but I keep running into a connection issue. When I attempt to connect via psql, I get the following error:
paul@tracker:~$ lxc exec postgres – bash
root@postgres:~# psql -U test -d test
psql: error: connection to server on socket “/var/run/postgresql/.s.PGSQL.5432” failed: FATAL: Peer authentication failed for user “test”
Here is some context about my setup:
Containers:
lxc list
±---------±--------±-------------------±-----±----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±---------±--------±-------------------±-----±----------±----------+
| test | RUNNING | 17x.x.x.x (eth0) | | CONTAINER | 0 |
| dhis | RUNNING | 17x.x.x.x (eth0) | | CONTAINER | 0 |
| postgres | RUNNING | 17x.x.x.x (eth0) | | CONTAINER | 0 |
±---------±--------±-------------------±-----±----------±----------+
DHIS2 dhis.conf:
Database connection for PostgreSQL
connection.dialect = org.hibernate.dialect.PostgreSQLDialect
connection.driver_class = org.postgresql.Driver
connection.url = jdbc:postgresql://17x.x.x.x/viva
connection.username = test
connection.password = test123
PostgreSQL databases:
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype
-----------±---------±---------±----------------±--------±--------
test | app | UTF8 | libc | C.UTF-8 | C.UTF-8
postgres | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8
template0 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8
template1 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8
pg_hba.conf:
“local” is for Unix domain socket connections only
local all all peer
IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
IPv6 local connections:
host all all ::1/128 scram-sha-256
Allow replication connections
local replication all peer
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
Custom connection for user ‘test’
host test test 17x.x.x.x/32 scram-sha-256
I suspect this may be related to the authentication method (peer vs scram-sha-256) in PostgreSQL, but I’m not sure how to fix it
Has anyone faced a similar issue connecting DHIS2 to PostgreSQL when using peer authentication, and how did you resolve it?
Thanks in advance for any guidance!