MySQL - pt-osc learning tool

MySQL - pt-osc learning tool

## ================================================ ## =====
pt-OSC's workflow:
1, check whether there are changes to table a primary key or unique index, if there is a trigger
2, check the table structure changes to the table, create a temporary table, ALTER execution on the new table tABLE statement
3, to create three flip-flops in the source table are for INSERT uPDATE DELETE operation
4, copy data from the source table to the temporary table, in the copy process, the source table update operations written to the new table
5, the source table and the temporary table rename (requires metadata to modify lock, need short lock table)
6, deleting the source table and triggers, modified table structure is completed.

## ================================================ ## ================
Pt-OSC limit the tool
1, the source table must have a primary key or a unique index, if not stop working tool
2, if the copying operation of the line filter environment is too complicated, the tool will not work
3, If the inspection opening replica delay, but the delay from the master tool to suspend copying of data
4, to open the main server load if the checks, but at higher loads the master server, a pause operation tool
5, when the foreign key table, if not use --alter-foreign-keys-method parameters, the tool can not be performed
6, only support Innodb table storage engine, and the table requires more than 1 times the free space on the server.

##=====================================================##

pt-osc of a unique index

When you create a unique index using pt-osc, will result in loss of data, the need to exercise caution:

1, duplicate data when the data columns in the table to create a unique index, the part of the duplicate data will be lost

2, if you insert a new data creation process, the new data with the original database duplicate, the original data is lost

Lost cause:

Since the trigger mode using INSERT and UPDATE REPLCAE INTO new table data update, the new table contains a unique index, resulting in a transition to the operation REPLACE INTO DELETE + INSERT operation, already exists in the new table duplicate records deleted, and then insert the current record, resulting in data loss.

## ================================================ ## ================
Pt-OSC copy of data
in the copying process the data, tool data will be split according to the primary or unique key, limiting the number of rows to ensure that each copy of the data for the copy, but consume more server resources. To ensure the same data source and target tables using LOCK IN SHARE MODE to get the latest data to copy the data segment and the data shared locks organization other answer modify data, using LOW_PRIORITY IGNORE to insert data into the new table, the keyword LOW_PRIORIT so that the insertion operation will wait for other operations to access the complete list will then perform keyword INGORE so that new data appear in the table are ignored and will not be inserted primary key or unique index key duplication.

Data copy script for table `testdb1`.`tb1001` be modified:

## to obtain a copy of the data at the border, forcing the index can effectively prevent the execution plan problems
SELECT / *! 40001 SQL_NO_CACHE * / `id` FROM` testdb1`.`tb1001` FORCE INDEX ( `PRIMARY`) WHERE ((` id`> = '8394306')) ORDER BY `id` LIMIT 22256, 2 / * next chunk boundary * /

## by copying data boundary limits, to prevent excessive single copy of the data block other long answer
INSERT LOW_PRIORITY IGNORE INTO `testdb1`.`_tb1001_new` (` id`, `c1`,` c6`) SELECT `id` , `c1`,` c6` FROM ` testdb1`.`tb1001` FORCE INDEX (` PRIMARY`) WHERE (( `id`> = '8394306')) AND ((` id` <= '8416562')) LOCK IN SHARE MODE / * pt-online -schema-change 14648 copy nibble * /


## ================================================ ## =====
pt-OSC of the flip-flop

pt-osc tool to create three AFTER triggers on the source table are for INSERT UPDATE DELETE operations, DELETE trigger use DELETE IGNORE to ensure that the data source table and the new table are deleted, and the INSERT and UPDATE triggers to use REPLACE INTO The new table data and ensure consistent data source table.

Since the same limits MySQL only one type of trigger, the trigger is required if there is to check before running on the source table, the processing to ensure the fragmentation efficiency and convenience deletes and updates the table and the source data, therefore requirements on the table primary key or unique index.

## ================================================ ===== ##
host performance impact of pt-osc

In order to avoid unduly affect the performance of the host, pt-osc tool is limited by the following aspects:
1, and chunk-size parameter chunk-time copy of the data size of each control
2, the host checks the current pressure parameter max-load, each after completion of the copy chunk views, runs SHOW GLOBAL STATUS LIKE 'Threads_running' command to check the number of currently running Threads default Threads_running = 25, if the maximum value is not specified, it will take 120% of the current value as the maximum value, and if it exceeds the valve copy data values will be suspended

## ================================================ ## =====
pt-delay from the OSC's database replication

For delay sensitive traffic replication, replication latency may be controlled by the following parameters:

--max-log
defaults to 1s, chunks after each copy is complete, view the check-slave-lag parameter specifies the delay information from the library, and if more than max-log threshold, data replication is suspended until replication latency max-log is less than the threshold. Check column Seconds_Behind_Master replica delay value dependent information SHOW SLAVE STATUS statement returned.

--check-interval
after the replica delay suspend replication occurs when the data in accordance with periodic inspection replica delay check-interval specified time, until the delay time is less than max-log threshold, then the data recovery copy

--check-slave-lag
need to check IP replication latency from the library
if you specify check-slave-lag parameters, and can not stop the connection from the library or from a library of normal IO thread and the SQL thread, I think that there is a delay from the master, causing the replication of data operation has been suspended.
If the check-slave-lag parameter is not specified, the default or delay checks from the library, but does not result in data replication replication latency pause.

## ================================================ ## ================
pt-osc disposed chunk of
the pt-osc help document, the following parameters regarding the chunk:
--chunk S-index = index for the this Prefer Tables CHUNKING

--chunk-index-columns=i Use only this many left-most columns of a --chunk-index

--chunk-size=z Number of rows to select for each chunk copied (default 1000)

--chunk-size-limit=f Do not copy chunks this much larger than the desired chunk size (default 4.0)

--chunk-time=f Adjust the chunk size dynamically so each data-copy query takes this long to execute (default 0.5)

When both chunk-size and chunk-time are not specified, the default chunk-size is 1000, chunk-time default value is 0.5S, chunk-size in accordance with the first data replication is performed, then in accordance with one copy of time dynamically resize chumk-size to accommodate changes in the performance of the server, a copy 1000 rows consumption as 0.1S, dynamically adjusting the next chumk-size 5000.
If the value is explicitly specified chumk-size chunk-time or to specify 0, the data is copied according to each chunk-size.

## ================================================ ## ================
Pt alter statement limiting the OSC-
1, does not need to alter table contains keywords may contain multiple modifications, separated by commas, such as "drop clolumn C1, C2 int the Add column"
2, does not support statement to rename a table rename operation
3, the index does not support the renaming operation
4, if you delete a foreign key, foreign key name needs to be underlined, such as deleting a foreign key fk_uid, modify the statement "DROP a fOREIGN kEY _fk_uid"
## ================================================== ## ===
pt-OSC of command template
## --execute that the implementation of
## --dry-run simulation testing indicates that only
## table name can only be used to set the parameter t, no long parameter
pt-online-schema -change \
--host = "127.0.0.1" \
--port = 3358 \
--user = "root" \
--password = "root @ root" \
--charset = "utf8" \
--max-LAG 10 = \
--check-LAG-Salve = 'xxx.xxx.xxx.xxx'\
--recursion-method="hosts" \
--check-interval=2 \
--database="testdb1" \
t="tb001" \
--alter="add column c4 int" \
--execute

##=====================================================##
pt-osc之命令输出
上面命令执行输出如下:
No slaves found. See --recursion-method if host 171DB166 has slaves.
Will check slave lag on:
170DB166
Operation, tries, wait:
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `testdb1`.`tb001`...
Creating new table...
Created new table testdb1._tb001_new OK.
Altering new table...
Altered `testdb1`.`_tb001_new` OK.
2016-04-28T23:18:04 Creating triggers...
2016-04-28T23:18:04 Created triggers OK.
2016-04-28T23:18:04 Copying approximately 1 rows...
2016-04-28T23:18:04 Copied rows OK.
2016-04-28T23:18:04 Swapping tables...
2016-04-28T23:18:04 Swapped original and new tables OK.
2016-04-28T23:18:04 Dropping old table...
2016-04-28T23:18:04 Dropped old table `testdb1`.`_tb001_old` OK.
2016-04-28T23:18:04 Dropping triggers...
2016-04-28T23:18:04 Dropped triggers OK.
Successfully altered `testdb1`.`tb001`.

##=====================================================##

 

Guess you like

Origin www.cnblogs.com/coco-caiyuan/p/11526976.html