简体   繁体   English

无需停机即可迁移大型生产数据库

[英]Migrating a giant production database without downtime

We host a Rails app on AWS which uses mysql on the amazon-rds database.我们在 AWS 上托管了一个 Rails 应用程序,它使用 amazon-rds 数据库上的 mysql。 We have a giant table in the database which we want to migrate, but it takes days to make the migration because of the millions of rows.我们在数据库中有一个要迁移的巨型表,但由于有数百万行,迁移需要几天时间。 Specifically we're moving a VARCHAR to a TEXT column具体来说,我们将VARCHAR移动到TEXT

How do I migrate this large production database without users experiencing downtime?如何在不让用户遇到停机的情况下迁移这个大型生产数据库?

One idea I've heard is to setup a copy of the database, and make the migration there and switching it to be the main database when that's done.我听说的一个想法是设置数据库的副本,并在那里进行迁移,并在完成后将其切换为主数据库。 However I'm not sure how this would take account of user data entered while the migration is ongoing.但是,我不确定这将如何考虑在迁移过程中输入的用户数据。

Update: This may be relevant: amazon-rds offers read replicas and Multi-AZ deployments which seem like they might be made for this type of thing.更新:这可能是相关的: amazon-rds 提供只读副本多可用区部署,看起来它们可能是为这类事情而设计的。 First time doing this, though, so would welcome guidance on any method whether it be this or another.不过,这是第一次这样做,因此欢迎就任何方法提供指导,无论是这种方法还是另一种方法。

I don't know if this is possible with the hosting options you are using, but I would tackle the problem this way: 我不知道你使用的托管选项是否可行,但我会这样解决问题:

  1. Copy the data to the new server (and record the binary log position on the old database server) 将数据复制到新服务器(并在旧数据库服务器上记录二进制日志位置)
  2. Turn on replication from the old server to the new server (and wait for it to catch up) 打开从旧服务器到新服务器的复制(并等待它赶上)
  3. Reconfigure the Rails application to point to the new server 重新配置Rails应用程序以指向新服务器

Read only mode is another potential option if a "write downtime" is more acceptable than a "full downtime" (depends on the application obviously). 如果“写入停机时间”比“完全停机时间”(显然取决于应用程序)更可接受,则只读模式是另一种可能的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM