Ghost/copy table 比原来的 table 大很多倍

Ghost/copy table is many times bigger than original table

信息: 我正在使用 AWS RDS Mysql 5.6.34 (500GB) 实例(没有副本,只有主实例)

注意: Binlog 已启用并设置为行

目标:将列field_1从enum修改为tinyint

额外信息: 我正在使用 Rails 应用程序。所以每次我想向枚举添加一个值时,我都需要编写一个迁移。因此,将枚举字段转换为 tinyint,这样我就可以添加或删除枚举值,而无需使用 Active Enum

编写迁移

其他信息:我也试过LHM但是RDS实例在93%时内存不足

运行 gh-ost:

之前的数据库信息
mysql> select table_schema, sum((data_length+index_length)/1024/1024) AS MB from information_schema.tables group by 1;
+--------------------+-----------------+
| table_schema       | MB              |
+--------------------+-----------------+
| information_schema |      0.00976560 |
| mysql              |      5.96277428 |
| performance_schema |      0.00000000 |
| my_app_db          | 223941.79882818 |
+--------------------+-----------------+

gh-ost 之前原始 table 的大小:(仅显示列表中需要修改的 table)

mysql> SELECT table_name AS `Table`, round(((data_length + index_length) / 1024 / 1024), 2) `Size (MB)` FROM information_schema.TABLES WHERE table_schema = "my_app_db";
+----------------------------------------+-----------+
| Table                                  | Size (MB) |
+----------------------------------------+-----------+
| table_abc                              |     70.41 |
| my_table                               |  86058.73 |

开始迁移:

gh-ost \
--user="user" \
--password="password" \
--host="my-endpoint.rds.amazonaws.com" \
--database="my_app_db" \
--table="my_table" \
--alter="MODIFY field_1 TINYINT(2) DEFAULT 1 NOT NULL" \
--assume-rbr \
--allow-on-master \
--verbose \
--execute

当迁移完成将近 93% 时,RDS 可用内存下降到 20GB。所以我停止了gh-ost。

停止 gh-ost 后的数据库信息:

mysql> select table_schema, sum((data_length+index_length)/1024/1024) AS MB from information_schema.tables group by 1;
+--------------------+-----------------+
| table_schema       | MB              |
+--------------------+-----------------+
| information_schema |      0.00976560 |
| mysql              |      5.96277428 |
| performance_schema |      0.00000000 |
| my_app_db          | 446299.17968756 |
+--------------------+-----------------+

停止 gh-ost 后原始 table 的大小:

mysql> SELECT table_name AS `Table`, round(((data_length + index_length) / 1024 / 1024), 2) `Size (MB)` FROM information_schema.TABLES WHERE table_schema = "my_app_db";
+----------------------------------------+-----------+
| Table                                  | Size (MB) |
+----------------------------------------+-----------+
| _my_table_ghc                       |      0.41 |
| _my_table_gho                       | 273157.00 |
| my_table                            |  85011.62 |

问题:

为什么 gh-ost table 比原来的 table 大很多倍?

如果需要有关 table、索引或数据库的更多信息,我可以提供:)

这是 link 在 gh-ost 回购中创建的问题:https://github.com/github/gh-ost/issues/890

我从生产数据库的备份创建了 mysql 数据库。

生产有 innodb_file_format 参数作为 Barracuda

新环境的 innodb_file_format 参数为 Antelope

生产中 table 的 ROW_FORMATCOMPRESSED

不幸的是 Antelope 数据库不支持 ROW_FORMAT 作为 COMPRESSED

如果我更深入地了解 information_schema 的细节,我本可以更轻松地解决它!