未提交事務造成的等待事件

wolfreturn發表於2016-01-06
開發人員過來說程式中無法修改資料
 ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
 
檢視是如下SQL語句造成的
UPDATE
                MemberAttribute
        SET name = '而',required = 1, enabled = 1, sequence = 34
         
                , memberTemplate_id = 698
         
        WHERE
                id = 284 and deleted = false;

剛開始一直考慮死鎖,但一直無死鎖資訊

如果單獨的一條sql是不會千萬死鎖的,肯定有其他語句
檢視未提交的事務
SELECT
     a.trx_id,
     a.trx_state,
     a.trx_started,
     a.trx_query,
     b.ID,
     b.USER,
     b.DB,
     b.COMMAND,
     b.TIME,
     b.STATE,
     b.INFO,
     c.PROCESSLIST_USER,
     c.PROCESSLIST_HOST,
     c.PROCESSLIST_DB,
     d.SQL_TEXT
FROM
     information_schema.INNODB_TRX a
LEFT JOIN information_schema.PROCESSLIST b ON a.trx_mysql_thread_id = b.id
AND b.COMMAND = 'Sleep'
LEFT JOIN PERFORMANCE_SCHEMA.threads c ON b.id = c.PROCESSLIST_ID
LEFT JOIN PERFORMANCE_SCHEMA.events_statements_current d ON d.THREAD_ID = c.THREAD_ID;

確實有未提交事務

檢視未提交執行緒id
SELECT * FROM information_schema.INNODB_TRX \G
*************************** 12. row ***************************
                    trx_id: 188721461
                 trx_state: RUNNING
               trx_started: 2016-01-06 09:41:22
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 26
       trx_mysql_thread_id: 2122328
                 trx_query: NULL
       trx_operation_state: NULL
         trx_tables_in_use: 0
         trx_tables_locked: 0
          trx_lock_structs: 24
     trx_lock_memory_bytes: 6544
           trx_rows_locked: 3003
         trx_rows_modified: 2
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE READ
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 0
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
與niravana資料庫相關的程式只有2122328
kill 2122328
再次修改即可

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24742969/viewspace-1972497/,如需轉載,請註明出處,否則將追究法律責任。

相關文章