2016-12-09 103 views
3

我不是很大的表掛在ALTER命令上。會是什麼呢?MySQL掛在ALTER TABLE上

只有150k行,42個字段共142 MByte。 InnoDB存儲引擎和服務器版本:5.5.44-MariaDB MariaDB服務器。 1字段'slotindex'是主鍵:bigint(20)和BTREE類型。

的命令:

MariaDB [mydb]> ALTER TABLE `runs` CHANGE `p_w_trans_x` `p_w_tran_x` FLOAT NOT NULL; 
    Stage: 1 of 2 'copy to tmp table' 65.7% of stage done 
    Stage: 2 of 2 'Enabling keys'  0% of stage done 

將完全在這一階段永遠掛2.

ProcessList中然後如下:

MariaDB [(none)]> show full processlist; 
+--------+------+-----------------+-----------+---------+-------+---------------------------------+---------------------------------------------------------------------+----------+ 
| Id  | User | Host   | db  | Command | Time | State       | Info                | Progress | 
+--------+------+-----------------+-----------+---------+-------+---------------------------------+---------------------------------------------------------------------+----------+ 
| 274226 | root | localhost:45423 | edc_proxy | Sleep | 16043 |         | NULL                | 0.000 | 
| 274319 | root | localhost  | myDB  | Query | 99 | Waiting for table metadata lock | ALTER TABLE `runs` CHANGE `p_w_trans_x` `p_w_tran_x` FLOAT NOT NULL | 0.000 | 
| 274416 | root | localhost  | NULL  | Query |  0 | NULL       | show full processlist            | 0.000 | 
+--------+------+-----------------+-----------+---------+-------+---------------------------------+---------------------------------------------------------------------+----------+ 

answer表明檢查INFORMATION_SCHEMA表,而不是那裏:

MariaDB [INFORMATION_SCHEMA]> SELECT * FROM INNODB_LOCK_WAITS; 
Empty set (0.00 sec) 

MariaDB [INFORMATION_SCHEMA]> SELECT * FROM INNODB_LOCKS ; 
Empty set (0.00 sec) 

MariaDB [INFORMATION_SCHEMA]> SELECT * FROM INNODB_TRX; 
+----------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+ 
| trx_id | trx_state | trx_started   | trx_requested_lock_id | trx_wait_started | trx_weight | trx_mysql_thread_id | trx_query | trx_operation_state | trx_tables_in_use | trx_tables_locked | trx_lock_structs | trx_lock_memory_bytes | trx_rows_locked | trx_rows_modified | trx_concurrency_tickets | trx_isolation_level | trx_unique_checks | trx_foreign_key_checks | trx_last_foreign_key_error | trx_adaptive_hash_latched | trx_adaptive_hash_timeout | 
+----------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+ 
| 83A8B36E | RUNNING | 2016-12-08 11:13:02 | NULL     | NULL    |   0 |    274226 | NULL  | NULL    |     0 |     0 |    0 |     376 |    0 |     0 |      0 | REPEATABLE READ  |     1 |      1 | NULL      |       0 |      10000 | 
+----------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+ 
1 row in set (0.00 sec) 

而且從show engine innodb status;上交易的部分:

------------ 
TRANSACTIONS 
------------ 
Trx id counter 83A8F071 
Purge done for trx's n:o < 83A8CA86 undo n:o < 0 
History list length 1490 
LIST OF TRANSACTIONS FOR EACH SESSION: 
---TRANSACTION 0, not started 
MySQL thread id 274543, OS thread handle 0x7fbb863e6700, query id 85356480 localhost root 
show engine innodb status 
---TRANSACTION 83A8EB07, not started 
mysql tables in use 1, locked 2 
MySQL thread id 274542, OS thread handle 0x7fbb843f6700, query id 85354935 localhost root Waiting for table metadata lock 
ALTER TABLE `runs` CHANGE `p_w_trans_x` `p_w_tran_x` FLOAT NOT NULL 
---TRANSACTION 83A8B36E, ACTIVE 24627 sec 
MySQL thread id 274226, OS thread handle 0x7fbb845f5700, query id 85337236 localhost 127.0.0.1 root 
Trx read view will not see trx with id >= 83A8B36F, sees < 83A8B36D 
---------------------------- 
END OF INNODB MONITOR OUTPUT 
============================ 

任何指針作進一步調查,規避問題和解決的感謝!

+0

請參閱http://stackoverflow.com/a/13155778/166339 – Asaph

+0

我對MariaDB並不積極,但我知道當您執行大部分'ALTER'時,MySQL必須重新創建整個表;索引無關緊要。如果其他人正在訪問該表,或者在其上持有鎖,例如未提交的事務,則上面鏈接的Asaph應該可以幫助您找到它。 – Uueerdo

+0

@Asaph @Uueerdo感謝您的評論,我編輯了這個問題以包含這些建議。沒有其他進程正在運行或鎖定表,「顯示進程列表;'也反映了這一點,或者它們可能被隱藏在別的地方? – Bastiaan

回答

0

元數據鎖是一種隱式(從用戶角度來看)鎖,它可以防止DDL對該表造成影響,因爲其他情況下需要該表保留其當前形式。在這種情況下,這是一個已經運行的事務。

任務1:您的ALTER如果你殺死線程274226.

mysql> KILL 274226; 

問題的連接在這裏,通過information_schema.innodb_trx指示,一定會成功的,這個線程已經離開事務中運行幾個小時我們可以推斷該表已被該事務引用。在沒有交易者仍然擁有MVCC視圖或任何涉及該表的鎖之前,表不能被修改。這項交易持有一個觀點,我們可以再次推斷可能影響此表,如在最後一行:

--TRANSACTION 83A8B36E, ACTIVE 24627 sec 
MySQL thread id 274226, OS thread handle 0x7fbb845f5700, query id 85337236 localhost 127.0.0.1 root 
Trx read view will not see trx with id >= 83A8B36F, sees < 83A8B36D 

注意Sleep是不是一個真正的命令,在這種情況下,它只是佔位狀態用於任何空閒連接。所有連接都在做某些事情,在這種情況下,「某事」正在休眠 - 換句話說,空閒並等待另一個查詢。但是空閒連接仍然是一個連接,如果你的代碼(或查詢瀏覽器工具)讓事務繼續運行,它只會繼續運行。

任務2:找出遺漏該事務運行的錯誤或錯誤。在實時應用程序中,讓事務運行可能會造成更大的混亂。