Master becomes secondary after stop all replicas

Hello! i have 3 node mongodb replica set ( Master > Secondary > Secondary )

and after i turn off 2 Secondaries ( systemctl stop mongod ) my Master after 10 seconds becomes a secondary! why this happend?

if a single node survives a system failure, it will not allow writes anymore and become read-only.

if there are 2 nodes surviving, they will not allow writes either because they fail to determine which would become a new primary. that is unless you gave them a priority.

think of this situation: your 3 member set somehow loses connection to the primary. now you will have 2 chunks of servers; 1 is alone, and the other 2. both chunks would think others had just died but they are well alive. what would happen if both chunks continue serving as primaries?

to protect chaos, this is the default behavior: they will serve read-only until other members come and voting for a primary completes.

Tessekur ederim! but what can i do if i lost this 2 servers? how can i make my remaining server working? i think i should delete this 2 died members from Replica set, but my db is secondary and it is Read only :frowning:

permanent or temporary? I will assume they lost to you forever else be careful.

it is usually about maintenance steps or just removing members.
Remove Members from Replica Set — MongoDB Manual
Perform Maintenance on Replica Set Members — MongoDB Manual

But since you current instance work in secondary mode, you cannot “db.shutdown()” it, nor “rs.remove” works because not authrized. you have to kill this instance first.

ps aux | grep mongod # gets its pid
kill pid # there is possibly shorter ways, what what you know is faster :)

then as described in maintanence document, comment out or edit some lines so you can run it again without replica settings. (replica set name and port are most important).

then connect on this new port, and remove “local” database (browse it if you want and see if there is another way). this is the fastest to remove from a replica set.

use local
use admin

now edit config again, change port and remove replica set related lines if you want, then just restart the server.

Cok sagol abi! it works!

Afiyet olsun :wink:
Good luck!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.