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

智能推荐

各类机器学习方法的应用场景是什么?_方法的适用场景-程序员宅基地

文章浏览阅读1.5k次,点赞2次,收藏8次。作者:xyzh链接:https://www.zhihu.com/question/26726794/answer/151282052来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 作者:xyzh链接:https://www.zhihu.com/question/26726794/answer/151282052来源:知乎著作权归作者所有。商业转载请..._方法的适用场景

关于前端组件化、状态管理规范化的思考-程序员宅基地

文章浏览阅读597次。苏格团队作者:Tomey一、开篇说起前端组件化是这几年老生常谈的话题,笔者就不在这里对前端组件化思想的发展史、优劣做详细的介绍。今天主要与大家分享一下,笔者在开发中从初期的小项目,到后期的项目功能迭代,功能模块越来越多,项目越来越大,组件化规范制定不够完善,多人团队协作开发导致的一些问题,与笔主自己处理的方案的思考。二、发现、提出问题1、三张图说明一个业务模块功能迭代图。第1版..._前端 组件 状态

unity如何查找某个脚本挂在了哪些物体上_unity查找物体挂载的组件-程序员宅基地

文章浏览阅读3.6w次,点赞29次,收藏115次。在开发中往往会遇到一个问题:不知道整个场景中究竟有哪些物体挂载了某一个脚本。如果挨个查找太麻烦了,下面有一种方法可以快速找到解决这个问题。在unity的Window里有一项Editor tests runner 选择这个会出现一个窗口:如下图:然后点击创建脚本会有脚本自动创建在project里的Editor下。之后我们要写两个脚本(如下图)这两个脚本代码,一个是用来盛放_unity查找物体挂载的组件

基于功能安全的车载计算平台开发:硬件层面_mcu 不同通道 共因-程序员宅基地

文章浏览阅读776次,点赞20次,收藏16次。如果不具备关于复杂元器件的安全故障比例的详细信息,可假定安全故障的保守比例为50%,并假定通过内部自检和外部看门狗(表中的安全机制SM4)达到对违背安全目标的总体覆盖率为90%。这里的意图不是一定需要全面的分析,比如要求对于微控制器内或者来自于一个复杂的PCB板上任何理论可能的信号组合的桥接故障进行详尽的分析。根据硬件故障对安全目标产生影响的不同,硬件故障可分为安全相关故障与非安全相关故障,其中安全相关故障又进一步分为单点故障、残余故障、多点可探测故障、多点可感知故障、多点潜伏故障与安全故障。

java中Arrays类的简单使用_java调用函数arrays-程序员宅基地

文章浏览阅读250次。转载原文:点击打开链接java.util.Arrays类能方便地操作数组,它提供的所有方法都是静态的。具有以下功能:² 给数组赋值:通过fill方法。² 对数组排序:通过sort方法,按升序。² 比较数组:通过equals方法比较数组中元素值是否相等。² 查找数组元素:通过binarySearch方法能对排序好的数组进行二分查找法操作。_java调用函数arrays

在 Airbnb 使用机器学习预测房源的价格-程序员宅基地

文章浏览阅读1.5k次。原文地址:Using Machine Learning to Predict Value of Homes On Airbnb原文作者:Robert Chang译文出自:掘金翻译计划本文永久链接:github.com/xitu/gold-m…译者:lsvih校对者:TobiasLee, RichardLeeH, reid3290在 Airbnb 使用机器学习预测房源的价格位..._airbnb(爱彼迎)短租平台机器学习算法房价预测

随便推点

汇编语言程序设计的实验环境及上机步骤_windows 98 se汇编实验-程序员宅基地

文章浏览阅读3.9k次,点赞5次,收藏45次。汇编语言源程序编制完成后,在计算机上的操作过程分为四个阶段:编辑、汇编、连接、运行调试(如图1)。一、实验环境汇编语言程序设计的实验环境如下:硬件环境微型计算机(Intel x86系列CPU)一台。软件环境Windows98/2000/XP操作系统任意一种文本编辑器(EDIT、NOTEPAD(记事本)、UltraEDIT等)。汇编程序(MASM.EXE或TASM.EXE)。调试程序(DEBUG.EXE或TD.EXE)。文本编辑器建议使用EDIT或NOTEPAD,汇编程序建议使用MAS_windows 98 se汇编实验

SpringBoot2.0 配置mongodb双数据源两种连接方式_springboot2.0 多mongo-程序员宅基地

文章浏览阅读2.5k次,点赞2次,收藏6次。一、使用database、host、port、username、password 连接方式1、自定义连接相关信息 application.ymlspring: data: mongodb: mcdr: database: mcdr host: 10.188.188.100 port: 27017 us..._springboot2.0 多mongo

【校内模拟】Slay(容斥原理)_slaynoip模拟-程序员宅基地

文章浏览阅读272次。题解:令f(p,k)f(p,k)f(p,k)表示从[0,n−1][0,n-1][0,n−1]中选择kkk个数,使得和为ppp的倍数的方案数。接下来用一种很诡异的姿势容斥。直接算并不好算,考虑枚举最后有iii个数固定且相同,前面选择k−ik-ik−i个不同的数和为sumsumsum,这两部分分开计算,互不影响。发现会出现i+1i+1i+1个数重复的情况,需要减掉,然后又多减掉了i+2i+2i..._slaynoip模拟

linux上配置项目自动svn up(svn钩子)_linux 自动化 svnup结束-程序员宅基地

文章浏览阅读347次。切到需要自动的svn项目中cd data/svn/huazhu进入到钩子目录cd hooks复制自动更新文件模板cp post-commit.tmpl post-commit增加文件内容export LANG=en_US.UTF-8svn update /data/wwwroot/huazhu/ --username xx --password xx其中,/da..._linux 自动化 svnup结束

coop:Learning to Prompt for Vision-Language Models-程序员宅基地

文章浏览阅读4.5k次,点赞2次,收藏18次。论文链接https://arxiv.org/pdf/2109.01134v1.pdf源码链接https://github.com/KaiyangZhou/CoOp一、摘要像CLIP这样的大型预训练视觉语言模型在学习表征方面显示出了巨大的潜力,这些表征可在广泛的下游任务中迁移。与传统的基于离散标签的表示学习不同,视觉语言的预训练将图像和文本对齐在一个共同的特征空间中,通过提示将零射转移到任何下游任务,即从描述感兴趣类的自然语言合成分类权值。在这项工作中,我们表明,部署的一个主要.._learning to prompt for vision-language models

用CMakeList 构建Qt 项目 及 遇到的问题yuan_qt cmakelists no build found in-程序员宅基地

文章浏览阅读4.5k次,点赞2次,收藏7次。本博文只是介绍在Cmake 构建Qt项目时遇到的问题,和对应的解决方案。构建方法参考博客:https://blog.csdn.net/u013243710/article/details/36005539问题1.找不到QT4CMake Error at can_ui/CMakeLists.txt:121 (find_package): By not providing "FindQT4.cma..._qt cmakelists no build found in

推荐文章

热门文章

相关标签