Common SQL Errors

MySQL Error 1841: ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>The error is raised when you run SET @@GLOBAL.GTID_PURGED while any session still owns GTIDs from open or pending transactions.</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 1841?

<p>MySQL Error 1841 (ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY) happens when you set @@GLOBAL.GTID_PURGED while other sessions still hold GTIDs. Finish or roll back all transactions, stop replication threads, then rerun the SET command to resolve the issue.</p>

Error Highlights

Typical Error Message

@@GLOBAL.GTID_PURGED can only be set when there are no

Error Type

Configuration Error

Language

MySQL

Symbol

ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY

Error Code

1841

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1841 (ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY)?

The server throws error 1841 with the message "@@GLOBAL.GTID_PURGED can only be set when there are no ongoing transactions" when you try to execute SET @@GLOBAL.GTID_PURGED while any GTIDs are still owned by active sessions.

GTID ownership occurs whenever a transaction begins but has not yet committed or rolled back. Until ownership ends, MySQL blocks GTID_PURGED changes to protect consistency in replication and point-in-time recovery.

Why does the server block the statement?

Updating GTID_PURGED rewrites the global GTID set stored in mysql.gtid_executed. Allowing the change while sessions hold GTIDs would orphan those identifiers and break replication or backups.

Therefore, MySQL validates that the owned_gtids set is empty before accepting the SET command.

When does the error usually appear?

The error frequently appears during migration to GTID-based replication, after loading a dump on a new replica, or while scripting disaster-recovery steps that manually adjust GTID_PURGED.

It can also arise in CI pipelines that automate resets between tests, where background connections still run.

Common Causes

Open Transactions in the Same Session

An explicit transaction started with START TRANSACTION but not yet committed or rolled back owns a GTID, blocking the SET command.

Long-Running Autocommit Statements

Statements such as ALTER TABLE or SELECT ... FOR UPDATE hold GTIDs until they finish, keeping owned_gtids non-empty.

Replication SQL or I/O Threads

Replica threads apply relay log events and own GTIDs temporarily, preventing changes to GTID_PURGED.

XA or Two-Phase Commit Transactions

Prepared but not committed XA transactions keep GTIDs in an owned state until XA COMMIT or XA ROLLBACK completes.

Idle Client Connections

Applications that open a transaction and then go idle leave the server with owned GTIDs that block administration commands.

Related Errors

MySQL Error 1840: ER_CANT_SUPPRESS_GTID_UNSAFE_TABLE

Raised when you try to disable GTID consistency while unsafe tables are in use.

MySQL Error 1843: ER_GTID_PURGED_OUT_OF_RANGE

Occurs if the GTID you attempt to purge is not present in mysql.gtid_executed.

MySQL Error 1236: ER_MASTER_FATAL_ERROR_READING_BINLOG

Replica stops because of missing or corrupt binary logs, often after incorrect GTID settings.

FAQs

Can I bypass the check and force GTID_PURGED?

No. MySQL does not provide a force option. All owned GTIDs must be cleared first.

Does SET GLOBAL read_only=1 solve the problem?

Read_only prevents new writes but does not end existing transactions. You still need to finish or kill them.

Why do I still see owned GTIDs after killing sessions?

Replication threads or XA transactions may continue owning GTIDs. Stop those processes and recheck.

How does Galaxy help avoid this error?

Galaxy’s connection browser shows live transactions and lets you terminate or commit them before running administrative SQL, reducing chances of Error 1841.

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