Pt-online-schema-change use

Source: Internet
Author: User

The DB table structure of a company's business because of the constantly changing requirements, the table structure needs to be modified as the requirements change, changing the field type, adding fields.
The most bitter force is that two of the main tables are particularly large, a 5000W or more, the other one more scary to reach more than 100 million. Used to be partitioned, followed by
Given that the partitioning field has no practical significance, the advantages of partitioning have not been reflected, but it has played a role in the mind, and I do not know the design
from where to start, this year will be all the partition removed.
cut-in topic:
These two large tables to add fields, but not downtime, business release time is urgent. The idea was to use standby to operate first and then switch to master.
then change master again. Then cut back to master. But this way is faster, and we also use Pt-online-schema-change to do
Change the table structure online. However, this is not fast enough, a lot slower than the direct change, the direct change of 5 hours. Pt-online-schema-change takes 15 hours.
of course, time has increased, but the business has no impact, or is worth recommending, when there are standby words, the use of Pt-online-schema-change is good.
We make a small table structure change, just use the pt-online-schema-change.
The simple usage: own use is in the company business, relates to the specific table, inconvenient to disclose:
The following source networks:

Feature Description:

The function does not lock the table when the alter operation changes the table structure, that is, do not block the write and read operations when the ALTER is executed, and note that the tool must be backed up when it is executed, and it is best to read the official documents carefully before doing so.

It works by creating an empty table structure that is the same as the table you want to perform the alter operation, performing a table structure modification, and then copy the original data from the original table to the modified table of the table structure, when the data copy is completed, the original table is removed, the original table is replaced with the new table, and the default action is to drop the original During copy data, any update to the original table will be updated to the new table because the tool will create a trigger on the original table, and the trigger will update the content updated on the original table to the new table. If a trigger is already defined in the table, the tool will not work.

Usage Description:

Pt-online-schema-change [OPTIONS] DSN

Options can view Help,dns as the database and table you want to manipulate.

Here are two parameters to introduce:

--dry-run This parameter does not establish a trigger, does not copy data, and does not replace the original table. Just create and change the new table.

--execute This parameter, like the previous working principle, creates a trigger to ensure that the newly changed data affects the new table. Note: If you do not add this parameter, the tool will exit after performing some checks. The move is intended to allow the use of this tool to fully understand the principle, while reading the official documentation.

Examples of Use:

The engine of the online change table, which is especially useful when sorting out the InnoDB table, is as follows:

Pt-online-schema-change--user=root--password=xxxx--host=localhost--lock-wait-time=120--alter= "ENGINE=InnoDB" D= Test,t=oss_pvinfo2--execute

From the following log, you can see the execution process:

Altering ' test '. ' Oss_pvinfo2 ' ...

Creating New Table ...

Created new Table Test._oss_pvinfo2_new OK.

Altering new Table ...

Altered ' test '. ' _oss_pvinfo2_new ' OK.

Creating triggers ...

Created triggers OK.

Copying approximately 995696 rows ...

Copied rows OK.

Swapping tables ...

Swapped original and new tables OK.

Dropping old table ...

Dropped old table ' test '. ' _oss_pvinfo2_old ' OK.

Dropping triggers ...

Dropped triggers OK.

Successfully altered ' test '. ' Oss_pvinfo2 '.

In an example, the large table adds a field, and the statement is as follows:

Pt-online-schema-change--user=root--password=xxx--host=localhost--lock-wait-time=120--alter= "ADD COLUMN domain_ ID INT "D=test,t=oss_pvinfo2--execute

Pt-online-schema-change use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.