pt-osc实战运用

1、安装pt-osc,解压即可用

安装包在:10.135.2.217:data/online/software/percona-toolkit-3.0.12.tar.gz
tar -zxvf percona-toolkit-3.0.12.tar.gz
cd percona-toolkit-3.0.12/bin
cp pt-online-schema-change /usr/bin/

2、常用命令

pt-online-schema-change \
--host=10.249.5.39 \
--port=3306 \
--user=xxxx \
--password=xxxx \
--alter "add column c4 varchar(8) not null default '' " \
D=darren \
t=t_user \
--execute

3、常用参数解释

--alter-foreign-keys-method=s
设置修改外键的方式,一共有如下4个值:
auto:优先选择rebuild_constraints方式处理外键,如果该方式不可用才选择drop_swap;
rebuild_constraints:在最后rename表后,删除子表上的外键,并进行重新建立到新表的外键。
drop_swap:拷贝数据后,设置SET foreign_key_checks=0,直接将原表drop掉,然后rename临时表为新表
none:表示强制不考虑子表外键约束,设置SET foreign_key_checks=0,最终会导致子表外键约束到_table_old这个已删除的表上,不建议使用
--max-load string
string是状态表达式,默认Threads_running=25,当设置多个状态值,用逗号分隔,如'Threads_running=100,Threads_connected=500',当超过该值,迁移暂停等待,通过sleep方式暂停
--critical-load
与max-load不同的是,当超过该值,迁移直接停止并退出,默认值是Threads_running=50
--max-lag=m
默认1s,检查slave延迟的值,超过1秒则暂停复制数据

4、输出日志分析

2018-10-17T13:43:01.414577+08:00        5892279 Connect dbadmin@10.249.5.39 on test using TCP/IP
2018-10-17T13:43:01.415106+08:00 5892279 Query set autocommit=1
2018-10-17T13:43:01.415645+08:00 5892279 Query SHOW VARIABLES LIKE 'innodb\_lock_wait_timeout'
2018-10-17T13:43:01.416889+08:00 5892279 Query SET SESSION innodb_lock_wait_timeout=1
2018-10-17T13:43:01.417276+08:00 5892279 Query SHOW VARIABLES LIKE 'lock\_wait_timeout'
2018-10-17T13:43:01.418441+08:00 5892279 Query SET SESSION lock_wait_timeout=60
2018-10-17T13:43:01.418874+08:00 5892279 Query SHOW VARIABLES LIKE 'wait\_timeout'
2018-10-17T13:43:01.419934+08:00 5892279 Query SET SESSION wait_timeout=10000
2018-10-17T13:43:01.420280+08:00 5892279 Query SELECT @@SQL_MODE
2018-10-17T13:43:01.420588+08:00 5892279 Query SET @@SQL_QUOTE_SHOW_CREATE = 1/*!40101, @@SQL_MODE='NO_AUTO_VALUE_ON_ZERO'*/
2018-10-17T13:43:01.420904+08:00 5892279 Query SELECT @@server_id /*!50038 , @@hostname*/
2018-10-17T13:43:01.422513+08:00 5892280 Connect dbadmin@10.249.5.39 on test using TCP/IP
2018-10-17T13:43:01.422827+08:00 5892280 Query set autocommit=1
2018-10-17T13:43:01.423249+08:00 5892280 Query SHOW VARIABLES LIKE 'innodb\_lock_wait_timeout'
2018-10-17T13:43:01.424386+08:00 5892280 Query SET SESSION innodb_lock_wait_timeout=1
2018-10-17T13:43:01.424691+08:00 5892280 Query SHOW VARIABLES LIKE 'lock\_wait_timeout'
2018-10-17T13:43:01.425711+08:00 5892280 Query SET SESSION lock_wait_timeout=60
2018-10-17T13:43:01.425999+08:00 5892280 Query SHOW VARIABLES LIKE 'wait\_timeout'
2018-10-17T13:43:01.426917+08:00 5892280 Query SET SESSION wait_timeout=10000
2018-10-17T13:43:01.427248+08:00 5892280 Query SELECT @@SQL_MODE
2018-10-17T13:43:01.427518+08:00 5892280 Query SET @@SQL_QUOTE_SHOW_CREATE = 1/*!40101, @@SQL_MODE='NO_AUTO_VALUE_ON_ZERO'*/
2018-10-17T13:43:01.427815+08:00 5892280 Query SELECT @@server_id /*!50038 , @@hostname*/
2018-10-17T13:43:01.428328+08:00 5892279 Query SHOW VARIABLES LIKE 'wsrep_on'
2018-10-17T13:43:01.429502+08:00 5892279 Query SHOW VARIABLES LIKE 'version%'
2018-10-17T13:43:01.430939+08:00 5892279 Query SHOW ENGINES
2018-10-17T13:43:01.431887+08:00 5892279 Query SHOW VARIABLES LIKE 'innodb_version'
2018-10-17T13:43:01.433792+08:00 5892279 Query SHOW VARIABLES LIKE 'innodb_stats_persistent'
2018-10-17T13:43:01.435051+08:00 5892279 Query SELECT @@SERVER_ID
2018-10-17T13:43:01.435445+08:00 5892279 Query SHOW GRANTS FOR CURRENT_USER()
2018-10-17T13:43:01.435940+08:00 5892279 Query SHOW FULL PROCESSLIST
2018-10-17T13:43:01.437507+08:00 5892281 Connect dbadmin@10.249.5.39 on using TCP/IP
2018-10-17T13:43:01.437790+08:00 5892281 Query set autocommit=1
2018-10-17T13:43:01.438283+08:00 5892281 Query SHOW VARIABLES LIKE 'innodb\_lock_wait_timeout'
2018-10-17T13:43:01.439414+08:00 5892281 Query SET SESSION innodb_lock_wait_timeout=1
2018-10-17T13:43:01.439725+08:00 5892281 Query SHOW VARIABLES LIKE 'lock\_wait_timeout'
2018-10-17T13:43:01.440783+08:00 5892281 Query SET SESSION lock_wait_timeout=60
2018-10-17T13:43:01.441155+08:00 5892281 Query SHOW VARIABLES LIKE 'wait\_timeout'
2018-10-17T13:43:01.442144+08:00 5892281 Query SET SESSION wait_timeout=10000
2018-10-17T13:43:01.442410+08:00 5892281 Query SELECT @@SQL_MODE
2018-10-17T13:43:01.442677+08:00 5892281 Query SET @@SQL_QUOTE_SHOW_CREATE = 1/*!40101, @@SQL_MODE='NO_AUTO_VALUE_ON_ZERO'*/
2018-10-17T13:43:01.442971+08:00 5892281 Query SELECT @@SERVER_ID
2018-10-17T13:43:01.443218+08:00 5892281 Quit
2018-10-17T13:43:01.443878+08:00 5892279 Query SHOW GLOBAL STATUS LIKE 'Threads_running'
2018-10-17T13:43:01.444693+08:00 5892279 Query SHOW GLOBAL STATUS LIKE 'Threads_running'
2018-10-17T13:43:01.445606+08:00 5892279 Query SELECT CONCAT(@@hostname, @@port)
2018-10-17T13:43:01.446302+08:00 5892279 Query SHOW TABLES FROM `test` LIKE 'foo'
2018-10-17T13:43:01.446768+08:00 5892279 Query SELECT VERSION()
2018-10-17T13:43:01.447179+08:00 5892279 Query SHOW TRIGGERS FROM `test` LIKE 'foo'
2018-10-17T13:43:01.448039+08:00 5892279 Query /*!40101 SET @OLD_SQL_MODE := @@SQL_MODE, @@SQL_MODE := '', @OLD_QUOTE := @@SQL_QUOTE_SHOW_CREATE, @@SQL_QUOTE_SHOW_CREATE := 1 */
2018-10-17T13:43:01.448296+08:00 5892279 Query USE `test`
2018-10-17T13:43:01.448577+08:00 5892279 Query SHOW CREATE TABLE `test`.`foo`
2018-10-17T13:43:01.449391+08:00 5892279 Query /*!40101 SET @@SQL_MODE := @OLD_SQL_MODE, @@SQL_QUOTE_SHOW_CREATE := @OLD_QUOTE */
2018-10-17T13:43:01.450129+08:00 5892279 Query EXPLAIN SELECT * FROM `test`.`foo` WHERE 1=1
2018-10-17T13:43:01.450998+08:00 5892279 Query SELECT table_schema, table_name FROM information_schema.key_column_usage WHERE referenced_table_schema='test' AND referenced_table_name='foo'
2018-10-17T13:43:01.462372+08:00 5892279 Query EXPLAIN SELECT * FROM `test`.`bar` WHERE 1=1
2018-10-17T13:43:01.463628+08:00 5892279 Query SHOW VARIABLES LIKE 'wsrep_on'
2018-10-17T13:43:01.464892+08:00 5892279 Query /*!40101 SET @OLD_SQL_MODE := @@SQL_MODE, @@SQL_MODE := '', @OLD_QUOTE := @@SQL_QUOTE_SHOW_CREATE, @@SQL_QUOTE_SHOW_CREATE := 1 */
2018-10-17T13:43:01.465176+08:00 5892279 Query USE `test`
2018-10-17T13:43:01.465476+08:00 5892279 Query SHOW CREATE TABLE `test`.`foo`
2018-10-17T13:43:01.465817+08:00 5892279 Query /*!40101 SET @@SQL_MODE := @OLD_SQL_MODE, @@SQL_QUOTE_SHOW_CREATE := @OLD_QUOTE */
2018-10-17T13:43:01.466230+08:00 5892279 Query CREATE TABLE `test`.`_foo_new` (
`foo_id` int(11) NOT NULL,
PRIMARY KEY (`foo_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
2018-10-17T13:43:01.487029+08:00 5892279 Query ALTER TABLE `test`.`_foo_new` engine=innodb
2018-10-17T13:43:01.521293+08:00 5892279 Query /*!40101 SET @OLD_SQL_MODE := @@SQL_MODE, @@SQL_MODE := '', @OLD_QUOTE := @@SQL_QUOTE_SHOW_CREATE, @@SQL_QUOTE_SHOW_CREATE := 1 */
2018-10-17T13:43:01.521614+08:00 5892279 Query USE `test`
2018-10-17T13:43:01.522134+08:00 5892279 Query SHOW CREATE TABLE `test`.`_foo_new`
2018-10-17T13:43:01.522487+08:00 5892279 Query /*!40101 SET @@SQL_MODE := @OLD_SQL_MODE, @@SQL_QUOTE_SHOW_CREATE := @OLD_QUOTE */
2018-10-17T13:43:01.523664+08:00 5892279 Query SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_MANIPULATION = 'DELETE' AND ACTION_TIMING = 'AFTER' AND TRIGGER_SCHEMA = 'test' AND EVENT_OBJECT_TABLE = 'foo'
2018-10-17T13:43:01.525314+08:00 5892279 Query SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_MANIPULATION = 'UPDATE' AND ACTION_TIMING = 'AFTER' AND TRIGGER_SCHEMA = 'test' AND EVENT_OBJECT_TABLE = 'foo'
2018-10-17T13:43:01.526610+08:00 5892279 Query SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_MANIPULATION = 'INSERT' AND ACTION_TIMING = 'AFTER' AND TRIGGER_SCHEMA = 'test' AND EVENT_OBJECT_TABLE = 'foo'
2018-10-17T13:43:01.527913+08:00 5892279 Query SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_MANIPULATION = 'DELETE' AND ACTION_TIMING = 'BEFORE' AND TRIGGER_SCHEMA = 'test' AND EVENT_OBJECT_TABLE = 'foo'
2018-10-17T13:43:01.529203+08:00 5892279 Query SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_MANIPULATION = 'UPDATE' AND ACTION_TIMING = 'BEFORE' AND TRIGGER_SCHEMA = 'test' AND EVENT_OBJECT_TABLE = 'foo'
2018-10-17T13:43:01.530485+08:00 5892279 Query SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, CHARACTER_SET_CLIENT, COLLATION_CONNECTION, EVENT_MANIPULATION, ACTION_TIMING FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_MANIPULATION = 'INSERT' AND ACTION_TIMING = 'BEFORE' AND TRIGGER_SCHEMA = 'test' AND EVENT_OBJECT_TABLE = 'foo'
2018-10-17T13:43:01.531854+08:00 5892279 Query CREATE TRIGGER `pt_osc_test_foo_del` AFTER DELETE ON `test`.`foo` FOR EACH ROW DELETE IGNORE FROM `test`.`_foo_new` WHERE `test`.`_foo_new`.`foo_id` <=> OLD.`foo_id`
2018-10-17T13:43:01.536997+08:00 5892279 Query CREATE TRIGGER `pt_osc_test_foo_upd` AFTER UPDATE ON `test`.`foo` FOR EACH ROW BEGIN DELETE IGNORE FROM `test`.`_foo_new` WHERE !(OLD.`foo_id` <=> NEW.`foo_id`) AND `test`.`_foo_new`.`foo_id` <=> OLD.`foo_id`;REPLACE INTO `test`.`_foo_new` (`foo_id`) VALUES (NEW.`foo_id`);END
2018-10-17T13:43:01.541525+08:00 5892279 Query CREATE TRIGGER `pt_osc_test_foo_ins` AFTER INSERT ON `test`.`foo` FOR EACH ROW REPLACE INTO `test`.`_foo_new` (`foo_id`) VALUES (NEW.`foo_id`)
2018-10-17T13:43:01.548005+08:00 5892279 Query EXPLAIN SELECT * FROM `test`.`foo` WHERE 1=1
2018-10-17T13:43:01.549823+08:00 5892279 Query EXPLAIN SELECT `foo_id` FROM `test`.`foo` LOCK IN SHARE MODE /*explain pt-online-schema-change 31654 copy table*/
2018-10-17T13:43:01.550622+08:00 5892279 Query INSERT LOW_PRIORITY IGNORE INTO `test`.`_foo_new` (`foo_id`) SELECT `foo_id` FROM `test`.`foo` LOCK IN SHARE MODE /*pt-online-schema-change 31654 copy table*/
2018-10-17T13:43:01.554366+08:00 5892279 Query SHOW WARNINGS
2018-10-17T13:43:01.554959+08:00 5892279 Query SHOW GLOBAL STATUS LIKE 'Threads_running'
2018-10-17T13:43:01.556226+08:00 5892279 Query ANALYZE TABLE `test`.`_foo_new` /* pt-online-schema-change */
2018-10-17T13:43:01.561668+08:00 5892279 Query RENAME TABLE `test`.`foo` TO `test`.`_foo_old`, `test`.`_foo_new` TO `test`.`foo`
2018-10-17T13:43:01.583926+08:00 5892279 Query /*!40101 SET @OLD_SQL_MODE := @@SQL_MODE, @@SQL_MODE := '', @OLD_QUOTE := @@SQL_QUOTE_SHOW_CREATE, @@SQL_QUOTE_SHOW_CREATE := 1 */
2018-10-17T13:43:01.584256+08:00 5892279 Query USE `test`
2018-10-17T13:43:01.584536+08:00 5892279 Query SHOW CREATE TABLE `test`.`bar`
2018-10-17T13:43:01.584904+08:00 5892279 Query /*!40101 SET @@SQL_MODE := @OLD_SQL_MODE, @@SQL_QUOTE_SHOW_CREATE := @OLD_QUOTE */
2018-10-17T13:43:01.585580+08:00 5892279 Query ALTER TABLE `test`.`bar` DROP FOREIGN KEY `__bar_ibfk_1`, ADD CONSTRAINT `bar_ibfk_1` FOREIGN KEY (`foo_id`) REFERENCES `test`.`foo` (`foo_id`)
2018-10-17T13:43:01.618352+08:00 5892279 Query DROP TABLE IF EXISTS `test`.`_foo_old`
2018-10-17T13:43:01.643179+08:00 5892279 Query DROP TRIGGER IF EXISTS `test`.`pt_osc_test_foo_del`
2018-10-17T13:43:01.645349+08:00 5892279 Query DROP TRIGGER IF EXISTS `test`.`pt_osc_test_foo_upd`
2018-10-17T13:43:01.646829+08:00 5892279 Query DROP TRIGGER IF EXISTS `test`.`pt_osc_test_foo_ins`
2018-10-17T13:43:01.649537+08:00 5892279 Query SHOW TABLES FROM `test` LIKE '\_foo\_new'
2018-10-17T13:43:01.650436+08:00 5892280 Quit
2018-10-17T13:43:01.651462+08:00 5892279 Quit

pt-osc使用方法的更多相关文章

  1. PT教程 - 应用系列 - ECO修复Timing(理论+实践+脚本分享)

    ​本文转自:自己的微信公众号<集成电路设计及EDA教程> <PT教程 - 应用系列 - ECO修复Timing(理论+实践+脚本分享)> 这篇推文讲一下数字IC设计中的post ...

  2. 利用java反射调用类的的私有方法--转

    原文:http://blog.csdn.net/woshinia/article/details/11766567 1,今天和一位朋友谈到父类私有方法的调用问题,本来以为利用反射很轻松就可以实现,因为 ...

  3. OpenCV2:特征匹配及其优化

    在OpenCV2简单的特征匹配中对使用OpenCV2进行特征匹配的步骤做了一个简单的介绍,其匹配出的结果是非常粗糙的,在这篇文章中对使用OpenCV2进行匹配的细化做一个简单的总结.主要包括以下几个内 ...

  4. 自己家里搭建NAS服务器有什么好方案?

    转自:https://www.zhihu.com/question/21359049 作者:陈二发链接:https://www.zhihu.com/question/21359049/answer/6 ...

  5. Android FM 模块学习之四 源码解析(1)

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 前一章我们了解了FM手动调频,接下 ...

  6. 2.1孙鑫C++

    0.vc++6.0 工程---win32控制台程序            文件---c++ 1.建立结构体 #include <iostream.h> struct Point { int ...

  7. Apache开启伪静态后报500错误.

    参考:http://blog.163.com/lgh_2002/blog/static/44017526201051452939761/ 加载Rewrite模块: 在conf目录下httpd.conf ...

  8. 25045操作标准子程序集41.C

    /* ;程 序 最 后 修 改 时 间 0-4-3 23:43 ;软 件 标 题:25045操作标准子程序集41 ;软 件 说 明:25045 I2C 串行EEPROM 驱动 ;___________ ...

  9. thinkphp5.0如何隐藏index.php入口文件

    隐藏入口文件 public/index.php 同级的.htaccess文件 [ Apache ] 方法1: <IfModule mod_rewrite.c> Options +Follo ...

  10. 【COCOS2DX-游戏开发之三一】之 坐标系(下) convertToNodeSpace和convertToWorldSpace

    游戏中常常会用到一些变换: 游戏中武器和角色在一个layer上,为了效率.会考虑将bullet, effect和 PhysicsParticle分别放到不用的层上,相应的层上使用batchnode来提 ...

随机推荐

  1. 【BZOJ】1632: [Usaco2007 Feb]Lilypad Pond(bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1632 我简直是个sb... ... bfs都不会写.. 算方案还用2个bfs! 都不会整合到一个! ...

  2. VC++ Debug显示指针所指的array内容

    If you expand a pointer and you only get a single item, just add ",n" to the entry in the ...

  3. PowerDesigner最基础的使用方法入门学习2

    from:http://www.cnblogs.com/huangcong/archive/2010/06/14/1757957.html 最近要忙期考,但还是决定每天抽点空来写CodeSmith的系 ...

  4. FOJ 1402(dp推规律)

    推规律吧 /** 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  5. 第一篇:《UNIX 环境高级编程》编译环境的搭建

    第一步:搭建基本的编译环境 安装gcc, g++, bulid-essential等编译软件 第二步:下载本书示例源码包 可在这里下载 www.apuenook.com 第三步:解压下载到的包并放在用 ...

  6. 69、ViewPagerIndicator+ViewPager实现Tab

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  7. 搭建一个简单的基于web的网络流量监控可视化系统

    本文转载于我的个人博客,转载请标明出处. 初衷 在腾讯云的学生认证申请提交上去n天之后,终于得到了审批,所以迫不及待的想玩玩腾讯云,作为一个搞网络的,自然有一些关于网络应用的小玩意,所以把以前部署过的 ...

  8. spring boot rabbitmq 多MQ配置 自动 创建 队列 RPC

      源码地址:https://github.com/hutuchong518/RabbitmqStudy 需求:   spring boot 整合 rabbitmq rpc功能, 需要将 请求和响应 ...

  9. storyboard设置navigation controller

    到storyboard选中我们唯一一个的viewcontroller,找到xcode的菜单栏,Edit->Embed In->NavigationController.这时候storybo ...

  10. Mac下安装apk(命令形式)

    1 连接上设备 2 卸载原有程序 3 进入adb程序目录/Applications/adt-bundle-mac-x86_64-20131030/sdk/platform-tools 4 键入命令 . ...