shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Force UTF-8 Encoding for PostgreSQL Backend Connections in ShardingSphere-Proxy

Open ShenFeng312 opened this issue 1 year ago • 1 comments

Feature Request

see https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/core/v3/SimpleParameterList.java#L553-L555 in pg jdbc

In pgjdbc, strings are always transmitted as UTF-8, regardless of any character set settings on the client or in the JDBC URL. The database still decodes the received bytes according to the client's client_encoding, and then converts them to its internal storage encoding.

Java Client String
        │ encode (UTF-8, forced)
        │  ← ignores client/JDBC character set settings
        ▼
     Byte Stream (always UTF-8)
        │
        ▼
PostgreSQL Server
        │ decode using client_encoding
        ▼
Database Internal Storage Encoding

ShenFeng312 avatar Aug 22 '25 02:08 ShenFeng312

I’d like to solve this issue. My short analysis is that we should make PostgreSQL client_encoding behavior explicit and consistent by enforcing a UTF-8-only policy in Proxy:

  1. Accept only UTF-8 aliases for client_encoding in PostgreSQLCharsetVariableProvider.java and normalize accepted values to UTF-8 internally.
  2. Reject non-UTF8 values with InvalidParameterValueException.

AsyncKurisu avatar Apr 21 '26 13:04 AsyncKurisu