If you're using pgbouncer, you'll notice that you can't put a WHERE clause in, which makes tracing down some particular issue on a particular connection more painful than it needs to be.
Enter Peter Eisentraut's
excellent idea
I've taken the liberty of wrapping that up in an
extension, which helps make it operational. Combined with the following simple SSH trick
ssh -fNL 6432:localhost:6432 pgbouncer@pgbouncerhost
you can monitor any pgbouncer you like from any convenient machine that can SSH in, and change the host it's talking to by mapping ports as above. You can also use
ALTER USER MAPPING to adjust credentials if needed.