Since pgbouncer is a connection pooler, it will reuse one actual connection to the database server for potentially many client connections. It has to make sure that whatever session state the first client created is reset when the next client gets the connection. Otherwise the first client might do something like
SET statement_timeout = '5min', and that would apply to all subsequent clients who happen to be assigned that connection. To avoid that, pgbouncer issues the "server reset query" before handing out the server connection to a new client. As the documentation says
A good choice for Postgres 8.2 and below is:
server_reset_query = RESET ALL; SET SESSION AUTHORIZATION DEFAULT;
for 8.3 and above its enough to do:
server_reset_query = DISCARD ALL;
The main reason this setting exists is that the
DISCARD ALL statement, which was invented for this very purpose, was not available before PostgreSQL 8.3.
The setting applies independently of the pool mode. Note that the client could issue a
SET statement or something like that in any pool mode.
The documentation also says
When transaction pooling is used, the
server_reset_query should be empty, as clients should not use any session features.
I think this is a faith-based approach. If you think your code is clean and you need the extra performance, go for it. I've been bitten by this, though. For example, if you use check_postgres to monitor your pgbouncer connections, it will issue a
SET statement_timeout like I showed above and mess up your connections.