<p>The error is raised when you run SET @@GLOBAL.GTID_PURGED while any session still owns GTIDs from open or pending transactions.</p>
<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>
@@GLOBAL.GTID_PURGED can only be set when there are no
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.
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.
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.
An explicit transaction started with START TRANSACTION but not yet committed or rolled back owns a GTID, blocking the SET command.
Statements such as ALTER TABLE or SELECT ... FOR UPDATE hold GTIDs until they finish, keeping owned_gtids non-empty.
Replica threads apply relay log events and own GTIDs temporarily, preventing changes to GTID_PURGED.
Prepared but not committed XA transactions keep GTIDs in an owned state until XA COMMIT or XA ROLLBACK completes.
Applications that open a transaction and then go idle leave the server with owned GTIDs that block administration commands.
Raised when you try to disable GTID consistency while unsafe tables are in use.
Occurs if the GTID you attempt to purge is not present in mysql.gtid_executed.
Replica stops because of missing or corrupt binary logs, often after incorrect GTID settings.
No. MySQL does not provide a force option. All owned GTIDs must be cleared first.
Read_only prevents new writes but does not end existing transactions. You still need to finish or kill them.
Replication threads or XA transactions may continue owning GTIDs. Stop those processes and recheck.
Galaxy’s connection browser shows live transactions and lets you terminate or commit them before running administrative SQL, reducing chances of Error 1841.