Monta
Monta

Reputation: 1180

Upgrade Mongodb data

I'm moving my database from 1 cluster (replica set of 3 nodes) to a new one and wanted to profit to upgrade my database version. I'm using 3.6 now and want to upgrade to the latest (4.4). I'm allowed to shutdown the service for a couple of hours.

According to what I found as information, here is how I'm planning to do:

Does that look correct?

Upvotes: 0

Views: 709

Answers (1)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59436

I would not recommend to combine these two actions. Do it separately.

Would be like this:

Upgrade to Mongo 4.4

  • Shut down the SECONDARY member
  • Replace the binaries
  • Restart the SECONDARY member
  • Step down the replica set PRIMARY member
  • Replace the binaries on stepped-down PRIMARY
  • Run db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
  • Repeat above till you reached version 4.4

Have a look at Post Upgrade tasks for each release. Setting FeatureCompatibilityVersion may also take some time.

Move to new server

  • Install MongoDB on new host

  • Add new hosts to Replica Set: rs.add( { host: "new_host_1.example.net:27017" } )

    Inital sync takes place and may take some time. I would recommend to add new hosts one-by-one

  • Step down the replica set PRIMARY member (on old host), ensure new primary run on a new host.

  • Stop Mongo service on old hosts

  • Remove old hosts from Replica Set: rs.remove("old_host_1.example.net")

Instead of adding 3 new nodes and then removing 3 old nodes, you can do it of course one-by-one, i.e.

  • add one new node to Replica Set
  • remove one old node from Replica Set
  • repeat above three times

Just ensure when you run rs.add/rs.remove that all members are either in PRIMARY or SECONDARY state!

By this your application has no downtime at all.

Upvotes: 3

Related Questions