Skip to content

AWS RDS Proxy connection pinning due to automatic charset setting for PostgreSQL #2026

@Vedmak

Description

@Vedmak

Summary

When using PostgreSQL with AWS RDS Proxy, connections get unnecessarily pinned due to the DoctrineBundle automatically setting charset: 'utf8' for PostgreSQL connections, even when no charset is explicitly configured. This causes the DBAL PostgreSQL driver to execute SET NAMES 'utf8', which AWS RDS Proxy cannot track, resulting in connection pinning.

Description

In ConnectionFactory.php, the bundle automatically sets a default charset when none is provided.

When a charset parameter is set, the PostgreSQL PDO driver Driver/PDO/PgSQL/Driver.php executes SET NAMES query.

AWS RDS Proxy Impact

AWS RDS Proxy logs warnings like:

The client session was pinned to the database connection [dbConnection=xxx] for the remainder of the session. The proxy can't reuse this connection until the session ends. Reason: SQL changed session settings that the proxy doesn't track. Consider moving session configuration to the proxy's initialization query. Digest: "set names $1".

Expected Behavior

For PostgreSQL connections, when no explicit charset is configured by the user, no charset should be automatically set by the bundle, allowing the database to use its default encoding without executing SET NAMES.

Current Workaround Status

There is currently no workaround for this issue:

  • Omitting charset from configuration → automatically set to 'utf8'
  • Setting charset: null → still automatically set to 'utf8' due to isset() check
  • Setting charset: '' → would still pass the isset() check but results in invalid set names query

Environment

  • DoctrineBundle version: 2.15.1
  • Doctrine DBAL version: 4.3.2
  • Database: PostgreSQL via AWS RDS with RDS Proxy
  • PHP version: 8.3

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