溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2020-07-01 07:34:34 來源:網(wǎng)絡(luò) 閱讀:2566 作者:Super_DBA 欄目:MySQL數(shù)據(jù)庫

添加索引

ALTER TABLE `FUND_PAY_TRADE_RECORD`

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

統(tǒng)計表大小5.6G

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

備份表:

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

報錯

利用pt-online-schema-change為千萬級別表在線添加索引報錯Threads_running=52 exceeds its critical threshold 50

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

--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操作前后,會根據(jù)show global status統(tǒng)計指定的狀態(tài)量的變化,默認是統(tǒng)計Thread_running。
目的是為了安全,防止原始表上的觸發(fā)器引起負載過高。這也是為了防止在線DDL對線上的影響。
超過設(shè)置的閥值,就會終止操作,在線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狀態(tài)值是否高于指定的閥值。該參數(shù)接受一個mysql status狀態(tài)變量以及一個閥值,
如果沒有給定閥值,則定義一個閥值為為高于當(dāng)前值的20%。
注意這個參數(shù)不會像--critical-load終止操作,而只是暫停操作。當(dāng)status值低于閥值時,則繼續(xù)往下操作。
是暫停還是終止操作這是--max-load和--critical-load的差別。

參數(shù)值為列表形式,可以指定show global status出現(xiàn)的狀態(tài)值。比如,Thread_connect 等等。
格式如下:--critical-load="Threads_running=200"  或者--critical-load="Threads_running:200"。




向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI