1

On an admin dashboard page of a PHP web application, I would like to display details about the database connection. Depending on the local setup, the connection may be direct, or it may be brokered by PgBouncer. Is it possible to detect exactly what I'm connecting to? This information could be useful for debugging.

Checking the default ports (6432 vs 5432) is possible but obviously unreliable. Does PgBouncer inject anything into the connection that would help differentiate it from a direct connection?

Zilk
  • 8,917
  • 7
  • 36
  • 44

2 Answers2

1

There is no direct way. Pgbouncer does not populate this info in pg_stat_activity.application_name or somewhere else. Of course you will see IP of the machine where you run pgbouncer in pg_stat_activity.client_addr, but it won't mean it is pgbouncer for sure. One way to bond pg_stat_activity with show clients command of pgbouncer together - this way you know the source of a query, I described this in another post here: Find source of query through pgbouncer But still it would require later bond of php sql process pid with all together to see the connection.

Also - php can consume both connections (any amount) so theoretically you need to check each statement on how it connects.

Community
  • 1
  • 1
Vao Tsun
  • 47,234
  • 13
  • 100
  • 132
1

Perhaps an alternative would be to use different access credentials based on your 'local setup'? Connections configured through pgbouncer could use a different username/password to those that go direct. This would allow you to differentiate the connections. Obviously depends on your local setup of course whether that is possible.

GreensterRox
  • 6,432
  • 2
  • 27
  • 30