# Atomic Rename Updating one Table to Another

**URL:** <https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589>\
**Category:** MySQL & MariaDB\
**Tags:** mysql, percona\
**Created:** [July 15, 2022, 9:32am UTC](https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589 "2022-07-15T09:32:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon.ward](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@simon.ward](https://forums.percona.com/u/simon.ward)\
**Post date:** [July 15, 2022, 9:32am UTC](https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589/1 "2022-07-15T09:32:23Z")

</div>

I am trying to update one table in Mysql called blpu with updated rows from another table using online schema change. I had created a new identical table \_blpu and loaded the rows. When I run online schema change the original table stays the same. Neither table is a master or a slave to each other.

The command I used was  
pt-online-schema-change D=osdata, t=blpu, h=host.docker.internal, u=root, p=pwd --execute

I had tried to force the rename with  
pt-online-schema-change D=osdata,t=blpu,h=host.docker.internal,u=root,p=pwd RENAME TABLE ‘osdata.blpu’ TO ‘osdata.blpu\_old’, ‘osdata.\_blpu’ TO ‘osdata.blpu’ --execute

this throws an sql error plus the documentation says RENAME TABLE can’t be used. I am new to pt-online-schema-change please excuse my lack of knowledge on this.

OS is Ubuntu 22.04  
Mysql version 8.0.26

Thanks

Simon

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [July 15, 2022, 11:21am UTC](https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589/2 "2022-07-15T11:21:29Z")

</div>

Hello, you are misunderstanding how pt-osc works. I suggest you read through the documentation. You don’t need to explicitly rename the table or copy the rows, that happens as part of pt-online-schema-change automatically. Instead feed pt-osc the ALTER TABLE command that you want to run on the original table.

---

<div class="post-metadata">

**Author:** ![simon.ward](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@simon.ward](https://forums.percona.com/u/simon.ward)\
**Post date:** [July 15, 2022, 11:45am UTC](https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589/3 "2022-07-15T11:45:04Z")

</div>

Hi,

Read through the documentation, maybe missed how that scenario works, can add columns etc no problem, I don’t quite get how pt-osc would overwrite one table with another.

Thanks for your help

Simon

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [July 15, 2022, 12:50pm UTC](https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589/4 "2022-07-15T12:50:26Z")

</div>

Hello Simon, there is no overwrite. The general steps are:

1. new table gets created empty with the new structure
2. rows are copied from old to new table
3. while (2) happens, any on-going operations to the old table are replicated to the new table via triggers
4. when both old and new tables are in-sync, there is an atomic rename operation to put the new table in place of the old table

Hope that helps

---

<div class="post-metadata">

**Author:** ![simon.ward](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@simon.ward](https://forums.percona.com/u/simon.ward)\
**Post date:** [July 15, 2022, 1:55pm UTC](https://forums.percona.com/t/atomic-rename-updating-one-table-to-another/16589/5 "2022-07-15T13:55:10Z")

</div>

Hi Ivan.

Thank you that has made things a lot more clear.

Maybe I am using the wrong tool as the main thing I am doing is updating rows rather than making changes to the table’s structure itself. We will be adding columns etc to live tables regularly so pt-osc will be very useful for that.

Thanks

Simon
