apache/shardingsphere · error · InvalidParameterValueException
invalid value for parameter "client_encoding": "%s"
Error message
invalid value for parameter "client_encoding": "%s"
What it means
Error "invalid value for parameter "client_encoding": "%s"" thrown in apache/shardingsphere.
Source
Thrown at proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java:156
PostgreSQLComStartupPacket startupPacket = new PostgreSQLComStartupPacket(payload);
clientEncoding = getNormalizedClientEncoding(startupPacket.getClientEncoding());
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(StandardCharsets.UTF_8);
String username = startupPacket.getUsername();
ShardingSpherePreconditions.checkNotEmpty(username, EmptyUsernameException::new);
startupMessageReceived = true;
context.writeAndFlush(getIdentifierPacket(username, rule));
currentAuthResult = AuthenticationResultBuilder.continued(username, "", startupPacket.getDatabase(), startupPacket.getConnectionAttributes());
return currentAuthResult;
}
private String getNormalizedClientEncoding(final String clientEncoding) {
String formattedClientEncoding = formatClientEncoding(clientEncoding);
String lowerCaseClientEncoding = formattedClientEncoding.toLowerCase(Locale.ROOT);
boolean isDefault = "default".equals(lowerCaseClientEncoding);
boolean isUtf8 = "utf8".equals(lowerCaseClientEncoding) || "utf-8".equals(lowerCaseClientEncoding) || "utf_8".equals(lowerCaseClientEncoding)
|| "unicode".equals(lowerCaseClientEncoding);
if (!isDefault && !isUtf8) {
throw new InvalidParameterValueException("client_encoding", lowerCaseClientEncoding);
}
return PostgreSQLCharacterSets.UTF8.name();
}
private String formatClientEncoding(final String value) {
return value.startsWith("'") && value.endsWith("'") || value.startsWith("\"") && value.endsWith("\"") ? value.substring(1, value.length() - 1).trim() : value.trim();
}
private PostgreSQLIdentifierPacket getIdentifierPacket(final String username, final AuthorityRule rule) {
Optional<Authenticator> authenticator = rule.findUser(new Grantee(username)).map(optional -> new AuthenticatorFactory<>(PostgreSQLAuthenticatorType.class, rule).newInstance(optional));
if (authenticator.isPresent() && PostgreSQLAuthenticationMethod.PASSWORD.getMethodName().equals(authenticator.get().getAuthenticationMethodName())) {
return new PostgreSQLPasswordAuthenticationPacket();
}
md5Salt = PostgreSQLRandomGenerator.getInstance().generateRandomBytes(4);
return new PostgreSQLMD5PasswordAuthenticationPacket(md5Salt);
}
}
View on GitHub (pinned to e952770a21)
Solutions
- Set client_encoding to a valid PostgreSQL encoding name such as UTF8.
- Remove the invalid client_encoding setting from the connection startup packet.
- Check for typos in the encoding name.
When it happens
Trigger: The client supplies an unrecognized client_encoding value in the PostgreSQL startup/authentication phase.
Common situations: Misspelled or unsupported charset names (e.g. 'utf-8' vs 'UTF8') in connection parameters.
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/67304ca701f24d76.
Report an issue: GitHub.