Skip to content

pgbouncer: expose server_reset_query_always as an inventory parameter (hardcoded to 0 in pgbouncer.ini template) #788

Description

@jotacampos

Summary

roles/pgsql/templates/pgbouncer.ini hardcodes

server_reset_query_always   = 0

There is no inventory parameter to change it (unlike pgbouncer_poolmode, pgbouncer_sslmode, pgbouncer_ignore_param, …). Any change made on the nodes is reverted the next time pgsql.yml renders the config.

Why it matters

With pgbouncer_poolmode: transaction (the default), PgBouncer only runs server_reset_query (DISCARD ALL) between sessions. Server connections are reused between transactions of different clients while still carrying their session state. We hit two problems with a schema-per-tenant application:

  1. Session state leaks between clients. A session-level SET search_path from one client stays on the server connection and is inherited by the next client, which then resolves unqualified tables in another schema.
  2. Shared prepared statements break when schemas differ. With max_prepared_statements > 0, PgBouncer reuses a server-side prepared statement across clients by query text. When the same query runs under a different search_path, and a result column's type differs between schemas (for example a per-schema enum), PostgreSQL fails with ERROR 0A000: cached plan must not change result type. In our load test about 40% of requests failed this way, even after the application stopped setting session-level state.

server_reset_query_always = 1 fixes both (0 errors in the same test). The cost is more Parse traffic on the server.

Request

Expose it as an inventory variable, for example:

pgbouncer_reset_query_always: false   # default keeps today's behaviour
server_reset_query_always   = {{ 1 if pgbouncer_reset_query_always|default(false)|bool else 0 }}

The default would stay the same, so nothing changes for existing clusters. Deployments running multi-schema or session-state-sensitive applications behind transaction pooling could turn it on without patching the role template.

Version: Pigsty v4.3.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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