# pt-online-schema swapping tables

**URL:** <https://forums.percona.com/t/pt-online-schema-swapping-tables/6685>\
**Category:** Percona Toolkit\
**Created:** [November 15, 2018, 12:43pm UTC](https://forums.percona.com/t/pt-online-schema-swapping-tables/6685 "2018-11-15T12:43:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smith18](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@smith18](https://forums.percona.com/u/smith18)\
**Post date:** [November 15, 2018, 12:43pm UTC](https://forums.percona.com/t/pt-online-schema-swapping-tables/6685/1 "2018-11-15T12:43:59Z")

</div>

.I did some research on pt-online-schema-change but still couldn’t figure out on when table swapping happens – if my application is still running and rows are still being added continuously then at what point percona makes decisions to swap the old and new tables? – anyone ideas or suggestions on when swapping tables happens without losing my incoming data-- I really don’t want to lose any data as there is no way to recover the lost rows. – any help would be appreciated

---

<div class="post-metadata">

**Author:** ![carlos.salguero](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/carlos.salguero/32/20_2.png) [@carlos.salguero](https://forums.percona.com/u/carlos.salguero)\
**Post date:** [November 16, 2018, 8:25am UTC](https://forums.percona.com/t/pt-online-schema-swapping-tables/6685/2 "2018-11-16T08:25:32Z")

</div>

At the end of the process, online-schema-change does a table rename like

```auto
RENAME TABLE original_table TO table_new, temp_table TO original_table.

```

Since this is an atomic operation, even if there are queries being executed on the server, they won’t be affected and they will be executed in the new altered table.

Regards

---

<div class="post-metadata">

**Author:** ![smith18](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@smith18](https://forums.percona.com/u/smith18)\
**Post date:** [November 19, 2018, 10:29am UTC](https://forums.percona.com/t/pt-online-schema-swapping-tables/6685/3 "2018-11-19T10:29:46Z")

</div>

will there be any lock on the table during the rename operation happens?

---

<div class="post-metadata">

**Author:** ![carlos.salguero](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/carlos.salguero/32/20_2.png) [@carlos.salguero](https://forums.percona.com/u/carlos.salguero)\
**Post date:** [November 19, 2018, 1:01pm UTC](https://forums.percona.com/t/pt-online-schema-swapping-tables/6685/4 "2018-11-19T13:01:18Z")

</div>

The program is not adding any extra lock. RENAME is an atomic operation and there won’t be queries affected by it.
