天天看點

GitHub開源MySQL Online DDL工具gh-ost參數解析

源文将持續更新,請點選此處閱讀原文

gh-ost版本:1.0.28

-allow-master-master

允許gh-ost運作在雙主複制架構中,一般與

-assume-master-host

參數一起使用。

-allow-nullable-unique-key

允許gh-ost在資料遷移(migrate)依賴的唯一鍵可以為NULL,預設為不允許為NULL的唯一鍵。如果資料遷移(migrate)依賴的唯一鍵允許NULL值,則可能造成資料不正确,請謹慎使用。

-allow-on-master

允許gh-ost直接運作在主庫上。預設gh-ost連接配接的從庫。

-alter string

ALTER語句的body部分,如”ALTER TABLE wing ADD COLUMN id int not null default 0”,使用gh-ost的

-alter

參數時,寫成

-alter ADD COLUMN id int not null default 0

即可。

-approve-renamed-columns ALTER

如果你修改一個列的名字(如change column),gh-ost将會識别到并且需要提供重命名列名的原因,預設情況下gh-ost是不繼續執行的,除非提供

-approve-renamed-columns ALTER

e.g:

沒有添加

-approve-renamed-columns ALTER

參數,并且修改列名:

gh-ost -user="wing" -host="127.0.0.1" -port=3306 -database="wing" -table="t" -password="wing" -alter="change column col1 c1 int not null default 0" -assume-rbr -execute

2016-12-07 16:39:55 FATAL gh-ost believes the ALTER statement renames columns, as follows: map[col1:col11]; as precation, you are asked to confirm gh-ost is correct, and provide with

--approve-renamed-columns

, and we’re all happy. Or you can skip renamed columns via

--skip-renamed-columns

, in which case column data may be lost

沒有添加

-approve-renamed-columns ALTER

參數,并且修改列名為相同名稱:

gh-ost -user="wing" -host="127.0.0.1" -port=3306 -database="wing" -table="t" -password="wing" -alter="change column c1 c1 int not null default 0" -assume-rbr -execute

Migrating

wing

.

t

; Ghost table is

wing

.

_t_gho

Migrating wing-01:3306; inspecting wing-02:3306; executing on wing-02

Migration started at Wed Dec 07 17:03:22 +0800 2016

chunk-size: 1000; max-lag-millis: 1500ms; max-load: ; critical-load: ; nice-ratio: 0.000000

throttle-additional-flag-file: /tmp/gh-ost.throttle

Serving on unix socket: /tmp/gh-ost.wing.t.sock

Copy: 0/3 0.0%; Applied: 0; Backlog: 0/100; Time: 0s(total), 0s(copy); streamer: mysql-bin.000005:62874; State: migrating; ETA: N/A

Copy: 0/3 0.0%; Applied: 0; Backlog: 0/100; Time: 1s(total), 1s(copy); streamer: mysql-bin.000005:64686; State: migrating; ETA: N/A

Copy: 3/3 100.0%; Applied: 0; Backlog: 0/100; Time: 1s(total), 1s(copy); streamer: mysql-bin.000005:64686; State: migrating; ETA: due

Copy: 3/3 100.0%; Applied: 0; Backlog: 1/100; Time: 2s(total), 1s(copy); streamer: mysql-bin.000005:69035; State: migrating; ETA: due

Migrating

wing

.

t

; Ghost table is

wing

.

_t_gho

Migrating wing-01:3306; inspecting wing-02:3306; executing on wing-02

Migration started at Wed Dec 07 17:03:22 +0800 2016

chunk-size: 1000; max-lag-millis: 1500ms; max-load: ; critical-load: ; nice-ratio: 0.000000

throttle-additional-flag-file: /tmp/gh-ost.throttle

Serving on unix socket: /tmp/gh-ost.wing.t.sock

Copy: 3/3 100.0%; Applied: 0; Backlog: 0/100; Time: 2s(total), 1s(copy); streamer: mysql-bin.000005:69759; State: migrating; ETA: due

添加

-approve-renamed-columns ALTER

參數,并且修改列名:

gh-ost -user="wing" -host="127.0.0.1" -port=3306 -database="wing" -table="t" -password="wing" -alter="change column col1 c1 int not null default 0" -assume-rbr -execute -approve-renamed-columns ALTER

Migrating

wing

.

t

; Ghost table is

wing

.

_t_gho

Migrating wing-01:3306; inspecting wing-02:3306; executing on wing-02

Migration started at Wed Dec 07 16:42:16 +0800 2016

chunk-size: 1000; max-lag-millis: 1500ms; max-load: ; critical-load: ; nice-ratio: 0.000000

throttle-additional-flag-file: /tmp/gh-ost.throttle

Serving on unix socket: /tmp/gh-ost.wing.t.sock

Copy: 0/3 0.0%; Applied: 0; Backlog: 0/100; Time: 0s(total), 0s(copy); streamer: mysql-bin.000005:41767; State: migrating; ETA: N/A

Copy: 0/3 0.0%; Applied: 0; Backlog: 0/100; Time: 1s(total), 1s(copy); streamer: mysql-bin.000005:43576; State: migrating; ETA: N/A

Copy: 3/3 100.0%; Applied: 0; Backlog: 0/100; Time: 1s(total), 1s(copy); streamer: mysql-bin.000005:43576; State: migrating; ETA: due

Copy: 3/3 100.0%; Applied: 0; Backlog: 1/100; Time: 2s(total), 1s(copy); streamer: mysql-bin.000005:47927; State: migrating; ETA: due

Migrating

wing

.

t

; Ghost table is

wing

.

_t_gho

Migrating wing-01:3306; inspecting wing-02:3306; executing on wing-02

Migration started at Wed Dec 07 16:42:16 +0800 2016

chunk-size: 1000; max-lag-millis: 1500ms; max-load: ; critical-load: ; nice-ratio: 0.000000

throttle-additional-flag-file: /tmp/gh-ost.throttle

Serving on unix socket: /tmp/gh-ost.wing.t.sock

Copy: 3/3 100.0%; Applied: 0; Backlog: 0/100; Time: 2s(total), 1s(copy); streamer: mysql-bin.000005:48651; State: migrating; ETA: due

-assume-master-host string

為gh-ost指定一個主庫,格式為”ip:port”或者”hostname:port”。預設推薦gh-ost連接配接從庫。

-assume-rbr

确認gh-ost連接配接的資料庫執行個體的binlog_format=ROW的情況下,可以指定

-assume-rbr

,這樣可以禁止從庫上運作

stop slave

,

start slave

,執行gh-ost使用者也不需要SUPER權限。

-chunk-size int

在每次疊代中處理的行數量(允許範圍:100-100000),預設值為1000。

-concurrent-rowcount

該參數如果為True(預設值),則進行row-copy之後,估算統計行數(使用explain select count(*)方式),并調整ETA時間,否則,gh-ost首先預估統計行數,然後開始row-copy。

-conf string

gh-ost的配置檔案路徑。

-critical-load string

一系列逗号分隔的status-name=values組成,當MySQL中status超過對應的values,gh-ost将會退出。

e.g:

-critical-load Threads_connected=20,Connections=1500

指的是當MySQL中的狀态值Threads_connected>20,Connections>1500的時候,gh-ost将會由于該資料庫嚴重負載而停止并退出。

-critical-load-interval-millis int

當值為0時,當達到

-critical-load

,gh-ost立即退出。當值不為0時,當達到

-critical-load

,gh-ost會在

-critical-load-interval-millis

秒數後,再次進行檢查,再次檢查依舊達到

-critical-load

,gh-ost将會退出。

-cut-over string

選擇cut-over類型:atomic/two-step,atomic(預設)類型的cut-over是github的算法,two-step采用的是facebook-OSC的算法。

-cut-over-lock-timeout-seconds int

gh-ost在cut-over階段最大的鎖等待時間,當鎖逾時時,gh-ost的cut-over将重試。(預設值:3)

-database string

資料庫名稱。

-debug

debug模式。

-default-retries int

各種操作在panick前重試次數。(預設為60)

-discard-foreign-keys

很危險的參數,慎用!

該參數針對一個有外鍵的表,在gh-ost建立ghost表時,并不會為ghost表建立外鍵。該參數很适合用于删除外鍵,除此之外,請謹慎使用。

-exact-rowcount

準确統計表行數(使用select count(*)的方式),得到更準确的預估時間。

-execute

實際執行alter&migrate表,預設為不執行,僅僅做測試并退出,如果想要ALTER TABLE語句真正落實到資料庫中去,需要明确指定

-execute

-force-named-cut-over

When true, the ‘unpostpone|cut-over’ interactive command must name the migrated table。

-heartbeat-interval-millis int

gh-ost心跳頻率值,預設為500。

-help

顯示gh-ost的幫助資訊。

-hooks-hint string

arbitrary message to be injected to hooks via GH_OST_HOOKS_HINT, for your convenience。

-hooks-path string

hook檔案存放目錄(預設為empty,即禁用hook)。hook會在這個目錄下尋找符合約定命名的hook檔案來執行。

-host string

資料庫的ip/hostname。(預設值:127.0.0.1)。

-initially-drop-ghost-table

gh-ost操作之前,檢查并删除已經存在的ghost表。該參數不建議使用,請手動處理原來存在的ghost表。預設不啟用該參數,gh-ost直接退出操作。

-initially-drop-old-table

gh-ost操作之前,檢查并删除已經存在的舊表。該參數不建議使用,請手動處理原來存在的ghost表。預設不啟用該參數,gh-ost直接退出操作。

-initially-drop-socket-file

gh-ost強制删除已經存在的socket檔案。該參數不建議使用,可能會删除一個正在運作的gh-ost程式,導緻DDL失敗。

-max-lag-millis int

主從複制最大延遲時間,當主從複制延遲時間超過該值後,gh-ost将采取節流(throttle)措施,預設值:1500s。

-max-load string

一系列逗号分隔的status-name=values組成,當MySQL中status超過對應的values,gh-ost将采取節流(throttle)措施。

e.g:

-max-load Threads_connected=20,Connections=1500

指的是當MySQL中的狀态值Threads_connected>20,Connections>1500的時候,gh-ost将采取節流(throttle)措施。

-migrate-on-replica

gh-ost的資料遷移(migrate)運作在從庫上,而不是主庫上。

Have the migration run on a replica, not on the master. This will do the full migration on the replica including cut-over (as opposed to –test-on-replica)

-nice-ratio float

每次chunk時間段的休眠時間,範圍[0.0…100.0]。

e.g:

0:每個chunk時間段不休眠,即一個chunk接着一個chunk執行;

1:每row-copy 1毫秒,則另外休眠1毫秒;

0.7:每row-copy 10毫秒,則另外休眠7毫秒。

-ok-to-drop-table

gh-ost操作結束後,删除舊表,預設狀态是不删除舊表,會存在_tablename_del表。

-panic-flag-file string

當這個檔案被建立,gh-ost将會立即退出。

-password string

MySQL密碼。

-port int

MySQL端口。

-postpone-cut-over-flag-file string

當這個檔案存在的時候,gh-ost的cut-over階段将會被推遲,直到該檔案被删除。

-quiet

靜默模式。

-replication-lag-query string

檢查主從複制延遲的SQL語句,預設gh-ost通過show slave status擷取Seconds_behind_master作為主從延遲時間依據。如果使用pt-heartbeat工具,檢查主從複制延遲的SQL語句類似于:

SELECT ROUND(UNIX_TIMESTAMP() - MAX(UNIX_TIMESTAMP(ts))) AS delay FROM my_schema.heartbeat;

-serve-socket-file string

gh-ost的socket檔案絕對路徑。

-serve-tcp-port int

gh-ost使用端口,預設為關閉端口。

-skip-renamed-columns ALTER

如果你修改一個列的名字(如change column),gh-ost将會識别到并且需要提供重命名列名的原因,預設情況下gh-ost是不繼續執行的。該參數告訴gh-ost跳該列的資料遷移,讓gh-ost把重命名列作為無關緊要的列。該操作很危險,你會損失該列的所有值。

e.g:

原始表資料:

mysql> select * from t;
+----+------+----+------+------+------+-------+
| id | name | c1 | col2 | col3 | col4 | col11 |
+----+------+----+------+------+------+-------+
|  1 |      | 22 |    0 |    0 |    0 |     0 |
|  2 |      | 22 |    0 |    0 |    0 |     0 |
|  3 |      | 22 |    0 |    0 |    0 |     0 |
+----+------+----+------+------+------+-------+
           
執行指令:

gh-ost -user="wing" -host="127.0.0.1" -port=3306 -database="wing" -table="t" -password="wing" -alter="change column c1 col1 int not null default 0" -assume-rbr -execute -skip-renamed-columns ALTER

操作後表資料:
mysql> select * from t;
+----+------+------+------+------+------+-------+
| id | name | col1 | col2 | col3 | col4 | col11 |
+----+------+------+------+------+------+-------+
|  1 |      |      |    0 |    0 |    0 |     0 |
|  2 |      |      |    0 |    0 |    0 |     0 |
|  3 |      |      |    0 |    0 |    0 |     0 |
+----+------+------+------+------+------+-------+
3 rows in set ( sec)
           

-stack

添加錯誤堆棧追蹤。

-switch-to-rbr

讓gh-ost自動将從庫的binlog_format轉換為ROW格式。

-table string

表名稱。

-test-on-replica

在從庫上測試gh-ost,包括在從庫上資料遷移(migration),資料遷移完成後stop slave,原表和ghost表立刻交換而後立刻交換回來。繼續保持stop slave,使你可以對比兩張表。

-test-on-replica-skip-replica-stop

-test-on-replica

執行時,該參數表示該過程中不用stop slave。

-throttle-additional-flag-file string

當該檔案被建立後,gh-ost操作立即停止。該參數可以用在多個gh-ost同時操作的時候,建立一個檔案,讓所有的gh-ost操作停止,或者删除這個檔案,讓所有的gh-ost操作恢複。

-throttle-control-replicas string

列出所有需要被檢查主從複制延遲的從庫。

e.g:

-throttle-control-replica=192.16.12.22:3306,192.16.12.23:3307,192.16.13.12:3308

-throttle-flag-file string

當該檔案被建立後,gh-ost操作立即停止。該參數适合控制單個gh-ost操作。

-throttle-additional-flag-file string

适合控制多個gh-ost操作。

-throttle-query string

節流查詢。每秒鐘執行一次。當傳回值=0時不需要節流,當傳回值>0時,需要執行節流操作。該查詢會在資料遷移(migrated)伺服器上操作,是以請確定該查詢是輕量級的。

-tungsten

告訴gh-ost你正在運作的是一個tungsten-replication拓撲結構。

-user string

MySQL使用者。

-verbose

gh-ost運作時輸出詳細資訊。

-version

輸出gh-ost版本資訊并退出。