Common SQL Errors

MySQL Error 1440: ER_XAER_DUPID – How to Fix “The XID already exists”

Galaxy Team
August 7, 2025

<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>

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 1440 (ER_XAER_DUPID)?

<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>

Error Highlights

Typical Error Message

XAER_DUPID: The XID already exists

Error Type

Transaction Error

Language

MySQL

Symbol

ER_XAER_DUPID

Error Code

1440

SQL State

XAE08

Explanation

Table of Contents

What does “XAER_DUPID: The XID already exists” mean?

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.

When does Error 1440 typically appear?

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.

What causes this error?

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.

How do I fix MySQL Error 1440?

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.

Best practices to avoid duplicates

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.

How Galaxy helps

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.

Common Causes

Reusing an active XID

A second XA START arrives before XA END completes, so MySQL still holds the identifier.

Prepared but uncommitted branch

The first phase finished with XA PREPARE, but a crash prevented commit or rollback, leaving the XID in limbo.

Non-unique XID generator

The application derives XIDs from low-precision timestamps or session IDs, causing collisions under load.

Middleware retry storm

Failure handling logic blindly retries the same XID after a network glitch, creating duplicates.

Related Errors

ER_XAER_NOTA (Error 1397)

Raised when XA COMMIT or ROLLBACK references an unknown XID.

ER_XAER_INVAL (Error 1399)

Indicates an invalid XA flag or parameter in the statement.

ER_XA_RMFAIL (Error 1398)

Signals that the resource manager failed to process the XA command.

FAQs

Can I disable XA to avoid error 1440?

No. XA is optional; if you do not use distributed transactions, simply avoid XA statements. Disabling is unnecessary.

How do I find duplicate XIDs quickly?

Run XA RECOVER and filter by the offending gtrid or bqual. Galaxy’s search can bookmark the query for repeated use.

Does restarting MySQL clear the problem?

Restarting only removes active branches, not prepared ones. Prepared XIDs survive restarts and still trigger duplicates.

Is Error 1440 version-specific?

The error exists in MySQL 5.7 and 8.0; behavior is identical across current GA releases.

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