MyCATApache/Mycat-Server · error · UnknownTxIsolationException
txIsolation
Error message
txIsolation:${txIsolation} What it means
PostgreSQLBackendConnection.getTxIsolationCommand() builds a 'SET SESSION TRANSACTION ISOLATION LEVEL ...' command from the configured txIsolation value. Only READ_UNCOMMITTED/READ_COMMITTED/REPEATABLE_READ/SERIALIZABLE are mapped; any other integer (including PG-specific constants outside the Isolations table) hits the default branch and throws UnknownTxIsolationException("txIsolation:" + txIsolation).
Solutions
- Set transactionIsolation to a supported value (1=READ_UNCOMMITTED, 2=READ_COMMITTED, 4=REPEATABLE_READ, 8=SERIALIZABLE) in the dataHost config
- Log/capture the offending txIsolation value from the exception message and correct the caller that set it
- Upgrade/patch MyCat to map PostgreSQL's own isolation constants in getTxIsolationCommand
- If you need READ COMMITTED behavior, use isolation 2 rather than driver-specific values
Example fix
// before <dataHost ... transactionIsolation="3"> // after <dataHost ... transactionIsolation="2">
Defensive patterns
Strategy: validation
Validate before calling
int tx = getTxIsolation();
if (tx != 1 && tx != 2 && tx != 4 && tx != 8) {
throw new IllegalArgumentException("txIsolation " + tx + " unsupported by PG backend; use 1/2/4/8");
} Try / catch
try { conn.execute(sql); } catch (UnknownTxIsolationException e) { /* correct transactionIsolation config from e.getMessage() and retry */ } Prevention
- Set transactionIsolation only to 1/2/4/8 in dataHost config
- Map driver-specific isolation constants before passing them to MyCat
- Validate isolation config at startup, not first query
When it happens
Trigger: A backend connection is created/used with a txIsolation value that is not one of the four supported Isolations constants — typically a bad value in the transactionIsolation config, or a caller passing a JDBC constant MyCat's Isolations table does not recognize.
Common situations: Typo'd or out-of-range isolation level in the dataHost/schema config; frontend session isolation mapped incorrectly to the backend; code that passes e.g. TRANSACTION_NONE or a driver-specific constant into the PG backend connection.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- invalid param ,connection request db is
- Invalid DataSource
- txIsolation
- the select proess err ,the SelectResponse is empty
- offer data error!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/4a6aeeee071f1293.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/backend/postgresql/PostgreSQLBackendConnection.java:125
* @param
* @param txIsolation
*/
private static void getTxIsolationCommand(StringBuilder sb, int txIsolation) {
switch (txIsolation) {
case Isolations.READ_UNCOMMITTED:
sb.append("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
return;
case Isolations.READ_COMMITTED:
sb.append("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;");
return;
case Isolations.REPEATED_READ:
sb.append("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;");
return;
case Isolations.SERIALIZABLE:
sb.append("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;");
return;
default:
throw new UnknownTxIsolationException("txIsolation:" + txIsolation);
}
}
private Object attachment;
private volatile boolean autocommit=true;
private volatile boolean txReadonly=false;
private volatile boolean borrowed;
protected volatile String charset = "utf8";
/***
* 当前事物ID
*/
private volatile String currentXaTxId;View on GitHub (pinned to 65f8d8beb7)