Failed to connect to docker container running Postgres via pgbouncer

32 views Asked by At

Trying to create connection pool using pgbouncer. Here is the docker-compose.yml file.

version: '3'
services:

  db:
    image: postgres:12
    volumes:
      - pg_data:/var/lib/postgresql/data
      - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=pass

  pgbouncer:
    image: edoburu/pgbouncer
    environment:
      - DB_USER=postgres
      - DB_PASSWORD=pass
      - DB_HOST=db
      # - DB_NAME=test
      # for postgres:14 and above
      - AUTH_TYPE=scram-sha-256 
      - POOL_MODE=transaction
      - ADMIN_USERS=postgres,dbuser
    ports:
      - "5432:5432"
    depends_on:
      - db

volumes:
  pg_data:

These two containers are running fine. But but when I try to connect to postgres via pgbouncer, it throws an error:

$ psql -h localhost -p 5432 -U postgres 
Password for user postgres: 
psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL:  password authentication failed for user "postgres"

In logs I see this:

compose-db-1         |  Connection matched pg_hba.conf line 99: "host all all all md5"
compose-pgbouncer-1  | 2024-03-29 02:19:45.445 UTC [1] WARNING C-0x7f3475c6f3a0: postgres/[email protected]:59276 pooler error: password authentication failed for user "postgres"
compose-pgbouncer-1  | 2024-03-29 02:19:45.445 UTC [1] LOG S-0x7f3475c193c0: postgres/[email protected]:5432 closing because: login failed (age=0s)

What the issue?

0

There are 0 answers