幽灵/复制表比原始表大很多倍 问题:

问题描述

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

注意:启用binlog并将其设置为“行”

目标:将列field_1从枚举修改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之前原始表的大小:(仅显示需要从列表中修改的表)

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后原始表的大小:

MysqL> SELECT table_name AS `Table`,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表比原始表大很多倍?

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

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

解决方法

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

生产的innodb_file_format参数为Barracuda

新环境的innodb_file_format参数为Antelope

生产中的表的ROW_FORMATCOMPRESSED

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

如果我进一步研究了information_schema的细节,那么我本可以解决得更麻烦的!