apache/shardingsphere · error · PostgreSQLProtocolException

Can not find `%s` in PostgreSQL identifier tag type.

Error message

Can not find `%s` in PostgreSQL identifier tag type.

What it means

PostgreSQLMessagePacketType.valueOf(int) maps the leading byte of a backend/frontend message to a known packet type enum. An unrecognized value throws PostgreSQLProtocolException 'Can not find `%s` in PostgreSQL identifier tag type.', meaning the first byte of the message does not correspond to any known PostgreSQL command tag.

Source

Thrown at database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketType.java:108

    
    PORTAL_SUSPENDED('s');
    
    private final char value;
    
    /**
     * Value of integer.
     *
     * @param value integer value
     * @return command packet type enum
     * @throws PostgreSQLProtocolException PostgreSQL protocol exception
     */
    public static PostgreSQLMessagePacketType valueOf(final int value) {
        for (PostgreSQLMessagePacketType each : values()) {
            if (value == each.value) {
                return each;
            }
        }
        throw new PostgreSQLProtocolException("Can not find `%s` in PostgreSQL identifier tag type.", value);
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Verify the client is a real PostgreSQL-protocol client and connects with the correct startup sequence (including SSL negotiation)
  2. Check earlier messages' length prefixes for correctness — a bad length desynchronizes the stream and surfaces here
  3. Compare the failing byte value against the protocol spec to see which message the peer thought it was sending
  4. Enable packet-level logging and test the same client against a vanilla PostgreSQL to isolate proxy-side desync
Defensive patterns

Strategy: validation

Validate before calling

int tag = buffer.readByte() & 0xff;
if (!PostgreSQLMessagePacketType.knownTags().contains(tag)) { /* drop connection, log tag */ }

Try / catch

catch (PostgreSQLProtocolException e) { /* treat as protocol desync: close connection, do not retry on same stream */ }

Prevention

When it happens

Trigger: The packet decoder reads a message tag byte that is not one of the enumerated tags — stream misalignment (reading a tag from the middle of a previous message), a truncated stream, or an unencrypted/SSL byte where a tag was expected (e.g. SSL negotiation handled incorrectly).

Common situations: Startup sequence handled out of order, SSLRequest vs regular startup confusion, earlier message length fields lying about payload size causing desync, or non-PostgreSQL clients connecting to the port.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/41391259ff3f8ab0. Report an issue: GitHub.