phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

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

Open Vedmak opened this issue 3 months ago • 1 comments

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

Vedmak avatar Sep 09 '25 11:09 Vedmak

Relying on the default connection charset caused issues in the past as this can lead to surprising behavior.

I suggest you to also open a feature request to the RDS proxy to add support for tracking SET NAMES queries.

stof avatar Dec 03 '25 17:12 stof