prometheus-community/pgbouncer_exporter

Container with pgbouncer_exporter fails immediately after start with "error setting up DB connection"

Cyber-Cowboy opened this issue · 2 comments

Full error text is following:
ts=2024-02-14T13:27:09.475Z caller=collector.go:138 level=error msg="error setting up DB connection" err="error pinging pgbouncer: dial tcp 127.0.0.1:5432: connect: connection refused"
PG bouncer Exporter container is configured like that:

pgbouncer-exporter:
    image: prometheuscommunity/pgbouncer-exporter
    env_file: .env
    depends_on:
      - db
    expose:
      - "9127"
    command: --pgBouncer.connectionString=${PGBOUNCER_EXPORTER_CONNECTION_STRING}
    deploy:
      placement:
        max_replicas_per_node: 1
        constraints:
          - "node.role == manager"
    networks:
      - backend

Where PGBOUNCER_EXPORTER_CONNECTION_STRING is like that:
postgres://user:password@db:5432/pgbouncer?sslmode=disable

As I understand pgbouncer for some reason is trying to connect on 127.0.0.1 even though it should connect to db through docker network. What should I do to fix that?

I get a similar error, for example if pgbouncer_exporter is started before pgbouncer is up:

ts=2024-05-06T13:48:14.237Z caller=collector.go:142 level=error msg="error setting up DB connection" err="error pinging pgbouncer: dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory"

In my case I'm connecting using domain sockets. I'd expect pgbouncer_exporter to retry connecting a bit later, instead of exiting the process.

I am also getting a similar issue

prometheus-pgbouncer-exporter_1 | ts=2024-05-20T12:53:46.279Z caller=collector.go:142 level=error msg="error setting up DB connection" err="error pinging pgbouncer: dial tcp 127.0.0.1:6543: connect: connection refused"