Skip to content

New server_reset_query_always default introduces non-deterministic behavior. #110

@sbranchaw

Description

@sbranchaw

Context: PgBouncer 1.7 changes the default of server_reset_query_always to 0, causing the server_reset_query to not take effect for transaction pooling.

According to the documentation, "When transaction pooling is used, the server_reset_query should be empty, as clients should not use any session features. If client does use session features, then they will be broken as transaction pooling will not guarantee that next query will be run on same connection."

I don't follow this argument. This may be true of statement pooling, but if you change a setting such as search_path or statement_timeout within a transaction, the changes are guaranteed to apply to the rest of the queries in that transaction. This is useful functionality, not something I would call broken.

As long as DISCARD ALL guarantees that all connections revert to a pristine state before returning to the pool, all behavior remains deterministic, in that the values of all settings within a transaction are controlled only by statements run within that transaction, plus the regular database configuration (per-user, per database, per-cluster, etc.).

Only if server_reset_query is left empty does the system enter what I would call a broken state: the values of settings are nondeterministic, governed by an unpredictable combination of all database activity since the creation of the connection pool.

For these reasons, I submit that server_reset_query should be set to DISCARD ALL for transaction-based pooling by default.

At the very least, if the new behavior is deemed to fix more than it breaks, could the 1.7 changelog be updated to highlight more clearly what is changing? "Now reset query is used only in pools that are in session mode" requires the reader to look up what reset query does and doesn't come across as "scary" enough to set off the proper alarm bells at the removal of the DISCARD ALL safety net users may have been relying on.

For instance, the Bucardo check_postgres monitoring plugin sets a non-default statement_timeout value. Once the Nagios check has run, other apps connecting to the database risk having a statement_timeout that was not anticipated by the author of those apps.

One could make the case that check_postgres shouldn't connect via pgbouncer, but until now it was safe, and especially since it's a third-party plugin, users might not be aware that it's changing a setting, even if they're confident their own code doesn't change any settings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions