×
技术社区 >  技术博客 >  OceanBase 4.3 适配 gh-ost 在线无锁 DDL 指南

OceanBase 4.3 适配 gh-ost 在线无锁 DDL 指南

背景

gh-ost 是 GitHub 开源的 MySQL 在线 DDL 工具,通过创建幽灵表(ghost table)并利用 binlog 回放增量变更,实现低锁、低负载的表结构变更。

OceanBase作为分布式数据库,其 MySQL 兼容模式虽支持大部分 gh-ost 功能,但官方原生 gh-ost 无法直接运行,需使用社区适配版本(如 whhe/gh-ost 的 OB 分支)。

基础环境:

  • 操作系统:Alibaba Cloud Linux release 3 (OpenAnolis Edition)

  • 数据库版本:OceanBase_CE 4.3.5.3

  • 代理版本:ObProxy-OceanBase 4.3.6.1-2.el7

  • Binlog 组件:obbinlog-ce-4.3.5-100000262026010516

  • gh-ost 适配版本:https://github.com/whhe/gh-ost/releases/tag/ob-2025030601

基础配置:

sys租户修改ODP配置 proxy_id、client_session_id_version、enable_single_leader_node_routing

  • proxy_id是给proxy设置id,不同proxy应该设置不同,用于识别proxy链接的和生成唯一client session id。
  • client_session_id_version修改为2,支持全局session id的能力,这就需要唯一的proxy_id
  • enable_single_leader_node_routing设置为false以后,pB会绕过OB2.0协议。表锁功能依赖MySQL协议,因此需要关闭该功能。
  • 需要开启OB binlog
alter proxyconfig set proxy_id=1; -- 保证每个proxy不同即可
alter proxyconfig set client_session_id_version=2;
alter proxyconfig set enable_single_leader_node_routing = false;

租户需要开启一下配置: enable_lock_priority 对于 DDL 性能可能有影响,细节参考 ,使用完毕建议及时关闭。

alter system set enable_lock_priority ='true';

工具安装配置

下载并安装适配 oceanbase 的 fork 版本

https://github.com/whhe/gh-ost/releases/tag/ob-2025030601

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
  -o gh-ost go/cmd/gh-ost/main.go

sudo mv gh-ost /usr/local/bin/
sudo chmod +x /usr/local/bin/gh-ost

测试验证:

gh-ost --version

输出示例(无版本号属正常)

测试参数情况:

参数 说明
--assume-rbr 跳过 binlog 格式检查和 STOP/START SLAVE
--aliyun-rds 跳过不兼容的系统查询
--skip-foreign-key-checks 跳过外键检查
--allow-on-master OceanBase 无从库概念时必须
--initially-drop-ghost-table 清理可能残留的 ghost 表
--initially-drop-old-table 清理可能残留的 old 表

实验

obclient -h127.0.0.1 -P2883 -uroot@mysql_test -p

实验前准备:

测试表
-- ============================================================
-- 测试表1:基础业务表(员工表)
-- ============================================================
CREATE TABLE t_employee (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(200) NOT NULL,
    department VARCHAR(50) DEFAULT 'Engineering',
    salary DECIMAL(10,2) DEFAULT 0.00,
    status TINYINT NOT NULL DEFAULT 1,
    phone VARCHAR(20) DEFAULT NULL COMMENT '手机号
  ,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_department (department),
    INDEX idx_email (email),
    INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


-- ============================================================
-- 测试表2:订单表(含多种数据类型)
-- ============================================================
CREATE TABLE t_order (
    order_id BIGINT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    order_no VARCHAR(64) NOT NULL,
    amount DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    status ENUM('pending','paid','shipped','completed','cancelled') DEFAULT 'pending',
    pay_time DATETIME DEFAULT NULL,
    remark TEXT DEFAULT NULL,
    extra JSON DEFAULT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uk_order_no (order_no),
    INDEX idx_user_id (user_id),
    INDEX idx_status (status),
    INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ============================================================
-- 测试表3:日志表(大文本字段)
-- ============================================================
CREATE TABLE t_log (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    log_level VARCHAR(10) NOT NULL DEFAULT 'INFO',
    module VARCHAR(50) NOT NULL,
    message TEXT NOT NULL,
    trace_id VARCHAR(64) DEFAULT NULL,
    created_at DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
    INDEX idx_level (log_level),
    INDEX idx_module (module),
    INDEX idx_trace (trace_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

测试1:


删除普通列
gh-ost \
  --host=127.0.0.1 --port=2883 \
  --user="root@mysql_test" --password="aaAA11__ob" \
  --database="lx" --table="t_employee" \
  --alter="drop COLUMN phone " \
  --assume-rbr --aliyun-rds --skip-foreign-key-checks \
    --cut-over=default \
  --allow-on-master \
  --initially-drop-ghost-table --initially-drop-old-table --ok-to-drop-table \
  --chunk-size=1000 --verbose \
  --execute

结果:

2026-08-10 09:38:34 INFO starting gh-ost unversioned (git commit: unknown)
2026-08-10 09:38:34 INFO Migrating `test`.`t_employee`
2026-08-10 09:38:34 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:38:34 INFO inspector connection validated on 127.0.0.1:2883
2026-08-10 09:38:34 INFO User has ALL privileges
2026-08-10 09:38:34 INFO binary logs validated on 127.0.0.1:2883
2026-08-10 09:38:34 INFO Inspector initiated on 127.0.0.1:2883, version 5.7.25-OceanBase_CE-v4.3.5.3
2026-08-10 09:38:34 INFO Table found. Engine=oceanbase
2026-08-10 09:38:34 WARNING --skip-foreign-key-checks provided: will not check for foreign keys []
2026-08-10 09:38:34 INFO Estimated number of rows via EXPLAIN: 0
2026-08-10 09:38:34 INFO Recursively searching for replication master
2026-08-10 09:38:34 INFO Master found to be 127.0.0.1:2883
2026-08-10 09:38:34 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:38:34 INFO streamer connection validated on 127.0.0.1:2883
[2026/08/10 09:38:34] [info] binlogsyncer.go:173 create BinlogSyncer with config {ServerID:99999 Flavor:mysql Host:127.0.0.1 Port:2883 User:root@mysql_test Password: Localhost: Charset: SemiSyncEnabled:false RawModeEnabled:false TLSConfig: ParseTime:false TimestampStringLocation:UTC UseDecimal:true RecvBufferSize:0 HeartbeatPeriod:0s ReadTimeout:0s MaxReconnectAttempts:0 DisableRetrySync:false VerifyChecksum:false DumpCommandFlag:0 Option: Logger:0xc000076420 Dialer:0x68f940 RowsEventDecodeFunc: DiscardGTIDSet:false}
2026-08-10 09:38:34 INFO Connecting binlog streamer at mysql-bin.000001:6824315
[2026/08/10 09:38:34] [info] binlogsyncer.go:410 begin to sync binlog from position (mysql-bin.000001, 6824315)
[2026/08/10 09:38:35] [info] binlogsyncer.go:813 rotate to (mysql-bin.000001, 6824315)
2026-08-10 09:38:35 INFO rotate to next log from mysql-bin.000001:0 to mysql-bin.000001
2026-08-10 09:38:35 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:38:35 INFO applier connection validated on 127.0.0.1:2883
2026-08-10 09:38:35 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:38:35 INFO applier connection validated on 127.0.0.1:2883
2026-08-10 09:38:35 INFO will use time_zone='+08:00' on applier
2026-08-10 09:38:35 INFO Examining table structure on applier
2026-08-10 09:38:35 INFO Applier initiated on 127.0.0.1:2883, version 5.7.25-OceanBase_CE-v4.3.5.3
2026-08-10 09:38:35 INFO Dropping table `test`.`_t_employee_gho`
2026-08-10 09:38:35 INFO Table dropped
2026-08-10 09:38:35 INFO Dropping table `test`.`_t_employee_del`
2026-08-10 09:38:35 INFO Table dropped
2026-08-10 09:38:35 INFO Dropping table `test`.`_t_employee_ghc`
2026-08-10 09:38:35 INFO Table dropped
2026-08-10 09:38:35 INFO Creating changelog table `test`.`_t_employee_ghc`
2026-08-10 09:38:35 INFO Changelog table created
2026-08-10 09:38:35 INFO Creating ghost table `test`.`_t_employee_gho`
2026-08-10 09:38:35 INFO Ghost table created
2026-08-10 09:38:35 INFO Altering ghost table `test`.`_t_employee_gho`
2026-08-10 09:38:35 INFO Ghost table altered
2026-08-10 09:38:35 INFO Waiting for ghost table to be migrated. Current lag is 0s
2026-08-10 09:38:36 INFO Intercepted changelog state GhostTableMigrated
2026-08-10 09:38:36 INFO Handled changelog state GhostTableMigrated
2026-08-10 09:38:36 INFO Chosen shared unique key is PRIMARY
2026-08-10 09:38:36 INFO Shared columns are id,name,email,department,salary,status,created_at,updated_at
2026-08-10 09:38:36 INFO Listening on unix socket file: /tmp/gh-ost.test.t_employee.sock
2026-08-10 09:38:36 INFO Migration min values: []
2026-08-10 09:38:36 INFO Migration max values: []
2026-08-10 09:38:36 INFO Waiting for first throttle metrics to be collected
2026-08-10 09:38:36 INFO First throttle metrics collected
# Migrating `test`.`t_employee`; Ghost table is `test`.`_t_employee_gho`
# Migrating 127.0.0.1:2883; inspecting 127.0.0.1:2883; executing on iZbp1dolvurzctg3ubygceZ
# Migration started at Mon Aug 10 09:38:34 +0800 2026
# chunk-size: 1000; max-lag-millis: 1500ms; dml-batch-size: 10; max-load: ; critical-load: ; nice-ratio: 0.000000
# throttle-additional-flag-file: /tmp/gh-ost.throttle 
# Serving on unix socket: /tmp/gh-ost.test.t_employee.sock
2026-08-10 09:38:36 INFO Row copy complete
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 2s(total), 0s(copy); streamer: mysql-bin.000001:6826508; Lag: 0.07s, HeartbeatLag: 0.38s, State: migrating; ETA: due
2026-08-10 09:38:36 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 2s(total), 0s(copy); streamer: mysql-bin.000001:6826508; Lag: 0.07s, HeartbeatLag: 0.38s, State: migrating; ETA: due []
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 2s(total), 0s(copy); streamer: mysql-bin.000001:6826508; Lag: 0.07s, HeartbeatLag: 0.38s, State: migrating; ETA: due
2026-08-10 09:38:36 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 2s(total), 0s(copy); streamer: mysql-bin.000001:6826508; Lag: 0.07s, HeartbeatLag: 0.38s, State: migrating; ETA: due []
2026-08-10 09:38:36 INFO Locking test.t_employee
2026-08-10 09:38:36 INFO Table test.t_employee locked
2026-08-10 09:38:36 INFO Writing changelog state: AllEventsUpToLockProcessed:1786325916621967439
2026-08-10 09:38:36 INFO Waiting for events up to lock
2026-08-10 09:38:36 INFO Intercepted changelog state ReadMigrationRangeValues
2026-08-10 09:38:36 INFO Handled changelog state ReadMigrationRangeValues
2026-08-10 09:38:36 INFO Intercepted changelog state AllEventsUpToLockProcessed
2026-08-10 09:38:36 INFO Handled changelog state AllEventsUpToLockProcessed
2026-08-10 09:38:37 INFO Waiting for events up to lock: got AllEventsUpToLockProcessed:1786325916621967439
2026-08-10 09:38:37 INFO Done waiting for events up to lock; duration=868.107724ms
# Migrating `test`.`t_employee`; Ghost table is `test`.`_t_employee_gho`
# Migrating 127.0.0.1:2883; inspecting 127.0.0.1:2883; executing on iZbp1dolvurzctg3ubygceZ
# Migration started at Mon Aug 10 09:38:34 +0800 2026
# chunk-size: 1000; max-lag-millis: 1500ms; dml-batch-size: 10; max-load: ; critical-load: ; nice-ratio: 0.000000
# throttle-additional-flag-file: /tmp/gh-ost.throttle 
# Serving on unix socket: /tmp/gh-ost.test.t_employee.sock
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 3s(total), 0s(copy); streamer: mysql-bin.000001:6833094; Lag: 0.08s, HeartbeatLag: 0.38s, State: migrating; ETA: due
2026-08-10 09:38:37 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 3s(total), 0s(copy); streamer: mysql-bin.000001:6833094; Lag: 0.08s, HeartbeatLag: 0.38s, State: migrating; ETA: due []
2026-08-10 09:38:37 INFO Locking test._t_employee_gho
2026-08-10 09:38:37 INFO Table test._t_employee_gho locked
2026-08-10 09:38:37 INFO Setting RENAME timeout as 3 seconds
2026-08-10 09:38:37 INFO Issuing and expecting this to block: rename /* gh-ost */ table `test`.`t_employee` to `test`.`_t_employee_del`, `test`.`_t_employee_gho` to `test`.`t_employee`
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 3s(total), 0s(copy); streamer: mysql-bin.000001:6833566; Lag: 0.08s, HeartbeatLag: 0.30s, State: migrating; ETA: due
2026-08-10 09:38:37 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 3s(total), 0s(copy); streamer: mysql-bin.000001:6833566; Lag: 0.08s, HeartbeatLag: 0.30s, State: migrating; ETA: due []
2026-08-10 09:38:37 INFO Tables renamed
2026-08-10 09:38:37 INFO Unlocking tables
2026-08-10 09:38:37 INFO Tables unlocked
2026-08-10 09:38:37 INFO Writing changelog state: Migrated
[2026/08/10 09:38:37] [info] binlogsyncer.go:206 syncer is closing...
[2026/08/10 09:38:37] [info] binlogsyncer.go:906 kill last connection id 311801
[2026/08/10 09:38:37] [info] binlogsyncer.go:236 syncer is closed
2026-08-10 09:38:37 INFO Closed streamer connection. err=
2026-08-10 09:38:37 INFO Dropping table `test`.`_t_employee_ghc`
2026-08-10 09:38:37 INFO Table dropped
2026-08-10 09:38:37 INFO Dropping table `test`.`_t_employee_del`
2026-08-10 09:38:37 ERROR Error 1146 (42S02): Table 'test._t_employee_ghc' doesn't exist
2026-08-10 09:38:38 ERROR Error 1146 (42S02): Table 'test._t_employee_ghc' doesn't exist
2026-08-10 09:38:38 ERROR Error 1146 (42S02): Table 'test._t_employee_ghc' doesn't exist
2026-08-10 09:38:38 INFO Table dropped
2026-08-10 09:38:38 INFO Done migrating `test`.`t_employee`
2026-08-10 09:38:38 INFO Removing socket file: /tmp/gh-ost.test.t_employee.sock
2026-08-10 09:38:38 INFO Tearing down inspector
2026-08-10 09:38:38 INFO Tearing down applier
2026-08-10 09:38:38 INFO Tearing down streamer
2026-08-10 09:38:38 INFO Tearing down throttler

测试2:


修改列类型
gh-ost \
  --host=127.0.0.1 --port=2883 \
  --user="root@mysql_test" --password="aaAA11__ob" \
  --database="lx" --table="t_order" \
  --alter="MODIFY COLUMN user_id int UNSIGNED NOT NULL COMMENT '用户ID-改为无符号'" \
  --assume-rbr --aliyun-rds --skip-foreign-key-checks \
  --allow-on-master \
  --cut-over=default \
  --initially-drop-ghost-table --initially-drop-old-table --ok-to-drop-table \
  --chunk-size=1000 --verbose \
  --execute

结果:

2026-08-10 09:42:47 INFO starting gh-ost unversioned (git commit: unknown)
2026-08-10 09:42:47 INFO Migrating `test`.`t_order`
2026-08-10 09:42:47 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:42:47 INFO inspector connection validated on 127.0.0.1:2883
2026-08-10 09:42:47 INFO User has ALL privileges
2026-08-10 09:42:47 INFO binary logs validated on 127.0.0.1:2883
2026-08-10 09:42:47 INFO Inspector initiated on 127.0.0.1:2883, version 5.7.25-OceanBase_CE-v4.3.5.3
2026-08-10 09:42:48 INFO Table found. Engine=oceanbase
2026-08-10 09:42:48 WARNING --skip-foreign-key-checks provided: will not check for foreign keys []
2026-08-10 09:42:48 INFO Estimated number of rows via EXPLAIN: 0
2026-08-10 09:42:48 INFO Recursively searching for replication master
2026-08-10 09:42:48 INFO Master found to be 127.0.0.1:2883
2026-08-10 09:42:48 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:42:48 INFO streamer connection validated on 127.0.0.1:2883
[2026/08/10 09:42:48] [info] binlogsyncer.go:173 create BinlogSyncer with config {ServerID:99999 Flavor:mysql Host:127.0.0.1 Port:2883 User:root@mysql_test Password: Localhost: Charset: SemiSyncEnabled:false RawModeEnabled:false TLSConfig: ParseTime:false TimestampStringLocation:UTC UseDecimal:true RecvBufferSize:0 HeartbeatPeriod:0s ReadTimeout:0s MaxReconnectAttempts:0 DisableRetrySync:false VerifyChecksum:false DumpCommandFlag:0 Option: Logger:0xc0000b8900 Dialer:0x68f940 RowsEventDecodeFunc: DiscardGTIDSet:false}
2026-08-10 09:42:48 INFO Connecting binlog streamer at mysql-bin.000001:6838078
[2026/08/10 09:42:48] [info] binlogsyncer.go:410 begin to sync binlog from position (mysql-bin.000001, 6838078)
2026-08-10 09:42:48 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
[2026/08/10 09:42:48] [info] binlogsyncer.go:813 rotate to (mysql-bin.000001, 6838078)
2026-08-10 09:42:48 INFO rotate to next log from mysql-bin.000001:0 to mysql-bin.000001
2026-08-10 09:42:48 INFO applier connection validated on 127.0.0.1:2883
2026-08-10 09:42:48 INFO OceanBase connection identified, version_comment: OceanBase_CE 4.3.5.3 (r103020012025120120-de5425fc0077d196353e20b011045b8c2d7d5514) (Built Dec  1 2025 20:46:46)
2026-08-10 09:42:48 INFO applier connection validated on 127.0.0.1:2883
2026-08-10 09:42:48 INFO will use time_zone='+08:00' on applier
2026-08-10 09:42:48 INFO Examining table structure on applier
2026-08-10 09:42:48 INFO Applier initiated on 127.0.0.1:2883, version 5.7.25-OceanBase_CE-v4.3.5.3
2026-08-10 09:42:48 INFO Dropping table `test`.`_t_order_gho`
2026-08-10 09:42:48 INFO Table dropped
2026-08-10 09:42:48 INFO Dropping table `test`.`_t_order_del`
2026-08-10 09:42:48 INFO Table dropped
2026-08-10 09:42:48 INFO Dropping table `test`.`_t_order_ghc`
2026-08-10 09:42:48 INFO Table dropped
2026-08-10 09:42:48 INFO Creating changelog table `test`.`_t_order_ghc`
2026-08-10 09:42:49 INFO Changelog table created
2026-08-10 09:42:49 INFO Creating ghost table `test`.`_t_order_gho`
2026-08-10 09:42:49 INFO Ghost table created
2026-08-10 09:42:49 INFO Altering ghost table `test`.`_t_order_gho`
2026-08-10 09:42:56 INFO Ghost table altered
2026-08-10 09:42:56 INFO Waiting for ghost table to be migrated. Current lag is 0s
2026-08-10 09:42:56 INFO Intercepted changelog state GhostTableMigrated
2026-08-10 09:42:56 INFO Handled changelog state GhostTableMigrated
2026-08-10 09:42:56 INFO Chosen shared unique key is PRIMARY
2026-08-10 09:42:56 INFO Shared columns are order_id,user_id,order_no,amount,status,pay_time,remark,extra,created_at
2026-08-10 09:42:56 INFO Listening on unix socket file: /tmp/gh-ost.test.t_order.sock
2026-08-10 09:42:56 INFO Migration min values: []
2026-08-10 09:42:56 INFO Migration max values: []
2026-08-10 09:42:56 INFO Waiting for first throttle metrics to be collected
2026-08-10 09:42:56 INFO First throttle metrics collected
# Migrating `test`.`t_order`; Ghost table is `test`.`_t_order_gho`
# Migrating 127.0.0.1:2883; inspecting 127.0.0.1:2883; executing on iZbp1dolvurzctg3ubygceZ
# Migration started at Mon Aug 10 09:42:47 +0800 2026
# chunk-size: 1000; max-lag-millis: 1500ms; dml-batch-size: 10; max-load: ; critical-load: ; nice-ratio: 0.000000
# throttle-additional-flag-file: /tmp/gh-ost.throttle 
# Serving on unix socket: /tmp/gh-ost.test.t_order.sock
2026-08-10 09:42:56 INFO Row copy complete
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 8s(total), 0s(copy); streamer: mysql-bin.000001:6838750; Lag: 0.14s, HeartbeatLag: 9223372036.85s, State: migrating; ETA: due
2026-08-10 09:42:56 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 8s(total), 0s(copy); streamer: mysql-bin.000001:6838750; Lag: 0.14s, HeartbeatLag: 9223372036.85s, State: migrating; ETA: due []
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 8s(total), 0s(copy); streamer: mysql-bin.000001:6838750; Lag: 0.14s, HeartbeatLag: 9223372036.85s, State: migrating; ETA: due
2026-08-10 09:42:56 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 8s(total), 0s(copy); streamer: mysql-bin.000001:6838750; Lag: 0.14s, HeartbeatLag: 9223372036.85s, State: migrating; ETA: due []
2026-08-10 09:42:56 INFO Locking test.t_order
2026-08-10 09:42:56 INFO Table test.t_order locked
2026-08-10 09:42:56 INFO Writing changelog state: AllEventsUpToLockProcessed:1786326176679732974
2026-08-10 09:42:56 INFO Waiting for events up to lock
2026-08-10 09:42:56 INFO Intercepted changelog state ReadMigrationRangeValues
2026-08-10 09:42:56 INFO Handled changelog state ReadMigrationRangeValues
2026-08-10 09:42:57 INFO Intercepted changelog state AllEventsUpToLockProcessed
2026-08-10 09:42:57 INFO Handled changelog state AllEventsUpToLockProcessed
2026-08-10 09:42:57 INFO Waiting for events up to lock: got AllEventsUpToLockProcessed:1786326176679732974
2026-08-10 09:42:57 INFO Done waiting for events up to lock; duration=900.42462ms
# Migrating `test`.`t_order`; Ghost table is `test`.`_t_order_gho`
# Migrating 127.0.0.1:2883; inspecting 127.0.0.1:2883; executing on iZbp1dolvurzctg3ubygceZ
# Migration started at Mon Aug 10 09:42:47 +0800 2026
# chunk-size: 1000; max-lag-millis: 1500ms; dml-batch-size: 10; max-load: ; critical-load: ; nice-ratio: 0.000000
# throttle-additional-flag-file: /tmp/gh-ost.throttle 
# Serving on unix socket: /tmp/gh-ost.test.t_order.sock
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 9s(total), 0s(copy); streamer: mysql-bin.000001:6845871; Lag: 0.04s, HeartbeatLag: 0.34s, State: migrating; ETA: due
2026-08-10 09:42:57 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 9s(total), 0s(copy); streamer: mysql-bin.000001:6845871; Lag: 0.04s, HeartbeatLag: 0.34s, State: migrating; ETA: due []
2026-08-10 09:42:57 INFO Locking test._t_order_gho
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 9s(total), 0s(copy); streamer: mysql-bin.000001:6845871; Lag: 0.04s, HeartbeatLag: 0.34s, State: migrating; ETA: due
2026-08-10 09:42:57 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 9s(total), 0s(copy); streamer: mysql-bin.000001:6845871; Lag: 0.04s, HeartbeatLag: 0.34s, State: migrating; ETA: due []
2026-08-10 09:42:57 INFO Table test._t_order_gho locked
2026-08-10 09:42:57 INFO Setting RENAME timeout as 3 seconds
2026-08-10 09:42:57 INFO Issuing and expecting this to block: rename /* gh-ost */ table `test`.`t_order` to `test`.`_t_order_del`, `test`.`_t_order_gho` to `test`.`t_order`
2026-08-10 09:42:58 INFO Tables renamed
2026-08-10 09:42:58 INFO Unlocking tables
2026-08-10 09:42:58 INFO Tables unlocked
2026-08-10 09:42:58 INFO Writing changelog state: Migrated
[2026/08/10 09:42:58] [info] binlogsyncer.go:206 syncer is closing...
[2026/08/10 09:42:58] [info] binlogsyncer.go:906 kill last connection id 311808
[2026/08/10 09:42:58] [info] binlogsyncer.go:236 syncer is closed
2026-08-10 09:42:58 INFO Closed streamer connection. err=
2026-08-10 09:42:58 INFO Dropping table `test`.`_t_order_ghc`
2026-08-10 09:42:58 INFO Table dropped
2026-08-10 09:42:58 INFO Dropping table `test`.`_t_order_del`
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 10s(total), 0s(copy); streamer: mysql-bin.000001:6849436; Lag: 0.04s, HeartbeatLag: 0.64s, State: migrating; ETA: due
2026-08-10 09:42:58 INFO Copy: 0/0 100.0%; Applied: 0; Backlog: 0/1000; Time: 10s(total), 0s(copy); streamer: mysql-bin.000001:6849436; Lag: 0.04s, HeartbeatLag: 0.64s, State: migrating; ETA: due []
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:58 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:59 ERROR Error 1146 (42S02): Table 'test._t_order_ghc' doesn't exist
2026-08-10 09:42:59 INFO Table dropped
2026-08-10 09:42:59 INFO Done migrating `test`.`t_order`
2026-08-10 09:42:59 INFO Removing socket file: /tmp/gh-ost.test.t_order.sock
2026-08-10 09:42:59 INFO Tearing down inspector
2026-08-10 09:42:59 INFO Tearing down applier
2026-08-10 09:42:59 INFO Tearing down streamer
2026-08-10 09:42:59 INFO Tearing down throttler

迁移完成后注意事项

1.恢复租户参数 :sql ALTER SYSTEM SET enable_lock_priority = 'false';

2.确认新表结构正确,业务无异常。

3.检查是否残留临时表:

SHOW TABLES LIKE '%_gho'; 
SHOW TABLES LIKE '%_ghc'; 
SHOW TABLES LIKE '%_del';

若有残留可手动 DROP。

精选推荐