<p>Error 1440 indicates your XA transaction is trying to register an XID that is already present in the server’s XA transaction cache.</p>
<p>MySQL Error 1440: ER_XAER_DUPID happens when an XA START statement reuses an XID that is still active or prepared. End or recover the conflicting transaction, then retry with a unique XID to resolve the problem.</p>
XAER_DUPID: The XID already exists
MySQL raises Error 1440 when an XA START statement supplies an XID that is already recorded in the server’s internal transaction cache. MySQL treats the duplicate identifier as a protocol violation and refuses the command.
The error stops the distributed transaction from beginning and leaves the client responsible for either selecting a new XID or completing the original in progress.
The message surfaces during two-phase commit workflows that span multiple databases or resource managers. It often shows up in microservices that coordinate transactions through middleware such as Atomikos, Narayana, or Spring‐JTA.
High-volume message queues and payment gateways that retry requests quickly are especially prone to reusing an XID before the first attempt finishes.
Most cases stem from reissuing XA START with the same global_transaction_id before calling XA END and XA PREPARE or XA COMMIT. A crash between prepare and commit can also leave the XID in a prepared state, triggering duplicates on recovery.
Application bugs that build XIDs from non-unique values, such as timestamps rounded to seconds, are another frequent trigger.
First, run XA RECOVER to list in-doubt transactions. If the duplicate XID is prepared, commit or rollback it. If the XID is active, finish it with XA END before starting a new branch. Finally, ensure your application generates truly unique XIDs, for example by appending a UUID.
Generate XIDs with collision-proof algorithms, log them for tracing, and wrap XA calls in idempotent retry logic. Monitor the mysql_error.log for repeated 1440 entries so you can patch faulty producers quickly.
Galaxy’s query history and AI copilot surface open XA transactions and suggest safe cleanup commands, reducing the risk of orphaned XIDs in collaborative environments.
A second XA START arrives before XA END completes, so MySQL still holds the identifier.
The first phase finished with XA PREPARE, but a crash prevented commit or rollback, leaving the XID in limbo.
The application derives XIDs from low-precision timestamps or session IDs, causing collisions under load.
Failure handling logic blindly retries the same XID after a network glitch, creating duplicates.
Raised when XA COMMIT or ROLLBACK references an unknown XID.
Indicates an invalid XA flag or parameter in the statement.
Signals that the resource manager failed to process the XA command.
No. XA is optional; if you do not use distributed transactions, simply avoid XA statements. Disabling is unnecessary.
Run XA RECOVER and filter by the offending gtrid or bqual. Galaxy’s search can bookmark the query for repeated use.
Restarting only removes active branches, not prepared ones. Prepared XIDs survive restarts and still trigger duplicates.
The error exists in MySQL 5.7 and 8.0; behavior is identical across current GA releases.