# How does pt-online-schema-change drop old table?

**URL:** <https://forums.percona.com/t/how-does-pt-online-schema-change-drop-old-table/24943>\
**Category:** Percona Toolkit\
**Created:** [September 5, 2023, 3:06am UTC](https://forums.percona.com/t/how-does-pt-online-schema-change-drop-old-table/24943 "2023-09-05T03:06:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![360324761](https://avatars.discourse-cdn.com/v4/letter/3/a4c791/32.png) [@360324761](https://forums.percona.com/u/360324761)\
**Post date:** [September 5, 2023, 3:06am UTC](https://forums.percona.com/t/how-does-pt-online-schema-change-drop-old-table/24943/1 "2023-09-05T03:06:45Z")

</div>

Hi:  
mysql5.7  
percona\_tool 3.4

/bin/pt-online-schema-change --host=${host} --port=${port} --user=${user} --password=${passwd} --recursion-method=processlist --check-interval=1 --chunk-time=1 --max-lag=1 --no-version-check --charset=“utf8” --max-load=threads\_running:100 --chunk-size=2000 D=${database},t=${table}   
–alter=“ENGINE=InnoDB” --print --execute  
echo `date +"%Y-%m-%d %H:%M:%S"`  
echo ‘\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>End DDL\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>’

some of the log as:  
Copying `wxashop`.`wxa_user_coupon`: 96% 03:19 remain  
Copying `wxashop`.`wxa_user_coupon`: 96% 02:50 remain  
Copying `wxashop`.`wxa_user_coupon`: 97% 02:20 remain  
Copying `wxashop`.`wxa_user_coupon`: 97% 01:50 remain  
Copying `wxashop`.`wxa_user_coupon`: 98% 01:20 remain  
Copying `wxashop`.`wxa_user_coupon`: 99% 00:51 remain  
Copying `wxashop`.`wxa_user_coupon`: 99% 00:23 remain  
2023-09-04T18:40:09 Copied rows OK.  
2023-09-04T18:40:09 Analyzing new table…  
2023-09-04T18:40:09 Swapping tables…  
RENAME TABLE `wxashop`.`wxa_user_coupon` TO `wxashop`.`_wxa_user_coupon_old`, `wxashop`.`_wxa_user_coupon_new` TO `wxashop`.`wxa_user_coupon`  
2023-09-04T18:40:09 Swapped original and new tables OK.  
2023-09-04T18:40:09 Dropping old table…  
DROP TABLE IF EXISTS `wxashop`.`_wxa_user_coupon_old`  
2023-09-04T18:40:10 Dropped old table `wxashop`.`_wxa_user_coupon_old` OK.  
2023-09-04T18:40:10 Dropping triggers…  
DROP TRIGGER IF EXISTS `wxashop`.`pt_osc_wxashop_wxa_user_coupon_del`  
DROP TRIGGER IF EXISTS `wxashop`.`pt_osc_wxashop_wxa_user_coupon_upd`  
DROP TRIGGER IF EXISTS `wxashop`.`pt_osc_wxashop_wxa_user_coupon_ins`  
2023-09-04T18:40:10 Dropped triggers OK.  
Successfully altered `wxashop`.`wxa_user_coupon`.  
2023-09-04 18:40:10

> > > > > > > > > > > > > > > > End DDL\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>

2023-09-04T18:40:09 Dropping old table… There is a 4-second delay on the slave database relative to the master database.

Under the same environment:  
When I execute the command mysql -h 172.1.1.7 -P3306 -uuser -ppassword -e ‘DROP TABLE IF EXISTS wxashop.\_wxa\_user\_coupon\_old;’, there is a delay of 12 seconds.

How does pt-online-schema-change achieve it?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [September 5, 2023, 4:54pm UTC](https://forums.percona.com/t/how-does-pt-online-schema-change-drop-old-table/24943/2 "2023-09-05T16:54:44Z")

</div>

pt-osc isn’t doing anything magic. It executes the same query as you are. You are using an inaccurate measurement of lag (Seconds\_behind\_master). Replica lag can be caused by any number of transactions running on the replica.  
Is your replica the same spec hardware? Same my.cnf config? Are you running parallel replica threads?  
If you want more accurate timing, run pt-heartbeat with parallel replica workers.  
You can also run pt-osc using `PTDEBUG=1 pt-online-schema-change ...` and see all the exact SQL being executed.

---

<div class="post-metadata">

**Author:** ![360324761](https://avatars.discourse-cdn.com/v4/letter/3/a4c791/32.png) [@360324761](https://forums.percona.com/u/360324761)\
**Post date:** [September 6, 2023, 8:32am UTC](https://forums.percona.com/t/how-does-pt-online-schema-change-drop-old-table/24943/3 "2023-09-06T08:32:57Z")

</div>

Hi:  
I try to get the source code about it , you are right .

Think you!!
