HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

MongoDB secondary node does not become primary when other nodes are stopped

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
nodesprimaryarenodestoppedmongodbsecondarydoeswhenother

Problem

I want to cluster MongoDB by using a replica set. I have created a three-node replicaset (rs0,rs1,rs2), and run the DBs in parallel with no issues. But when I shut down any two instance (one primary and secondary), the remaining secondary member is not made the primary, instead it remains as a secondary.

Step1:

  • rs0: primary



  • rs1: secondary



  • rs2: secondary



Every thing is ok. When

Step2:

  • rs0: stopped



  • rs1: stopped



  • rs2: secondary (This is not promoted to primary)



Why?

Solution

This is by design. If you want to run with only one node, restart that node without replica set switch.


If a majority of the replica set is inaccessible or unavailable to the
current primary, the primary will step down and become a secondary.
The replica set cannot accept writes after this occurs, but remaining
members can continue to serve read queries if such queries are
configured to run on secondaries.

Read these resources for more details:

  • Replica Set Elections



  • mongo replica set to single server



  • Voting in MongoDB

Context

StackExchange Database Administrators Q#183056, answer score: 3

Revisions (0)

No revisions yet.