The log message you shared is not due to some error with a query. Rather, it is due to a pgbouncer client session that is waiting for a server connection, but that wait took more than 2 minutes. In other words, all real-connections in a pool have been used, and some session was waiting around for 2 minutes to get an opportunity to run a query on the database. There could be a number of factors causing this situation:
- Session-level pooling -- you may have several pgbouncer sessions that get real connections to the database, but are idle and never releasing a connection back to the pool. Then, the newest session just waits around and never gets a chance to run its query (and
query_wait_timeout
happens, and the new pgbouncer session is booted)
- Transaction-level pooling, pool size too small -- you may just have a lot of connections from applications and they spend a lot of time running a transaction, such that any new sessions are stuck waiting around for the transactions to finish, but 2 minutes was not enough time.
query_wait_timeout
too small -- you might just have lots of long-running queries (check pg_stat_activity
for any old queries that are still running, or for idle transactions)
There may be a few other possible reasons for what you're seeing, but these are just a few that came to mind.