【Mysql】從庫大量select堵塞,Waiting for table flush 狀態
背景:
- mycat讀寫分離,應用大量select超時
1.檢查
- 透過檢查發現大量select處於Waiting for table flush 狀態,仔細看了一下processlist以及時間段,可以斷定是備份加select慢查詢引起的!
2.重現環境
-
session1
- 終端一執行一個慢查詢
- mysql> select *,sleep(1000) from operation_log limit 100
- 終端二執行xtracebackup備份
- 。。。。。
- 。。。。。
-
>> log scanned up to (768745274)
- 。。。。。備份堵塞
-
mysql> show full processlist;
-
+------+------+---------------------+--------+-------------+---------+-----------------------------------------------------------------------+---------------------------------------------------+
-
| Id | User | Host | db | Command | Time | State | Info |
-
+------+------+---------------------+--------+-------------+---------+-----------------------------------------------------------------------+---------------------------------------------------+
-
| 2 | repl | 47.93.243.162:43700 | NULL | Binlog Dump | 1527333 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |
-
| 9140 | root | localhost | devops | Query | 564 | User sleep | select *,sleep(1000) from operation_log limit 100 |
-
| 9141 | root | localhost | NULL | Query | 0 | init | show full processlist |
- | 9143 | root | localhost:56880 | NULL | Query | 509 | Waiting for table flush | FLUSH NO_WRITE_TO_BINLOG TABLES |
-
session3
-
終端3對慢查詢涉及到的表進行查詢操作
-
[root@iZ2ze66bhrbxkc31nljgjnZ ~]# mysql -uroot -p***** -e "select * from operation_log limit 10" devops
-
Warning: Using a password on the command line interface can be insecure.
- ...堵塞狀態
-
-
終端3對慢查詢涉及到的表進行查詢操作
-
此時的processlist狀態
-
mysql> show full processlist;
-
+------+------+---------------------+--------+-------------+---------+-----------------------------------------------------------------------+---------------------------------------------------+
-
| Id | User | Host | db | Command | Time | State | Info |
-
+------+------+---------------------+--------+-------------+---------+-----------------------------------------------------------------------+---------------------------------------------------+
-
| 2 | repl | 47.93.243.162:43700 | NULL | Binlog Dump | 1527460 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |
-
| 9140 | root | localhost | devops | Query | 691 | User sleep | select *,sleep(1000) from operation_log limit 100 |
-
| 9141 | root | localhost | NULL | Query | 0 | init | show full processlist |
- | 9143 | root | localhost:56880 | NULL | Query | 636 | Waiting for table flush | FLUSH NO_WRITE_TO_BINLOG TABLES |
-
| 9150 | root | localhost | devops | Query | 454 | Waiting for table flush | select * from operation_log limit 10 | --查詢被堵塞
- +------+------+---------------------+--------+-------------+---------+-----------------------------------------------------------------------+---------------------------------------------------+
-
步驟1阻塞了步驟二,步驟二導致步驟三需要等待步驟一。
-
mysql> show full processlist;
-
session4
-
終端四對其它非慢查詢中的表進行查詢(不堵塞)
-
[root@iZ2ze66bhrbxkc31nljgjnZ ~]# mysql -uroot -pESBecs00 -e "select * from role limit 10" devops
-
Warning: Using a password on the command line interface can be insecure.
-
+----+-----------------+--------------------------------+--------+
-
| id | role_name | description | status |
-
+----+-----------------+--------------------------------+--------+
-
| 1 | 超級管理員 | 所有許可權 | 1 |
-
| 3 | 開發工程師 | 開發工程師開發工程師 | 1 |
-
| 4 | 運維工程師 | 運帷工程師運帷工程師 | 1 |
-
+----+-----------------+--------------------------------+--------+
-
[root@iZ2ze66bhrbxkc31nljgjnZ ~]# mysql -uroot -pESBecs00 -e "select * from module limit 10" devops
-
Warning: Using a password on the command line interface can be insecure.
-
+-----+--------------+--------+------------+
-
| id | module_name | status | list_order |
-
+-----+--------------+--------+------------+
-
| 100 | 系統管理 | 1 | 2 |
-
| 600 | 環境管理 | 1 | 3 |
- +-----+--------------+--------+------------+
-
終端四對其它非慢查詢中的表進行查詢(不堵塞)
- 解決辦法:
- 殺掉原始慢查詢sql即可!
- xtrace版本2.2可加引數 --lock-wait-query-type=all
- xtrace版本2.4可加引數 --ftwrl-wait-query-type
- 該選項表示獲得全域性鎖之前允許那種查詢完成,預設是ALL,可選update。
原因:
在flush tables with read lock成功獲得鎖之前,必須等待所有語句執行完成(包括SELECT)。所以如果有個慢查詢在執行,或者一個開啟的事務,或者其他程式拿著表鎖,flush tables
with read lock就會被阻塞,直到所有的鎖被釋放。
-
The thread got a notification that the underlying structure for a table has changed
-
and it needs to reopen the table to get the new structure.
-
However, to reopen the table,
-
it must wait until all other threads have closed the table in question.
-
This notification takes place if another thread has used FLUSH TABLES
-
or one of the following statements on the table in question:
- FLUSH TABLES tbl_name, ALTER TABLE, RENAME TABLE, REPAIR TABLE, ANALYZE TABLE, orOPTIMIZE TABLE.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2144836/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL5.7 Waiting FOR TABLE FLUSHMySqlAI
- MySQL:Analyze table導致'waiting for table flush'MySqlAI
- 關於MYSQL flush table的作用MySql
- MySQL Cases-記錄大量waiting for handler commitMySqlAIMIT
- MySQL新增索引偶遇waiting for table metadata lockMySql索引AI
- MySQL DDL Waiting for table metadata lock 解決MySqlAI
- 7. 監控MySQL主從狀態MySql
- create table if not exists Waiting for table metadata lockAI
- MySQL:FLTWL的堵塞和被堵塞總結MySql
- Waiting for table metadata lockAI
- Shell指令碼監控MySQL主從狀態指令碼MySql
- mysql檢視主從同步狀態的方法MySql主從同步
- 【MySQL】select for update 的Row Lock 與Table LockMySql
- zabbix應用-監控mysql slave 主從狀態MySql
- Oracle table selectOracle
- Vuex 單狀態庫 與 多模組狀態庫Vue
- 關於 mysql 中的 select * from table_a,table_b 的問題MySql
- mysql主從同步(4)-Slave延遲狀態監控MySql主從同步
- Mysql:從一個USE DB堵塞故障展開的探討MySql
- mysql 大事物commit慢造成全庫堵塞問題MySqlMIT
- Oracle Create Table as SelectOracle
- MySQL:FTWRL一個奇怪的堵塞現象和堵塞總結MySql
- mysql flush 命令詳解MySql
- mysql下的flush操作MySql
- Waiting for table阻塞查詢的問題AI
- mysql 鎖狀態的一些狀態資訊記錄MySql
- 配置CACTI監控MySQL資料庫狀態(5)增加MySQL監控模板MySql資料庫
- 配置CACTI監控MySQL資料庫狀態(4)配置cactiMySql資料庫
- 【Mysql】FLUSH TABLES WITH READ LOCKMySql
- java中WAITING狀態的執行緒為啥還會消耗CPUJavaAI執行緒
- mysql關於FLUSH TABLES和FLUSH TABLES WITH READ LOCK的理解MySql
- oracle資料庫狀態Oracle資料庫
- MySQL 分析伺服器狀態MySql伺服器
- sqlserver不能直接create table as select ......SQLServer
- 配置CACTI監控MySQL資料庫狀態(1)準備工作MySql資料庫
- 配置CACTI監控MySQL資料庫狀態(3)配置apache模組MySql資料庫Apache
- 從MySQL大量資料清洗到TiBD說起MySql
- MySQL大量資料入庫的效能比較MySql