user3525290
user3525290

Reputation: 1617

mysql transaction loct stuck

I am updating a table and I seem to have a lock and it will not release. If i am reading this correctly the transaction 2 has been rolled back, but transaction 1 is still locking my table. Is there a way to force kill the transaction and roll it back?

*** (1) TRANSACTION:
TRANSACTION 421886199343912, ACTIVE 5 sec fetching rows
mysql tables in use 3, locked 3
LOCK WAIT 224788 lock struct(s), heap size 25419896, 2349612 row lock(s)
MySQL thread id 2967966, OS thread handle 140383641106176, query id 458710084 web.pub 192.168.2.57 user1 executing  
INSERT IGNORE into file_search select distinct f.id, f.basename,f.filename,f.filesize as   ...
 *** (1) HOLDS THE LOCK(S):
 RECORD LOCKS space id 2272 page no 2238466 n bits 456 index datatype_sensor_basename_idx of table `datastore`.`files` trx id 421886199343912 lock mode S waiting
 Record lock, heap no 215 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
 0: len 2; hex 8411; asc   ;;
 1: len 2; hex 8007; asc   ;;
 2: len 27; hex 41323032313331313231343030302e4c325f4c41435f4f432e6e63; asc   fill.pdf;;
 3: len 4; hex 0b103a5a; asc   :Z;;

 *** (1) WAITING FOR THIS LOCK TO BE GRANTED:
 RECORD LOCKS space id 2272 page no 2238466 n bits 456 index datatype_sensor_basename_idx  of table `datastore`.`files` trx id 421886199343912 lock mode S waiting
 Record lock, heap no 215 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
 0: len 2; hex 8411; asc   ;;
 1: len 2; hex 8007; asc   ;;
 2: len 27; hex 41323032313331313231343030302e4c325f4c41435f4f432e6e63; asc  file2.pdf;;
 3: len 4; hex 0b103a5a; asc   :Z;;

 *** (2) TRANSACTION:
 TRANSACTION 850180982, ACTIVE 33 sec updating or deleting
 mysql tables in use 1, locked 1
 LOCK WAIT 893 lock struct(s), heap size 123000, 16885 row lock(s), undo log entries 14091
 MySQL thread id 3045015, OS thread handle 140383648741120, query id 458721905   web.pub 192.168.2.187 user1 updating
 UPDATE files SET ... where id = 100
 *** (2) HOLDS THE LOCK(S):                                                                                                                                              RECORD LOCKS space id 2272 page no 2238466 n bits 456 index datatype_sensor_basename_idx of   table `datastore`.`files` trx id 850180982 lock_mode X locks rec but not gap
Record lock, heap no 215 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 2; hex 8411; asc   ;;
1: len 2; hex 8007; asc   ;;
2: len 27; hex 41323032313331313231343030302e4c325f4c41435f4f432e6e63; asc   file3.pdf;;
3: len 4; hex 0b103a5a; asc   :Z;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:                                                                                                                           RECORD LOCKS space id 2272 page no 2238466 n bits 456 index datatype_sensor_basename_idx of   table `datastore`.`files` trx id 850180982 lock_mode X locks gap before rec insert intention   waiting
 Record lock, heap no 215 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
 0: len 2; hex 8411; asc   ;;
 1: len 2; hex 8007; asc   ;;
 2: len 27; hex 41323032313331313231343030302e4c325f4c41435f4f432e6e63; asc A2021311214000.L2_LAC_OC.nc;;
 3: len 4; hex 0b103a5a; asc   :Z;;
 *** WE ROLL BACK TRANSACTION (2)

Upvotes: 0

Views: 393

Answers (1)

utdrmac
utdrmac

Reputation: 781

You can kill a query/connection in MySQL using https://dev.mysql.com/doc/refman/8.0/en/kill.html

I also notice the (S)hared locks in use. These typically appear only when you are using FOREIGN KEYS. The recommendation to reduce deadlocks like this is to simply remove the FKs and implement in code instead.

Upvotes: 1

Related Questions