利用pt-online-schema-change爲千萬級別表在線添加索引報錯

添加索引

ALTER TABLE `FUND_PAY_TRADE_RECORD`

     ADD INDEX `IDX_PAY_THIRD_ID` (`THIRD_ID`) USING BTREE ;

統計表大小5.6G

blob.png

備份表:

mysqldump -uroot -p --master-data=2 --single-transaction -t  xiaodai   FUND_PAY_TRADE_RECORD > TRADE_RECORD0621.sql

用pt工具變更:

pt-online-schema-change --user=root --password= --alter="ADD INDEX IDX_PAY_THIRD_ID (THIRD_ID) USING BTREE" D=xiaodai,t=FUND_PAY_TRADE_RECORD   --no-check-replication-filters  --execute

報錯

blob.pngThreads_running=52 exceeds its critical threshold 50

從提示上可以看出是Threads_running 超過了警告的閥值,查看官方文檔,有兩種方式來設置這個參數:

--critical-load
type: Array; default: Threads_running=50
Examine SHOW GLOBAL STATUS after every chunk, 
and abort if the load is too high. The option accepts a comma-separated list of MySQL status variables and thresholds. 
An optional =MAX_VALUE (or :MAX_VALUE) can follow each variable. If not given, 
the tool determines a threshold by examining the current value at startup and doubling it.
See --max-load for further details. These options work similarly, 
except that this option will abort the tool’s operation instead of pausing it,
 and the default value is computed differently if you specify no threshold. 
 The reason for this option is as a safety check in case the triggers on the
 original table add so much load to the server that it causes downtime. 
 There is probably no single value of Threads_running that is wrong for 
 every server, but a default of 50 seems likely to be unacceptably high
 for most servers, indicating that the operation should be canceled immediately.

大致的意思如下:
每次chunk操作前後,會根據show global status統計指定的狀態量的變化,默認是統計Thread_running。
目的是爲了安全,防止原始表上的觸發器引起負載過高。這也是爲了防止在線DDL對線上的影響。
超過設置的閥值,就會終止操作,在線DDL就會中斷。提示的異常如上報錯信息。


--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. 
The option accepts a comma-separated list of MySQL status variables. An optional =MAX_VALUE (or :MAX_VALUE) can 
follow each variable. If not given, the tool determines a threshold by examining the current value and increasing it by 20%.

For example, if you want the tool to pause when Threads_connected gets too high, you can specify “Threads_connected”,
 and the tool will check the current value when it starts working and add 20% to that value. If the current value is 100, 
 then the tool will pause when Threads_connected exceeds 120, and resume working when it is below 120 again. If you want to
 specify an explicit threshold, such as 110, you can use either “Threads_connected:110” or “Threads_connected=110”.

The purpose of this option is to prevent the tool from adding too much load to the server. If the data-copy queries are 
intrusive, or if they cause lock waits, then other queries on the server will tend to block and queue. This will typically 
cause Threads_running to increase, and the tool can detect that by running SHOW GLOBAL STATUS immediately after each query finishes. 
If you specify a threshold for this variable, then you can instruct the tool to wait until queries are running normally again. This will 
not prevent queueing, however; it will only give the server a chance to recover from the queueing. If you notice queueing, it is best to decrease the chunk time.

--max-load 選項定義一個閥值,在每次chunk操作後,查看show global status狀態值是否高於指定的閥值。該參數接受一個mysql status狀態變量以及一個閥值,
如果沒有給定閥值,則定義一個閥值爲爲高於當前值的20%。
注意這個參數不會像--critical-load終止操作,而只是暫停操作。當status值低於閥值時,則繼續往下操作。
是暫停還是終止操作這是--max-load和--critical-load的差別。

參數值爲列表形式,可以指定show global status出現的狀態值。比如,Thread_connect 等等。
格式如下:--critical-load="Threads_running=200"  或者--critical-load="Threads_running:200"。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章