当需要缩减 AWS RDS for MySQL 数据库的存储空间时,直接操作会导致停机时间。AWS RDS 不支持直接缩减存储,但可以通过蓝/绿部署技术实现零停机时间的存储缩减。
检查当前环境:
创建数据库快照:
aws rds create-db-snapshot \
--db-instance-identifier production-db \
--db-snapshot-identifier production-db-pre-shrink-snapshot
启动蓝/绿部署:
aws rds create-blue-green-deployment \
--blue-green-deployment-name mysql-storage-shrink \
--source arn:aws:rds:region:account-id:db:production-db \
--target-engine-version same-as-source \
--target-db-parameter-group-name same-as-source \
--target-db-instance-class same-as-source \
--target-storage-type gp3 \
--target-allocated-storage 100 # 新的较小存储大小(GB)
监控部署状态:
aws rds describe-blue-green-deployments \
--blue-green-deployment-identifier deployment-id
等待蓝/绿部署完成:
AVAILABLE
后继续执行切换:
aws rds switchover-blue-green-deployment \
--blue-green-deployment-identifier deployment-id \
--switchover-timeout 300 # 超时时间(秒)
验证新环境:
删除旧实例(可选):
aws rds delete-db-instance \
--db-instance-identifier old-production-db \
--skip-final-snapshot # 仅在确认不需要快照时使用
保留蓝/绿部署配置(可选):
存储缩减限制:
性能考虑:
成本影响:
应用程序兼容性:
方案 | 停机时间 | 复杂度 | 成本 | 适用场景 |
---|---|---|---|---|
蓝/绿部署 | 零 | 中 | 中高 | 关键生产环境 |
逻辑导出导入 | 长 | 高 | 低 | 小型数据库 |
等待存储自动缩减 | 无(不可控) | 低 | 低 | 存储自动扩展后等待 |
通过此蓝/绿部署方案,您可以实现 MySQL RDS 存储的缩减而无需停机,确保业务连续性。