MySQL Percona Toolkit--pt-osc重点参数-程序员宅基地

技术标签: 数据库  

修改命令参数alter

1、不需要包含alter table关键字,可以包含多个修改操作,使用逗号分开,如"drop clolumn c1, add column c2 int"
2、不支持rename语句来对表进行重命名操作
3、不支持对索引进行重命名操作
4、如果删除外键,需要对外键名加下划线,如删除外键fk_uid, 修改语句为"DROP FOREIGN KEY _fk_uid"
5、重命名字段,不能使用drop add方式,会导致数据丢失,使用“change col1 col1_new type constraint",保持数据和约束一致。

 

外键参数alter-foreign-keys-method

当对“被其他表外键关联的表”做修改时,RENAME操作会导致外键关联失败而不允许RENAME执行。
pt-osc提供--alter-foreign-keys-method选项:rebuild_constraints/drop_swap/auto/none

假设 t1 是要修改的表,t2 有外键依赖于 t1,_t1_new 是pt-osc工具产生的新临时表。

rebuild_constraints实现方式:
1、删除T2上的外键约束
2、对T1和_t1_new进行重命令
3、新增T2上的外键约束

drop_swap实现方式:
1、禁用T2的外键约束检查,FOREIGN_KEY_CHECKS=0,
2、DROP原始表t1,对_t1_new进行重命令
3、开启T2的外键约束检查

none实现方式:
1、禁用T2的外键约束检查,FOREIGN_KEY_CHECKS=0,
2、对表t1和_t1_new进行重命令
3、开启T2的外键约束检查

auto实现方式:
自动决定使用rebuild_constraints或drop_swap

 

主机性能压力检查参数

在每次考完完成一个chunk数据后,会在主库上执行SHOW GLOBAL STATUS来获取当前的运行状态,判断是否继续拷贝数据和是否取消执行。
--critical-load=(type: Array; default: Threads_running=50)  
Examine SHOW GLOBAL STATUS after every chunk, and abort if the load is too high (default Threads_running=50)
--max-load=(type: Array; default: Threads_running=25)   
Examine SHOW GLOBAL STATUS after every chunk, and pause if any status variables are higher than their thresholds (default Threads_running=25)

参数--max-load不仅可以执行Threads_running状态的阈值,还可以指定其他状态阈值,如果未指定,则会默认使用当前值的120%作为阈值,如假设未指定Threads_connected参数,且当前Threads_connected参数值为100,则当Threads_connected参数值超过120时,会暂停拷贝。

当状态值超过--critical-load阈值后,会暂停拷贝数据并休眠一个复制周期(--chunk-time值),
当状态值超过--critical-load阈值后,会取消pt-osc工具继续执行并清理中间数据。

 

从库复制延迟检查参数

--recursion-method 
Preferred recursion method for discovering replicas (default processlist,hosts)
选择通过何种方式获取从库信息,可选参数:
processlist  SHOW PROCESSLIST
hosts        SHOW SLAVE HOSTS
dsn=DSN      DSNs from a table
none         Do not find slaves

--max-lag(type: time; default: 1s) 
Pause the data copy until all replicas' lag is less than this value (default 1s).
Optional suffix s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used.
默认为1s,每个chunks拷贝完成后,会查看check-slave-lag参数所指定的从库的延迟信息,如果超过max-log的阀值,则暂停复制数据,直到复制延迟小于max-log的阀值。
检查复制延迟信息依赖于SHOW SLAVE STATUS语句中返回的Seconds_Behind_Master列的值。

--check-interval(type: time; default: 1s)
Sleep time between checks for --max-lag (default 1).  
Optional suffix s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used.
当出现复制延迟暂停复制数据后,按照check-interval指定的时间进行周期检查复制延迟。

--check-slave-lag=s
Pause the data copy until this replica's lag is less than --max-lag
需要检查复制延迟的从库IP
如果指定check-slave-lag参数,且从库无法正常连接或从库IO线程和SQL线程停止,会认为主从存在延迟,导致复制数据操作一直暂停。
如果未指定check-slave-lag参数,默认会检查从库的延迟,但复制延迟不会导致数据复制暂停。

--skip-check-slave-lag=d
DSN to skip when checking slave lag
不需要检查复制延迟的从库IP

--slave-user=s
Sets the user to be used to connect to the slaves

--slave-password=s
Sets the password to be used to connect to the slaves

如果未指明从库账号信息,则默认使用主库相同的端口/用户/密码等信息。

 

批量复制数据参数

--chunk-index=s 
Prefer this index for chunking tables

--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)


当chunk-size和chunk-time两者都未指定时,chunk-size默认值为1000,chunk-time默认值为0.5S,第一次按照chunk-size来进行数据复制,然后根据第一次复制的时间动态调整chumk-size的大小,以适应服务器的性能变化,如上一次复制1000行消耗0.1S,则下次动态调整chumk-size为5000。

如果明确指定chumk-size的值或将chunk-time指定为0,则每次都按照chunk-size复制数据。

 

帮助文档(3.0.3)

pt-online-schema-change alters a table's structure without blocking reads or
writes.  Specify the database and table in the DSN.  Do not use this tool before
reading its documentation and checking your backups carefully.  For more
details, please use the --help option, or try 'perldoc
/usr/bin/pt-online-schema-change' for complete documentation.

Usage: pt-online-schema-change [OPTIONS] DSN

Options:

  --alter=s                        The schema modification, without the ALTER
                                   TABLE keywords
  --alter-foreign-keys-method=s    How to modify foreign keys so they reference
                                   the new table
  --[no]analyze-before-swap        Execute ANALYZE TABLE on the new table
                                   before swapping with the old one (default
                                   yes)
  --ask-pass                       Prompt for a password when connecting to
                                   MySQL
  --charset=s                  -A  Default character set
  --[no]check-alter                Parses the --alter specified and tries to
                                   warn of possible unintended behavior (
                                   default yes)
  --check-interval=m               Sleep time between checks for --max-lag (
                                   default 1).  Optional suffix s=seconds, m=
                                   minutes, h=hours, d=days; if no suffix, s is
                                   used.
  --[no]check-plan                 Check query execution plans for safety (
                                   default yes)
  --[no]check-replication-filters  Abort if any replication filter is set on
                                   any server (default yes)
  --check-slave-lag=s              Pause the data copy until this replica's lag
                                   is less than --max-lag
  --chunk-index=s                  Prefer this index for chunking tables
  --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)
  --config=A                       Read this comma-separated list of config
                                   files; if specified, this must be the first
                                   option on the command line
  --critical-load=A                Examine SHOW GLOBAL STATUS after every
                                   chunk, and abort if the load is too high (
                                   default Threads_running=50)
  --data-dir=s                     Create the new table on a different
                                   partition using the DATA DIRECTORY feature
  --database=s                 -D  Connect to this database
  --default-engine                 Remove ENGINE from the new table
  --defaults-file=s            -F  Only read mysql options from the given file
  --[no]drop-new-table             Drop the new table if copying the original
                                   table fails (default yes)
  --[no]drop-old-table             Drop the original table after renaming it (
                                   default yes)
  --[no]drop-triggers              Drop triggers on the old table. --no-drop-
                                   triggers forces --no-drop-old-table (default
                                   yes)
  --dry-run                        Create and alter the new table, but do not
                                   create triggers, copy data, or replace the
                                   original table
  --execute                        Indicate that you have read the
                                   documentation and want to alter the table
  --force                          This options bypasses confirmation in case
                                   of using alter-foreign-keys-method = none ,
                                   which might break foreign key constraints
  --help                           Show help and exit
  --host=s                     -h  Connect to host
  --max-flow-ctl=f                 Somewhat similar to --max-lag but for PXC
                                   clusters
  --max-lag=m                      Pause the data copy until all replicas' lag
                                   is less than this value (default 1s).
                                   Optional suffix s=seconds, m=minutes, h=
                                   hours, d=days; if no suffix, s is used.
  --max-load=A                     Examine SHOW GLOBAL STATUS after every
                                   chunk, and pause if any status variables are
                                   higher than their thresholds (default
                                   Threads_running=25)
  --new-table-name=s               New table name before it is swapped. %T is
                                   replaced with the original table name (
                                   default %T_new)
  --null-to-not-null               Allows MODIFYing a column that allows NULL
                                   values to one that doesn't allow them
  --password=s                 -p  Password to use when connecting
  --pause-file=s                   Execution will be paused while the file
                                   specified by this param exists
  --pid=s                          Create the given PID file
  --plugin=s                       Perl module file that defines a
                                   pt_online_schema_change_plugin class
  --port=i                     -P  Port number to use for connection
  --print                          Print SQL statements to STDOUT
  --progress=a                     Print progress reports to STDERR while
                                   copying rows (default time,30)
  --quiet                      -q  Do not print messages to STDOUT (disables --
                                   progress)
  --recurse=i                      Number of levels to recurse in the hierarchy
                                   when discovering replicas
  --recursion-method=a             Preferred recursion method for discovering
                                   replicas (default processlist,hosts)
  --remove-data-dir                If the original table was created using the
                                   DATA DIRECTORY feature, remove it and create
                                   the new table in MySQL default directory
                                   without creating a new isl file (default no)
  --set-vars=A                     Set the MySQL variables in this comma-
                                   separated list of variable=value pairs
  --skip-check-slave-lag=d         DSN to skip when checking slave lag
  --slave-password=s               Sets the password to be used to connect to
                                   the slaves
  --slave-user=s                   Sets the user to be used to connect to the
                                   slaves
  --sleep=f                        How long to sleep (in seconds) after copying
                                   each chunk (default 0)
  --socket=s                   -S  Socket file to use for connection
  --statistics                     Print statistics about internal counters
  --[no]swap-tables                Swap the original table and the new, altered
                                   table (default yes)
  --tries=a                        How many times to try critical operations
  --[no]use-insert-ignore          pt-online-schema-change by default use
                                   INSERT LOW_PRIORITY IGNORE statements to
                                   copy rows from the old table to the new one (
                                   default yes)
  --user=s                     -u  User for login if not current user
  --version                        Show version and exit
  --[no]version-check              Check for the latest version of Percona
                                   Toolkit, MySQL, and other programs (default
                                   yes)

Option types: s=string, i=integer, f=float, h/H/a/A=comma-separated list, d=DSN, z=size, m=time

Rules:

  --dry-run and --execute are mutually exclusive.
  This tool accepts additional command-line arguments. Refer to the SYNOPSIS and usage information for details.

DSN syntax is key=value[,key=value...]  Allowable DSN keys:

  KEY  COPY  MEANING
  ===  ====  =============================================
  A    yes   Default character set
  D    yes   Database for the old and new table
  F    yes   Only read default options from the given file
  P    yes   Port number to use for connection
  S    yes   Socket file to use for connection
  h    yes   Connect to host
  p    yes   Password to use when connecting
  t    no    Table to alter
  u    yes   User for login if not current user

  If the DSN is a bareword, the word is treated as the 'h' key.

Options and values after processing arguments:

  --alter                          (No value)
  --alter-foreign-keys-method      (No value)
  --analyze-before-swap            TRUE
  --ask-pass                       FALSE
  --charset                        (No value)
  --check-alter                    TRUE
  --check-interval                 1
  --check-plan                     TRUE
  --check-replication-filters      TRUE
  --check-slave-lag                (No value)
  --chunk-index                    (No value)
  --chunk-index-columns            (No value)
  --chunk-size                     1000
  --chunk-size-limit               4.0
  --chunk-time                     0.5
  --config                         /etc/percona-toolkit/percona-toolkit.conf,/etc/percona-toolkit/pt-online-schema-change.conf,/root/.percona-toolkit.conf,/root/.pt-online-schema-change.conf
  --critical-load                  Threads_running=50
  --data-dir                       (No value)
  --database                       (No value)
  --default-engine                 FALSE
  --defaults-file                  (No value)
  --drop-new-table                 TRUE
  --drop-old-table                 TRUE
  --drop-triggers                  TRUE
  --dry-run                        FALSE
  --execute                        FALSE
  --force                          FALSE
  --help                           TRUE
  --host                           (No value)
  --max-flow-ctl                   (No value)
  --max-lag                        1
  --max-load                       Threads_running=25
  --new-table-name                 %T_new
  --null-to-not-null               FALSE
  --password                       (No value)
  --pause-file                     (No value)
  --pid                            (No value)
  --plugin                         (No value)
  --port                           (No value)
  --print                          FALSE
  --progress                       time,30
  --quiet                          FALSE
  --recurse                        (No value)
  --recursion-method               processlist,hosts
  --remove-data-dir                TRUE
  --set-vars                       
  --skip-check-slave-lag           (No value)
  --slave-password                 (No value)
  --slave-user                     (No value)
  --sleep                          0
  --socket                         (No value)
  --statistics                     FALSE
  --swap-tables                    TRUE
  --tries                          (No value)
  --use-insert-ignore              TRUE
  --user                           (No value)
  --version                        FALSE
  --version-check                  TRUE

 

参考资料

https://www.cnblogs.com/xiaoyanger/p/6043986.html

转载于:https://www.cnblogs.com/gaogao67/p/11170602.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30905133/article/details/99965718

智能推荐

分布式光纤传感器的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告_预计2026年中国分布式传感器市场规模有多大-程序员宅基地

文章浏览阅读3.2k次。本文研究全球与中国市场分布式光纤传感器的发展现状及未来发展趋势,分别从生产和消费的角度分析分布式光纤传感器的主要生产地区、主要消费地区以及主要的生产商。重点分析全球与中国市场的主要厂商产品特点、产品规格、不同规格产品的价格、产量、产值及全球和中国市场主要生产商的市场份额。主要生产商包括:FISO TechnologiesBrugg KabelSensor HighwayOmnisensAFL GlobalQinetiQ GroupLockheed MartinOSENSA Innovati_预计2026年中国分布式传感器市场规模有多大

07_08 常用组合逻辑电路结构——为IC设计的延时估计铺垫_基4布斯算法代码-程序员宅基地

文章浏览阅读1.1k次,点赞2次,收藏12次。常用组合逻辑电路结构——为IC设计的延时估计铺垫学习目的:估计模块间的delay,确保写的代码的timing 综合能给到多少HZ,以满足需求!_基4布斯算法代码

OpenAI Manager助手(基于SpringBoot和Vue)_chatgpt网页版-程序员宅基地

文章浏览阅读3.3k次,点赞3次,收藏5次。OpenAI Manager助手(基于SpringBoot和Vue)_chatgpt网页版

关于美国计算机奥赛USACO,你想知道的都在这_usaco可以多次提交吗-程序员宅基地

文章浏览阅读2.2k次。USACO自1992年举办,到目前为止已经举办了27届,目的是为了帮助美国信息学国家队选拔IOI的队员,目前逐渐发展为全球热门的线上赛事,成为美国大学申请条件下,含金量相当高的官方竞赛。USACO的比赛成绩可以助力计算机专业留学,越来越多的学生进入了康奈尔,麻省理工,普林斯顿,哈佛和耶鲁等大学,这些同学的共同点是他们都参加了美国计算机科学竞赛(USACO),并且取得过非常好的成绩。适合参赛人群USACO适合国内在读学生有意向申请美国大学的或者想锻炼自己编程能力的同学,高三学生也可以参加12月的第_usaco可以多次提交吗

MySQL存储过程和自定义函数_mysql自定义函数和存储过程-程序员宅基地

文章浏览阅读394次。1.1 存储程序1.2 创建存储过程1.3 创建自定义函数1.3.1 示例1.4 自定义函数和存储过程的区别1.5 变量的使用1.6 定义条件和处理程序1.6.1 定义条件1.6.1.1 示例1.6.2 定义处理程序1.6.2.1 示例1.7 光标的使用1.7.1 声明光标1.7.2 打开光标1.7.3 使用光标1.7.4 关闭光标1.8 流程控制的使用1.8.1 IF语句1.8.2 CASE语句1.8.3 LOOP语句1.8.4 LEAVE语句1.8.5 ITERATE语句1.8.6 REPEAT语句。_mysql自定义函数和存储过程

半导体基础知识与PN结_本征半导体电流为0-程序员宅基地

文章浏览阅读188次。半导体二极管——集成电路最小组成单元。_本征半导体电流为0

随便推点

【Unity3d Shader】水面和岩浆效果_unity 岩浆shader-程序员宅基地

文章浏览阅读2.8k次,点赞3次,收藏18次。游戏水面特效实现方式太多。咱们这边介绍的是一最简单的UV动画(无顶点位移),整个mesh由4个顶点构成。实现了水面效果(左图),不动代码稍微修改下参数和贴图可以实现岩浆效果(右图)。有要思路是1,uv按时间去做正弦波移动2,在1的基础上加个凹凸图混合uv3,在1、2的基础上加个水流方向4,加上对雾效的支持,如没必要请自行删除雾效代码(把包含fog的几行代码删除)S..._unity 岩浆shader

广义线性模型——Logistic回归模型(1)_广义线性回归模型-程序员宅基地

文章浏览阅读5k次。广义线性模型是线性模型的扩展,它通过连接函数建立响应变量的数学期望值与线性组合的预测变量之间的关系。广义线性模型拟合的形式为:其中g(μY)是条件均值的函数(称为连接函数)。另外,你可放松Y为正态分布的假设,改为Y 服从指数分布族中的一种分布即可。设定好连接函数和概率分布后,便可以通过最大似然估计的多次迭代推导出各参数值。在大部分情况下,线性模型就可以通过一系列连续型或类别型预测变量来预测正态分布的响应变量的工作。但是,有时候我们要进行非正态因变量的分析,例如:(1)类别型.._广义线性回归模型

HTML+CSS大作业 环境网页设计与实现(垃圾分类) web前端开发技术 web课程设计 网页规划与设计_垃圾分类网页设计目标怎么写-程序员宅基地

文章浏览阅读69次。环境保护、 保护地球、 校园环保、垃圾分类、绿色家园、等网站的设计与制作。 总结了一些学生网页制作的经验:一般的网页需要融入以下知识点:div+css布局、浮动、定位、高级css、表格、表单及验证、js轮播图、音频 视频 Flash的应用、ul li、下拉导航栏、鼠标划过效果等知识点,网页的风格主题也很全面:如爱好、风景、校园、美食、动漫、游戏、咖啡、音乐、家乡、电影、名人、商城以及个人主页等主题,学生、新手可参考下方页面的布局和设计和HTML源码(有用点赞△) 一套A+的网_垃圾分类网页设计目标怎么写

C# .Net 发布后,把dll全部放在一个文件夹中,让软件目录更整洁_.net dll 全局目录-程序员宅基地

文章浏览阅读614次,点赞7次,收藏11次。之前找到一个修改 exe 中 DLL地址 的方法, 不太好使,虽然能正确启动, 但无法改变 exe 的工作目录,这就影响了.Net 中很多获取 exe 执行目录来拼接的地址 ( 相对路径 ),比如 wwwroot 和 代码中相对目录还有一些复制到目录的普通文件 等等,它们的地址都会指向原来 exe 的目录, 而不是自定义的 “lib” 目录,根本原因就是没有修改 exe 的工作目录这次来搞一个启动程序,把 .net 的所有东西都放在一个文件夹,在文件夹同级的目录制作一个 exe._.net dll 全局目录

BRIEF特征点描述算法_breif description calculation 特征点-程序员宅基地

文章浏览阅读1.5k次。本文为转载,原博客地址:http://blog.csdn.net/hujingshuang/article/details/46910259简介 BRIEF是2010年的一篇名为《BRIEF:Binary Robust Independent Elementary Features》的文章中提出,BRIEF是对已检测到的特征点进行描述,它是一种二进制编码的描述子,摈弃了利用区域灰度..._breif description calculation 特征点

房屋租赁管理系统的设计和实现,SpringBoot计算机毕业设计论文_基于spring boot的房屋租赁系统论文-程序员宅基地

文章浏览阅读4.1k次,点赞21次,收藏79次。本文是《基于SpringBoot的房屋租赁管理系统》的配套原创说明文档,可以给应届毕业生提供格式撰写参考,也可以给开发类似系统的朋友们提供功能业务设计思路。_基于spring boot的房屋租赁系统论文