最近線上頻繁的出現(xiàn)slave延時(shí)的情況,經(jīng)排查發(fā)現(xiàn)為用戶在刪除數(shù)據(jù)的時(shí)候,由于表主鍵的主鍵的缺少,同時(shí)刪除條件沒有索引,或或者刪除的條件過濾性極差,導(dǎo)致slave出現(xiàn)hang住,嚴(yán)重的影響了生產(chǎn)環(huán)境的穩(wěn)定性,也希望通過這篇博客,來加深主鍵在innodb引擎中的重要性,希望用戶在使用RDS,設(shè)計(jì)自己的表的時(shí)候,一定要為表加上主鍵,主鍵可以認(rèn)為是innodb存儲(chǔ)引擎的生命,下面我們就來分析一下這個(gè)案例(本案例的生產(chǎn)環(huán)境的binlog為row模式,對(duì)于myisam存儲(chǔ)引擎也有同樣的問題):
(1).現(xiàn)象slave:
mysql> show slave status/G;*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: xxx.xx.xx.xxMaster_User: replicatorMaster_Port: 3006Connect_Retry: 60Master_Log_File: mysql-bin.000006Read_Master_Log_Pos: 47465657Relay_Log_File: slave-relay.100383Relay_Log_Pos: 251Relay_Master_Log_File: mysql-bin.000006Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 18057461Relay_Log_Space: 29409335Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 1339Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error:
slave的Seconds_Behind_Master一直在增加,slave出現(xiàn)hang住。
(2).解析當(dāng)前slave執(zhí)行到的位置的binlog: