I assume you you have a high availability (master - slave topology) setup. I will be brief and technical on this one :)
Context:
- dbfoo1 is master and dbfoo2 is slave - dbfoo1(M) - dbfoo2(S)
- dbfoo2 has to be promoted to master - dbfoo2(M) - dbfoo1(S)
- note that in some cases the slave requires a innodb buffer pool warm-up before being promoted to master
Let's get to work:
- remove the VIP from dbfoo1 (/etc/network/interfaces)
- add the VIP to dbfoo2 (/etc/network/interfaces)
- take down the VIP on dbfoo1
[codesyntax lang="bash"]
dbfoo1# ip a d dev eth0 x.x.x.x/y
[/codesyntax]
- dbfoo2 should not be lagging behind dbfoo1
dbfoo2> show slave status\G Relay_Log_Space: 0 Seconds_Behind_Master: 0
- check the "freezing point" on dbfoo1 and note down the output from 'show' commands (this is optional but good to have)
dbfoo1> flush logs; dbfoo1> show master status\G dbfoo1> show slave status\G
- check the "freezing point" on dbfoo1 and note down the output from 'show' commands
dbfoo2> slave stop; dbfoo2> flush logs; dbfoo2> show master status\G <--- from here use File: and Position: to attach dbfoo1 (two steps below) dbfoo2> show slave status\G
MariaDB [(none)]> show master status\Gshow slave status\G *************************** 1. row *************************** File: bin.005662 Position: 385 Binlog_Do_DB: Binlog_Ignore_DB: 1 row in set (0.00 sec) *************************** 1. row *************************** Slave_IO_State: Master_Host: dbfoo1 Master_User: user Master_Port: 3306 Connect_Retry: 60 Master_Log_File: bin.006034 Read_Master_Log_Pos: 245 Relay_Log_File: relay.017538 Relay_Log_Pos: 523 Relay_Master_Log_File: bin.006034 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 245 Relay_Log_Space: 1128 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 310 1 row in set (0.00 sec) MariaDB [(none)]>
- finish the flip - promote dbfoo2 as master by adding the VIP on it
[codesyntax lang="bash"]
dbfoo2# ip a a dev eth0 x.x.x.x/y
[/codesyntax]
- connect dbfoo2 to the new master
dbfoo1> reset slave all; dbfoo1> change master to master_host='dbfoo2', master_user='user', master_password='password', master_log_file='bin.005662', master_log_pos=385; dbfoo1> slave start;
- done!
you are mixing hostnames (dbfoo1, dbfoo2) on few places in this article... it's confusing :(
but thx anyway and keep writing ;)
I remember that when I wrote this post I checked it for errors pretty well, but there might still be some.
Could you please point me where I am mixing the hostnames?
Thanks.
On the last step: "connect dbfoo2 to the new master" should be:
dbfoo2> reset slave all;
dbfoo2> change master to master_host='dbfoo2', master_user='user', master_password='password', master_log_file='bin.005662', master_log_pos=385;
dbfoo2> slave start;
No make sense
Be on the same host that you will promote to master. You must be in dbfoo1 to trigger this command.
`check the "freezing point" on dbfoo1 and note down the output from 'show' commands`
should read
`check the "freezing point" on dbfoo2 and note down the output from 'show' commands`