修改命令参数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] DSNOptions:--alter=s                        The schema modification, without the ALTERTABLE keywords--alter-foreign-keys-method=s    How to modify foreign keys so they referencethe new table--[no]analyze-before-swap        Execute ANALYZE TABLE on the new tablebefore swapping with the old one (defaultyes)--ask-pass                       Prompt for a password when connecting toMySQL--charset=s                  -A  Default character set--[no]check-alter                Parses the --alter specified and tries towarn 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 isused.--[no]check-plan                 Check query execution plans for safety (default yes)--[no]check-replication-filters  Abort if any replication filter is set onany server (default yes)--check-slave-lag=s              Pause the data copy until this replica's lagis 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 chunkcopied (default 1000)--chunk-size-limit=f             Do not copy chunks this much larger than thedesired chunk size (default 4.0)--chunk-time=f                   Adjust the chunk size dynamically so eachdata-copy query takes this long to execute (default 0.5)--config=A                       Read this comma-separated list of configfiles; if specified, this must be the firstoption on the command line--critical-load=A                Examine SHOW GLOBAL STATUS after everychunk, and abort if the load is too high (default Threads_running=50)--data-dir=s                     Create the new table on a differentpartition 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 originaltable 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 (defaultyes)--dry-run                        Create and alter the new table, but do notcreate triggers, copy data, or replace theoriginal table--execute                        Indicate that you have read thedocumentation and want to alter the table--force                          This options bypasses confirmation in caseof 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 PXCclusters--max-lag=m                      Pause the data copy until all replicas' lagis 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 everychunk, and pause if any status variables arehigher than their thresholds (defaultThreads_running=25)--new-table-name=s               New table name before it is swapped. %T isreplaced with the original table name (default %T_new)--null-to-not-null               Allows MODIFYing a column that allows NULLvalues to one that doesn't allow them--password=s                 -p  Password to use when connecting--pause-file=s                   Execution will be paused while the filespecified by this param exists--pid=s                          Create the given PID file--plugin=s                       Perl module file that defines apt_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 whilecopying rows (default time,30)--quiet                      -q  Do not print messages to STDOUT (disables --progress)--recurse=i                      Number of levels to recurse in the hierarchywhen discovering replicas--recursion-method=a             Preferred recursion method for discoveringreplicas (default processlist,hosts)--remove-data-dir                If the original table was created using theDATA DIRECTORY feature, remove it and createthe new table in MySQL default directorywithout 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 tothe slaves--slave-user=s                   Sets the user to be used to connect to theslaves--sleep=f                        How long to sleep (in seconds) after copyingeach 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, alteredtable (default yes)--tries=a                        How many times to try critical operations--[no]use-insert-ignore          pt-online-schema-change by default useINSERT LOW_PRIORITY IGNORE statements tocopy 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 PerconaToolkit, MySQL, and other programs (defaultyes)Option types: s=string, i=integer, f=float, h/H/a/A=comma-separated list, d=DSN, z=size, m=timeRules:--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 setD    yes   Database for the old and new tableF    yes   Only read default options from the given fileP    yes   Port number to use for connectionS    yes   Socket file to use for connectionh    yes   Connect to hostp    yes   Password to use when connectingt    no    Table to alteru    yes   User for login if not current userIf 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

MySQL Percona Toolkit--pt-osc重点参数相关推荐

  1. mysql 工具_最全Mysql运维工具Percona Toolkit使用案例

    Percona Toolkit简介 Percona Toolkit简称pt工具,是Percona公司开发用于管理MySQL的工具,DBA熟悉掌握后将极大提高工作效率. Percona toolkit有 ...

  2. mysql开启yum search pt-mysql_Centos使用MySQL工具Percona Toolkit

    Centos使用MySQL工具Percona Toolkit 安装Percona Toolkit 的Repo 得以支持直接用yum 安装二进制包 yum install -y https://www. ...

  3. mysql percona server_MySQL Study之--Percona Server版本

    1.简介 Percona 为 MySQL 数据库服务器进行了改进,在功能和性能上较 MySQL 有着很显著的提升.该版本提升了在高负载情况下的 InnoDB 的性能.为 DBA 提供一些非常有用的性能 ...

  4. percona toolkit系列(gh-ost)

    背景 和上篇pt-osc同样功能的工具gh-ost(使用的是binlog复制数据),目前是为了修改表结构 online DDL 写在前面 (该工具并不是percona toolkit中的,只是为了读者 ...

  5. percona toolkit 简介

    os: centos 7.4 db: mysql 5.7 software: toolkit 3.0.8 percona toolkit 是一款percona公司推出的优秀的开源的mysql分析工具. ...

  6. Percona Toolkit工具简介

    系列文章目录 第一章:sql_mode模式 第二章:optimize table.analyze table.alter table.gh-ost 第三章:InnoDB MVCC原理 第四章:sql语 ...

  7. MySQL 8.0 首个自适应参数横空出世

    |什么是自适应参数 MySQL8.0推出一个号称可以自适应服务器的参数,保证在各种不同的服务器.虚拟机.容器下自动适配服务器资源,让我们一起来看看到底它能做到什么地步. |自适应参数是如何设置和适应变 ...

  8. Want to archive tables? Use Percona Toolkit’s pt-archiver--转载

    原文地址:https://www.percona.com/blog/2013/08/12/want-to-archive-tables-use-pt-archiver/ Percona Toolkit ...

  9. Percona Toolkit安装

    TIPS 本文基于Percona Toolkit 3.2.0,理论支持所有版本. Percona Toolkit是一款MySQL世界里面非常实用的工具套件,本文来探讨如何安装它. 工具列表 pt-al ...

  10. mysql percona 集群_MySQL高可用性解决方案—Percona XtraDB Cluster

    MySQL数据库的性能是服务器运维中不可缺少的部分,需要不断的优化数据库的性能,寻找出系统的瓶颈.今天就来分享一款提高数据库高可用性的解决方案.Percona XtraDB Cluster---MyS ...

最新文章

  1. R语言数学函数:abs绝对值、sqrt平方根、ceiling向上近似整数、floor向下近似整数、trunc去除小数部分、round近似到指定小数位、signif近似到有效数字、三角函数、指数、对数
  2. CV之IS:计算机视觉之图像分割(Image Segmentation)算法的挑战任务、算法演化、目标检测和图像分割(语义分割/实例分割/全景分割)的对比
  3. oracle的have,Does oracle have “auto number” data type [duplicate]
  4. 2018年度机器学习50大热门网文
  5. 进腾讯实习要交钱?腾讯2021年开除70名员工,拉黑13家公司
  6. 管理exchange 2010用户邮箱本地移动请求
  7. 佳能80d有人脸识别吗_2020单反/微单相机推荐,单反和微单(无反)选购攻略,佳能、尼康、索尼、富士、松下相机...
  8. servlet学习笔记_2
  9. C运行时库(CRT)
  10. 某超市销售数据的分析
  11. linux ora -03113,ORA-03113解决方法
  12. Leetcode刷题-707:设计链表
  13. 温度传感器MLX90614的STM32驱动实现
  14. 实验室信息管理系统的进化史
  15. win10打印机无法打印(怎样使用打印机打印)
  16. flutter 斗音页面
  17. 工程师职称评审两大阶段要明白!
  18. 学3d建模和计算机编程,超好用的3D建模软件全科普,想要学好建模的你千万别错过!...
  19. 人工智能未来十大趋势,22年最新
  20. 设置Mac的输入法切换快捷键

热门文章

  1. 2019杭州小学入学报名指南
  2. 数据库MySQL学习笔记高级篇(周阳)
  3. 小讲堂:Mobox文档管理软件中的文件外链是什么?
  4. 新年之初 云计算2009年十大预测
  5. 程序化交易常用的监管指标
  6. 简单易懂的金融杠杆原理解说
  7. 聊聊我这不正的「用户观」 ofo退款与最后一公里之死
  8. 解决JS中0.1+0.2不等于0.3
  9. 电子烟怎么选?不如先看看这篇EVOVE电子烟体验
  10. 2016:iOS开发趋势思考--写的有趣~