# Deadlock Encountered when using pt-online-schema-change

**URL:** <https://forums.percona.com/t/deadlock-encountered-when-using-pt-online-schema-change/4698>\
**Category:** Percona Toolkit\
**Created:** [February 2, 2016, 10:24am UTC](https://forums.percona.com/t/deadlock-encountered-when-using-pt-online-schema-change/4698 "2016-02-02T10:24:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eiosis](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@eiosis](https://forums.percona.com/u/eiosis)\
**Post date:** [February 2, 2016, 10:24am UTC](https://forums.percona.com/t/deadlock-encountered-when-using-pt-online-schema-change/4698/1 "2016-02-02T10:24:23Z")

</div>

I have a shell script looping 1000 times, doing inserts into a database table.  
I am running pt-online-schema-change, creating a unique index on a column in that table.  
pt-online-schema-change --alter-foreign-keys-method=auto --alter=“ADD UNIQUE INDEX UQ\_E\_ID (E\_ID)” --execute h=localhost,u=xx,p=\*\*,D=db,t=t1

My shell script reports  
./do\_sql.sh  
ERROR 1213 (40001) at line 1: Deadlock found when trying to get lock; try restarting transaction

The deadlock reported is  
pt-deadlock-logger h=localhost,u=xx,p=\*\*,D=db,t=t1  
server ts thread txn\_id txn\_time user hostname ip db tbl idx lock\_type lock\_mode wait\_hold victim query  
localhost 2016-02-02T10:40:06 13616 0 0 root localhost db t1 PRIMARY RECORD S w 0 INSERT LOW\_PRIORITY IGNORE INTO `db.`\_t1\_new` (`uid`, `name`, `accountid`, `deleted`, `e\_id`, `parent\_id`, `classification`) SELECT `uid`, `name`, `accountid`, `deleted`, `e\_id`, `parent\_id`, `classification`FROM`db`.`t1`LOCK IN SHARE MODE /*pt-online-schema-change 23347 copy table*/ localhost 2016-02-02T10:40:06 13847 0 0 root localhost db _t1_new TABLE AUTO-INC w 1 REPLACE INTO`db`.`\_t1\_new` (`uid`, `name`, `accountid`, `deleted`, `e\_id`, `parent\_id`, `classification`) VALUES (NEW.`uid`, NEW.`name`, NEW.`accountid`, NEW.`deleted`, NEW.`e\_id`, NEW.`parent\_id`, NEW.`classification`)

We are seriously considering using this tool to prevent downtime in our application when we need to modify our database schema, but am quite concerned by this finding. Can anyone suggest work-arounds or problems with my commands.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![eiosis](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@eiosis](https://forums.percona.com/u/eiosis)\
**Post date:** [February 2, 2016, 10:28am UTC](https://forums.percona.com/t/deadlock-encountered-when-using-pt-online-schema-change/4698/2 "2016-02-02T10:28:02Z")

</div>

mysql\> show variables like ‘%version%’;  
±------------------------±------------------------+  
| Variable\_name | Value |  
±------------------------±------------------------+  
| innodb\_version | 5.5.46 |  
| protocol\_version | 10 |  
| slave\_type\_conversions | |  
| version | 5.5.46-0ubuntu0.14.04.2 |  
| version\_comment | (Ubuntu) |  
| version\_compile\_machine | x86\_64 |  
| version\_compile\_os | debian-linux-gnu |  
±------------------------±------------------------+  
7 rows in set (0.00 sec)

pt-online-schema-change --version  
pt-online-schema-change 2.2.14
