innodb_online_alter_log_max_size导致的innodb添加字段时报错

时间:2025-04-01 19:23:31

innodb_online_alter_log_max_size这个参数是mysql 5.6.6引入的,因为在online ddl过程中需要保持delete、update、insert这些数据,所以需要一个日志去保持,这个参数就是限制这个日志的最大大小,当ddl过程中需要的这个日志的大小比这个限制还大的时候就会报错。

具体的错误:

ERROR 1799 (HY000) at line 1: Creating index 'PRIMARY' required more than 'innodb_online_alter_log_max_size' bytes of modification log. Please try again.

解决方法:

该参数为动态参数且全局的,可通过如下命令加大(不一定是我下面设置的大小,这个根据你的情况)

mysql> set global innodb_online_alter_log_max_size=402653184;

5.7中的官方文档关于这个参数的解释:

innodb_online_alter_log_max_size

Command-Line Format --innodb_online_alter_log_max_size=#
System Variable Name innodb_online_alter_log_max_size
Variable Scope Global
Dynamic Variable Yes
Permitted Values Type integer
Default 134217728
Min Value 65536
Max Value 2**64-1

Specifies an upper limit on the size of the temporary log files used during online DDL operations for InnoDB tables. There is one such log file for each index being created or table being altered. This log file stores data inserted, updated, or deleted in the table during the DDL operation. The temporary log file is extended when needed by the value of innodb_sort_buffer_size, up to the maximum specified by innodb_online_alter_log_max_size. If any temporary log file exceeds the upper size limit, the ALTER TABLE operation fails and all uncommitted concurrent DML operations are rolled back. Thus, a large value for this option allows more DML to happen during an online DDL operation, but also causes a longer period at the end of the DDL operation when the table is locked to apply the data from the log.

online ddl的原理是,mysql把在ddl时间内的所有的 插入,更新和删除操作记录到一个日志文件, 然后再把这些增量数据应用到相应的表上(等表上的事务完全释放后),这个临时日志文件的上限值由innodb_online_alter_log_max_size指定,每次扩展innodb_sort_buffer_size的大小 该参数如果太小有可能导致DDL失败,这期间所有的未提交的并发DML操作都会回滚;但是如果太大会可能会导致后DDL操作最后锁定表的时间更长(锁定表,应用日志到表上)。 每一个变化的索引或者表都会分配一个。

关于更多的online ddl可以看看5.6和5.7的官方文档。

/doc/refman/5.6/en/

/doc/refman/5.7/en/