I have a PgBouncer
installed on the same host with postgres server and I have several scenarios for it:
- Monitoring(
pgwatch2
) should connect withpeer
authentication to thepostgres
(for example) database viaPgBouncer
- External client connection should also be able connect to the database postgres via
PgBouncer
(withhost
authentication method)
I can’t understand how to properly configure PgBouncer
to follow the rules:
- If the connection to
PgBouncer
is done via socket, it should proceed withpeer
authentication to the postgres server - If the connection uses the
host
authentication method,PgBouncer
should also connect to postgres server with the correspondinghost
method
My current configuration is as follows, but it doesn’t choose socket or localhost properly(sometimes it fails):
[databases]
* = host=localhost port=5432
* = host=/tmp port=5432
I added two different rules to fix my issues, but it doesn’t seem to work as expected.
2
Answers
Use a different database user for the monitoring system, and create a special one-session pool for it. If your monitoring system is smart enough to keep the database connection open, do without pgBouncer and let the monitoring system connect to the database directly.
I think that you can’t distinguish pools based on the incoming connection type. You could create a fake database entry, and then direct it to the real database in the config:
But in this case the peer authentication would be coming from the owner of the pgbouncer process, not from the owner of the monitoring client.