Common SQL Errors

MySQL Error 1397 ER_XAER_NOTA: Unknown XID - Fix Guide

Galaxy Team
August 7, 2025

<p>The server cannot find the XA transaction identifier (XID) referenced in a COMMIT, ROLLBACK, or PREPARE statement.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1397 ER_XAER_NOTA?

<p>ER_XAER_NOTA (MySQL Error 1397: Unknown XID) appears when a COMMIT, ROLLBACK, or PREPARE references an XA transaction ID that the server does not recognize. Verify that the XID was started on the same connection, recover or forget orphaned transactions, and retry the command using the right session.</p>

Error Highlights

Typical Error Message

XAER_NOTA: Unknown XID

Error Type

Transaction Error

Language

MySQL

Symbol

ER_XAER_NOTA

Error Code

1397

SQL State

XAE04

Explanation

Table of Contents

What is MySQL Error 1397 ER_XAER_NOTA?

Error 1397 fires when you execute XA COMMIT, XA ROLLBACK, or XA PREPARE with an XID the server cannot locate. The condition name ER_XAER_NOTA maps to the XA standard code XAER_NOTA, meaning "Node transaction association does not exist."

The problem usually shows up in distributed transaction managers, message queues, or application servers that rely on MySQLs XA interface. Fixing it fast is critical because dangling transactions lock rows, hold resources, and break two phase commit workflows.

Why does the "Unknown XID" message matter?

An unknown XID means the server sees no matching transaction in its in-memory XA list or the binary log recovery set. Subsequent COMMIT or ROLLBACK does nothing, leaving participating resources out of sync and risking data inconsistency across systems.

Production environments using microservices and global transactions can cascade failures if one branch silently skips commit while others succeed. Early detection and correction protect atomicity and consistency guarantees.

What Causes This Error?

Most cases trace back to session mis-management or crash recovery gaps. Losing the original connection or forgetting to PREPARE before COMMIT are frequent triggers. Network blips, timeouts, or manual KILL commands also orphan XIDs.

In replication setups, the error may appear on slaves if binary logs include COMMIT for an XID never PREPAREd on that replica. Version mismatches or disabled XA support can contribute.

How to Fix MySQL Error 1397 ER_XAER_NOTA

Start by confirming the XID truly exists. Query performance_schema.xa_transactions (MySQL 8.0+) or run SHOW ENGINE INNODB STATUS to list active XA entries. If absent, the server will always return ER_XAER_NOTA.

Next, ensure COMMIT or ROLLBACK executes on the same connection that ran XA START. Switching sessions clears the XA list, so connection pooling must pin transactions.

Common Scenarios and Solutions

When a crash occurs between PREPARE and COMMIT, run XA RECOVER to list pending XIDs, then decide to XA COMMIT 'xid' ONE PHASE or XA ROLLBACK 'xid'.

If the application issued COMMIT without PREPARE, resend XA PREPARE first or restart the whole XA sequence. Galaxy users can trace the statement history per connection to identify the missing step.

Best Practices to Avoid This Error

Always PREPARE before COMMIT in two phase workflows. Use connection pooling libraries that support stickiness or pinning to keep the same connection until the global transaction finishes.

Monitor performance_schema.xa_transactions for orphaned rows and configure alerts on ER_XAER_NOTA spikes. Galaxy’s query versioning lets teams audit who executed what step when, reducing guesswork.

Related Errors and Solutions

Error 1398 ER_XAER_INVAL signals an invalid XA argument, often due to malformed XIDs. Validate identifier length and character set.

Error 1399 ER_XAER_RMFAIL indicates the resource manager failed. Check storage engines and crash recovery logs.

Common Causes

Connection Lost After XA START

The client disconnects or the pool recycles the connection before PREPARE or COMMIT, leaving MySQL unaware of the XID in later calls.

Missing XA PREPARE

Applications jump directly from XA START to XA COMMIT, so the server never moves the transaction into the prepared list.

Crash Between PREPARE and COMMIT

MySQL or the host crashes after PREPARE. On restart, the XID lives in recovery but the client issues COMMIT from a new session.

Replication Drift

Slaves replay a COMMIT event for an XID that was filtered or failed earlier, producing ER_XAER_NOTA during relay log execution.

Related Errors

MySQL Error 1398 ER_XAER_INVAL

Raised when XA commands use an invalid argument or malformed XID. Fix by ensuring XID length and format are correct.

MySQL Error 1399 ER_XAER_RMFAIL

Indicates the resource manager (storage engine) is unavailable or failed to process the XA request. Check engine logs and restart if needed.

MySQL Error 1400 ER_XAER_OUTSIDE

Occurs when XA commands are issued outside an XA transaction context. Always wrap statements with XA START and XA END.

FAQs

Is ER_XAER_NOTA a bug in MySQL?

No. The error correctly signals that the XID you passed is not in MySQLs XA transaction table.

Can I safely ignore Unknown XID errors?

Ignoring them risks data inconsistency across participating systems. Always investigate and resolve the underlying cause.

How do I find stray XA transactions?

Run XA RECOVER or query performance_schema.xa_transactions to list pending or prepared XIDs.

Does Galaxy help prevent this error?

Yes. Galaxy keeps each connection visible in dedicated tabs, making it easier to run XA commands on the correct session and audit the full statement chain.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo