I have pgbouncer running locally with config:

* = host=myremoteIP port=5432 user=postgres
listen_addr = *
listen_port = 6432

When I connect using pgsql using:

psql -h -p 6432 -U postgres -W

I receive an error:

psql: ERROR: pgbouncer cannot connect to server

/var/log/pgbouncer/pgbouncer.log contains the following:

WARNING Cannot listen on unix:/var/run/postgresql/.s.PGSQL.6432: bind(): Permission denied

Disabling the firewall on the local and remote machines still results in the same error.

What configuration am I missing?

  • Checking your permission on /var/run/postgresql/. – Luan Huynh May 22 '18 at 9:56
  • @LuanHuynh it was 755. I've changed to 777 and now get: FATAL @src/system.c:113 in function change_file_mode(): chown(/var/run/postgresql/.s.PGSQL.6432, -1, 26) failed: Operation not permitted – Owen Pauling May 22 '18 at 10:15
  • Which Linux distro are you using? It might have AppArmor or SELinux – Philᵀᴹ May 22 '18 at 10:45
  • Please check how many psql client in your machine. Then, check pidfile param in /etc/pgbouncer/pgbouncer.ini – Luan Huynh May 22 '18 at 11:22

The error message in the log was a red herring, and due to the configuration for Unix sockets (when I only needed TCP). Disabling Unix sockets by setting the unix_socket_dir to an empty string (as per the documentation) made those errors disappear from the logs.

The connection problem was because I needed to specify the password in the pgbouncer.ini file.

The line:

* = host=myremoteIP port=5432 user=postgres

Needed to be:

* = host=myremoteIP port=5432 user=postgres password=mypassword

I can now connect using psql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.