Perform Online DDL in MariaDB with Minimal Locking
Learn how to run ALTER TABLE operations that avoid full table locks in MariaDB 10.0+, verify low impact, and recover if the operation stalls.
29 Jun 2026, 10:40 UTC

Desired Outcome
Execute an ALTER TABLE change (e.g., add a column) without blocking concurrent DML, verify that lock impact is negligible, and know how to recover if the operation stalls.
Prerequisites
- MariaDB server version 10.0 or newer (Online DDL introduced in 10.0).
- User account with the
ALTERprivilege on the target table and thePROCESSprivilege to view lock information. - Enough free disk space for a temporary copy of the table (roughly the size of the table plus indexes).
- Access to the mysql client or any compatible SQL interface.
Procedure
- Check server version
SELECT VERSION();Confirm the version string starts with
10.or higher. - Identify the table and column to add
Replace
mydb.usersandnew_flagwith your actual schema. - Run the Online DDL with the INSTANT algorithm (if supported)
The
INSTANTalgorithm modifies only the table metadata and avoids copying data.ALTER TABLE mydb.users ADD COLUMN new_flag TINYINT(1) NOT NULL DEFAULT 0 ALGORITHM=INSTANT;If the column definition cannot be satisfied with INSTANT (e.g., adding a NOT NULL column without a default), MariaDB will automatically fall back to
INPLACEorCOPY. You can explicitly request a method to see what will happen:ALTER TABLE mydb.users ADD COLUMN new_flag TINYINT(1) NOT NULL DEFAULT 0 ALGORITHM=INPLACE, LOCK=NONE; - Monitor lock and performance impact
While the statement runs, open another session and check:
SHOW ENGINE INNODB STATUS\GLook for the
---TRANSACTIONsection; there should be no long waits labeledWaiting for table lock.You can also query the performance schema for current locks:
SELECT OBJECT_NAME, LOCK_TYPE, LOCK_MODE FROM performance_schema.data_locks WHERE OBJECT_SCHEMA = 'mydb' AND OBJECT_NAME = 'users';Expect few or no rows, or only short‑lived
RECORD_NOT_GAPlocks. - Verify the change completed
After the statement returns, confirm the column exists:
SHOW COLUMNS FROM mydb.users LIKE 'new_flag';Check
UPDATE_TIMEininformation_schema.tablesto see when the table was last modified.
Expected Checks
- The
ALTER TABLEstatement returns quickly (usually within a few seconds) forINSTANTorINPLACEoperations. SHOW ENGINE INNODB STATUSshows no pending lock waits for the table.- Querying
performance_schema.data_locksreturns minimal or no lock rows for the table during the operation. - The table’s
UPDATE_TIMEreflects the time of the change, confirming the metadata swap.
Recovery Options
If the operation stalls before the metadata swap
Long‑running transactions can block the final swap phase. You can:
- Identify blocking transactions with:
- Kill the blocking session (requires
SUPERprivilege): - The Online DDL will then resume and complete the swap automatically.
SELECT trx_id, trx_state, trx_started
FROM information_schema.innodb_trx
WHERE trx_mysql_thread_id IN (SELECT blocking_thread FROM sys.innodb_lock_waits);
KILL <thread_id>;
If you need to cancel the operation entirely
You can issue a KILL on the thread running the ALTER TABLE. Depending on the phase:
- Before the temporary table is created, the server rolls back the statement with no lasting effects.
- After a temporary copy exists but before the swap, MariaDB automatically drops the temporary table when the statement is killed.
- After the swap has occurred, the change is already committed; to revert you must issue another
ALTER TABLE(e.g., drop the column) or restore from a backup.
Disk‑space exhaustion
If the server runs out of space while creating the temporary copy, the operation fails with an error like The table is full. In that case:
- Free space or increase the
tmpdircapacity. - Retry the
ALTER TABLE.
No manual cleanup is required; any partial temporary table is removed automatically on failure.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.