Guide
Perform an InnoDB Online DDL to Add a Column Without Blocking Writes in MySQL 8.0
Learn how to add a column to an InnoDB table with MySQL’s online DDL, allowing concurrent writes, monitoring progress, and recovering if the operation needs more log space.
10 Jul 2026, 03:22 UTC
3 min18.2K views0

Desired outcome
Add a new column to an existing InnoDB table while the table continues to accept INSERT, UPDATE, and DELETE statements, minimizing downtime for applications.
Prerequisites
- MySQL Server version 5.6 or later (the steps assume MySQL 8.0).
- The table uses the InnoDB storage engine.
- Sufficient free disk space for the online DDL log and undo logs.
- MySQL user with either the SUPER privilege or the ALTER privilege on the target table.
- Access to the server’s error log and, if using replication, to the replica’s SHOW SLAVE STATUS output.
Procedure
- Check the current online DDL log size limit. Run this query on the primary server (requires SELECT on performance_schema or access to SHOW VARIABLES):
The value is in bytes; a typical default is 64 MiB (67108864). Note it for later adjustment if needed.SHOW VARIABLES LIKE 'innodb_online_alter_log_max_size'; - Determine the change you want to make. For this guide we add an INT column named
status_codeafter an existing columncreated_atin tableordersin databasesales. - Run the ALTER TABLE statement with online DDL options. Execute with a user that has ALTER (or SUPER) privilege:
TheALTER TABLE sales.orders ADD COLUMN status_code INT AFTER created_at, ALGORITHM=INPLACE, LOCK=NONE;ALGORITHM=INPLACEtells InnoDB to use the online DDL mechanism;LOCK=NONErequests no table lock (if the operation cannot meet this, MySQL will upgrade the lock automatically and report it). - Monitor the operation while it runs. You can watch for increasing lock wait times or log usage:
- Using Performance Schema (requires SELECT on performance_schema):
SELECT EVENT_NAME, TIMER_WAIT FROM performance_schema.events_statements_current WHERE SQL_TEXT LIKE 'ALTER TABLE sales.orders%'; - Or inspect InnoDB metrics:
Watch theSELECT NAME, COUNT FROM information_schema.INNODB_METRICS WHERE NAME LIKE 'online_ddl%';online_ddl_log_wait_timemetric; if it approaches the limit set byinnodb_online_alter_log_max_size, the operation may fall back to a copying algorithm.
- Using Performance Schema (requires SELECT on performance_schema):
- If the log size is insufficient, adjust it temporarily. You can increase the limit without restarting the server:
Then retry the ALTER TABLE. Remember that this change affects all concurrent online DDL operations.SET GLOBAL innodb_online_alter_log_max_size = 134217728; -- 128 MiB
Expected checks
- Verify the column was added:
Look for the line definingSHOW CREATE TABLE sales.orders\Gstatus_code INTin the output. - Check the MySQL error log for any online DDL warnings or failures (replace
/var/log/mysql/error.logwith your actual path):
No recent failures should appear.grep -i 'online dd' /var/log/mysql/error.log - If you use replication, confirm the replica is not lagging excessively:
EnsureSHOW SLAVE STATUS\GSeconds_Behind_Masterstays low during and after the DDL; a temporary spike is normal but should return to zero.
Recovery options
If the operation rolls back or falls back to a copying algorithm:
- Increase
innodb_online_alter_log_max_size(as shown above) and retry the sameALTER TABLE … ALGORITHM=INPLACE, LOCK=NONEstatement. - If the table is very large and the log limit cannot be raised enough, you can explicitly request a copy‑based algorithm as a fallback:
This will block writes only for the short period needed to acquire the metadata lock, then proceed with a table copy.ALTER TABLE sales.orders ADD COLUMN status_code INT AFTER created_at, ALGORITHM=COPY, LOCK=NONE; - Always ensure you have a recent logical or physical backup before attempting schema changes, especially on production systems.
Limitations and practical verification
- Online DDL requires adequate undo log space; if the server runs out of undo tablespace, the operation will fail with an error like
Undo tablespace is full. Monitor undo usage viaSHOW ENGINE INNODB STATUS\Gunder theTRANSACTIONSsection. - On replicas, the applier thread must process the online DDL log; heavily delayed replicas may see a temporary increase in
Seconds_Behind_Masterwhile the log is applied. Verify replication continuity after the change as described in the checks. - The
LOCK=NONErequest is a best‑effort hint; if the alteration truly requires a table rebuild (e.g., changing a column’s data type to a larger size), MySQL will automatically upgrade the lock and you will see a message in the error log indicating a fallback toALGORITHM=INPLACE, LOCK=SHAREDorLOCK=EXCLUSIVE.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.