**> FGO2CDB(全称: FGEDU Overseas to China DataBase Migration),是一款国外数据库 → 国产数据库 高性能统一迁移平台(命令行 + 可视化)
**功能简介:FGO2CDB 是面向信创/国产化场景的一站式数据库迁移平台,覆盖 Oracle / MySQL / Percona / MariaDB / PostgreSQL / DB2 / SQL Server / Redis / MongoDB 等源端到达梦 DM / 金仓 KingbaseES V9 / TiDB / TDSQL / GBase / openGauss / OceanBase(MySQL/Oracle 双模式)/ GreatSQL / GaussDB(DWS) / GaussDB(TPOPS) / YashanDB / GoldenDB 等国产目标端的全流程迁移。平台支持表结构、数据、索引、视图、函数、存储过程、触发器、序列的自动转换与迁移,内置原生 C 类型映射引擎 + Python 流式管道,提供断点续传、暂停/恢复/停止、批量 COPY 写入、并发多表、内存保护、连接池重试、数据行数 + 抽样校验,以及可视化控制台、迁移评估报告。支持 KingbaseES V9、openGauss、GaussDB DWS/TPOPS、OceanBase 等多兼容模式切换,全链路 UTF-8 强制,确保 GB ~ TB 级数据零乱码迁移;对于无法自动转换的程序对象(视图/函数/存储过程/触发器),自动登记到人工处理清单。**
## 一、程序介绍
### 1.1 项目概述
**FGO2CDB 是由 风哥 倾力研发的面向信创/国产化场景的数据库迁移平台,工具底层采用C + Python混合架构,它将国外主流关系型/NoSQL 数据库统一抽象为「源端连接器 + 类型映射 + 流式管道 + 目标端写入器」的标准流水线,覆盖 结构迁移、数据迁移、对象迁移、进度跟踪、数据校验、迁移报告 全流程,支持 GB ~ TB 级数据量的稳定、高速、零乱码迁移。**
### 1.2 作者信息
| 项目 | 内容 |
| — | — |
| 作者 | 风哥 |
| 微信 | itpux-com |
| QQ | 113257174 |
| 官方网站 | http://www.fgedu.net.cn |
| 技术社区 | http://www.itpux.com |
| 数据库教程 | https://edu.51cto.com/lecturer/8020378.html |
### 1.3 设计理念
**统一平台:所有源端/目标端组合在同一个工具内完成,无需切换多个迁移产品;**
**配置驱动:每个迁移对提供独立 YAML 模板,复制即用;**
**命令行优先:命令行是主交互方式,便于 DevOps/CI-CD 集成;**
**可视化辅助:Web 控制台用于实时监控、评估、报告查看;**
**稳定优先:断点续传、自动重试、内存保护、连接池,保证 TB 级任务不中断;**
**零乱码:全链路 UTF-8 强制 + 二进制列 bytes 直传 + COPY 转义。**
────────────────────────────────────────
## 二、程序功能与特性
### 2.1 核心功能
| 功能 | 说明 |
| — | — |
| 表结构迁移 | 自动 DDL 转换(类型/约束/默认值/注释),跨方言兼容 |
| 数据迁移 | 流式游标读取 + 批量写入,支持 COPY FROM STDIN 高速导入 |
| 索引迁移 | 主键、唯一索引、普通索引自动重建 |
| 视图迁移 | SQL 方言转换(MySQL/PG/Oracle 互相适配) |
| 函数迁移 | PL/SQL ↔ PL/pgSQL 方言转换,含函数映射表 |
| 存储过程迁移 | 过程体语法转换,必要时人工复核 |
| 触发器迁移 | Oracle/YashanDB 等 PL/SQL 系支持 |
| 序列迁移 | 序列当前值同步,确保自增连续 |
| 迁移前评估 | 扫描源库对象,输出兼容性评分、风险清单、HTML 报告 |
| 进度跟踪 | SSE 实时推送表级/行级进度到 Web 控制台 |
| 数据校验 | 行数校验 + 抽样比对 + checksum 双向验证 |
| 迁移报告 | 自动生成 HTML 报告(已迁移表/错误/警告/不一致表) |
| 断点续传 | 每表独立检查点,中断重启自动跳过已完成表 |
| 并发迁移 | 线程池并发多表,I/O 与 CPU 充分利用 |
### 2.2 性能特性
**原生 C 引擎:负责类型转换/转义/编码,性能数倍于纯 Python;**
**流式游标:服务端游标 + fetch_size 批量拉取,避免大表 OOM;**
**生产者-消费者管道:读/转/写三级流水线,queue_size 缓冲背压;**
**COPY 批量导入:PG 系目标(Kingbase/openGauss/GaussDB)走 COPY FROM STDIN;**
**多表并发:concurrency 参数控制并发表数(默认 8-10);**
**动态批大小:按表大小自动调整 batch_insert_size,大表用大批次;**
**内存保护:memory_hard_limit_mb 硬限,超限自动降速;**
**规模预设:scale_preset(small/medium/large)一键适配硬件规格。**
### 2.3 稳定性特性
**断点续传:checkpoint_dir 保存每表进度,重启自动恢复;**
**指数退避重试:retry_max 次数 + retry_backoff_base 退避基数;**
**连接池:max_open_conns 复用连接,避免频繁握手;**
**死锁恢复:检测死锁/连接异常自动重连重试;**
**一致快照:consistent_snapshot 选项保证源端读一致性;**
**超时保护:per_table_timeout / global_timeout 双层超时熔断;**
**错误隔离:单表失败不阻塞其他表,错误日志独立记录。**
### 2.4 数据质量特性
**零乱码:全链路 UTF-8,utf8mb4 支持 emoji/4 字节字符;**
**二进制直传:BLOB/IMAGE/BYTEA 以 bytes 直传,不经过字符串层;**
**二进制兜底映射:原生引擎未命中时,按 BLOB/RAW/IMAGE/BYTEA 模式自动映射到目标族二进制类型(BLOB/BYTEA/LONGBLOB),避免 bytes 经字符串层产生乱码;**
**字符串兜底:未识别的字符类型一律映射到 TEXT/CLOB/LONGTEXT,保证不丢数据;**
**COPY 转义:COPY 模式自动处理 \t \n \\ \N 转义;**
**类型映射表:每个源-目标对都有详细类型映射 + 兜底策略(UNKNOWN → TEXT/CLOB/BLOB);**
**数据校验(强校验):行数比对 + 抽样 10 行 MD5 checksum 比对,双重保证不丢不错。**
### 2.5 加固特性(防崩溃、防丢数、防乱码)
**分批量提交:每表按 batch_insert_size 分批提交,单批失败按指数退避重试 retry_times 次,全部失败才标记失败;**
**断点续传强化:每批写入后立即保存 checkpoint(status=running, rows=N),中断重启自动跳过已完成表;**
**内存背压保护:按批次估算字节数,超过 memory_limit_mb 60% 自动降速,超过 memory_hard_limit_mb 强制降速,避免 OOM;**
**双层超时熔断:per_table_timeout(默认 86400s/1天)单表超时 + global_timeout(默认 432000s/5天)全局超时;**
**停止信号传播:web 控制台停止请求通过双重标志(_STOP_EVENT + pipeline._STOP_FLAG)传播到每个迁移线程,及时响应;**
**SSE 防过载:控制台 SSE 连接数硬限 100,每条队列上限 2000 条消息,30 分钟空闲自动断开,避免僵尸连接耗内存;**
**异常隔离:后台迁移线程异常不外泄到 Web 进程,单表失败不阻塞其他表;**
**重连恢复:单批失败重试时自动 disconnect+connect 重连目标端,处理死连接;**
**checksum 强校验:迁移后行数 + 抽样 MD5 比对,发现不一致即标记 fail,不静默通过。**
────────────────────────────────────────
## 三、支持环境
### 3.1 支持的操作系统(信创生态全覆盖)
**国产操作系统(主推):**
| OS | 支持版本 | 架构 |
| — | — | — |
| 麒麟 Kylin | Kylin V10 SP1/SP2/SP3、Kylin Server V10 | x86_64, aarch64, loongarch64 |
| 统信 UOS | UOS V20(1020/1021/1022/1060)、UOS Server | x86_64, aarch64, loongarch64, mips64el |
| 深度 Deepin | Deepin 20.x / 23 | x86_64, aarch64 |
| 欧拉 openEuler | 20.03 / 22.03 / 24.03 LTS | x86_64, aarch64, loongarch64 |
| 龙蜥 Anolis OS | 7.9 / 8.x | x86_64, aarch64 |
| 腾讯 TencentOS | Server 2.4 / 3.1 | x86_64, aarch64 |
| 鸿蒙 HarmonyOS | Server(轻量场景) | aarch64 |
**国外操作系统:**
| OS | 支持版本 | 架构 |
| — | — | — |
| CentOS | 7.x / 8.x / Stream 8/9 | x86_64, aarch64 |
| RHEL | 7.x / 8.x / 9.x | x86_64, aarch64, ppc64le |
| Ubuntu | 18.04 / 20.04 / 22.04 / 24.04 LTS | x86_64, aarch64 |
| Debian | 10 / 11 / 12 | x86_64, aarch64 |
| SUSE SLES | 12 / 15 | x86_64, aarch64 |
| Oracle Linux | 7 / 8 / 9 | x86_64, aarch64 |
| Rocky Linux | 8 / 9 | x86_64, aarch64 |
| AlmaLinux | 8 / 9 | x86_64, aarch64 |
| Fedora | 38 / 39 / 40 | x86_64, aarch64 |
| Microsoft Windows | Server 2016/2019/2022/2025、Windows 10/11 | x86_64 |
| Apple macOS | 11+(Big Sur/Monterey/Sonoma/Sequoia) | x86_64, arm64 |
| IBM AIX | 7.2 / 7.3 | ppc64/ppc64le |
### 3.2 CPU 架构
**x86_64 (amd64) — 主流服务器架构**
**aarch64 (arm64) — 鲲鹏/飞腾/擎天等国产 CPU**
**loongarch64 — 龙芯**
**mips64el — 龙芯旧指令集**
**sw_64 — 申威**
**ppc64/ppc64le — PowerPC(AIX/Linux on POWER)**
### 3.3 Python 环境
**Python 3.8+(推荐 3.9 / 3.10 / 3.11)**
**依赖:Flask、PyYAML、psycopg2-binary、pymysql、cx_Oracle/oracledb、pyodbc、pymongo、redis 等**
### 3.4 C 编译环境(编译原生引擎)
**GCC 7+ 或 Clang 10+(国产 CPU 需对应交叉工具链)**
**Make 3.8+**
**Windows 需 Visual Studio 2019+ (MSVC)**
**国产系统:麒麟/UOS 自带 gcc,openEuler/Anolis 用 dnf 安装**
### 3.5 支持的数据库版本
**源端(国外数据库):**
| 源端 | 支持版本 | 类型族 | 驱动/协议 |
| — | — | — | — |
| Oracle | 9i / 10g / 11g R1/R2 / 12c R1/R2 / 18c / 19c / 21c / 23ai / 26ai | oracle | oracledb |
| MySQL | 5.6 / 5.7 / 8.0 / 8.1-8.4 | mysql | PyMySQL |
| MariaDB | 10.3-10.11 / 11.x | mysql | PyMySQL |
| PostgreSQL | 9.6 / 10-16 / 17 | postgres | psycopg2 |
| IBM DB2 | 10.5 / 11.1 / 11.5 / 12.x (LUW) | db2 | pyodbc |
| MS SQL Server | 2008 R2 / 2012/2014/2016/2017/2019/2022 | sqlserver | pyodbc |
| Redis | 4.x / 5.x / 6.x / 7.x | redis | redis-py |
| MongoDB | 3.6 / 4.0-4.4 / 5.0 / 6.0 / 7.0 | mongodb | pymongo |
**目标端(国产数据库):**
| 目标 | 支持版本 | 类型族 | 协议兼容 | 默认端口 |
| — | — | — | — | — |
| 达梦 DM | DM7 / DM8 / DM9 | dm | 自研(SQL 标准) | 5236 |
| 金仓 KingbaseES | V8R3 / V8R6 / V9 | postgres | PostgreSQL | 54321 |
| TiDB | 4.0 / 5.x / 6.x / 7.x / 8.x | mysql | MySQL | 4000 |
| TDSQL | TDSQL-C MySQL 5.7/8.0 / TDSQL-C PostgreSQL | mysql | MySQL(分布式) | 15001 |
| GBase | GBase 8a 8.6/9.x / 8s 8.8/9.x / 8c | gbase | 自研 | 5258 |
| openGauss | 1.x-5.x / 6.x (B/Plus/企业版) | postgres | PostgreSQL | 5432 |
| OceanBase | 3.x / 4.x (MySQL/Oracle 模式) | mysql | MySQL 模式 | 2881 |
| GaussDB | GaussDB 200/100 (DWS) / Top 1.x-2.x / 分布式版 | postgres | PostgreSQL (MPP) | 25308 |
| YashanDB | 22.x / 23.x | oracle | Oracle | 1688 |
| GoldenDB | 6.x / 7.x / 8.x | mysql | MySQL(分布式) | 3306 |
### 3.6 硬件规格建议
| 规模预设 | CPU | 内存 | 磁盘 | 适用数据量 |
| — | — | — | — | — |
| small | 4 核 | 4 GB | SSD 100 GB | < 50 GB |
| medium | 8 核 | 8 GB | SSD 500 GB | 50 GB ~ 500 GB |
| large | 16 核 | 16 GB | NVMe 1 TB | 500 GB ~ 5 TB |
| xlarge | 32 核 | 32 GB+ | NVMe 2 TB+ | 5 TB ~ 50 TB |
### 3.7 关键配置参数(加固相关)
| 参数 | 默认值 | 说明 |
| — | — | — |
| `concurrency` | 8 | 多表并发度 |
| `batch_insert_size` | 50000 | 单批提交行数(分批量提交) |
| `fetch_size` | 10000 | 流式游标每批拉取 |
| `retry_times` | 3 | 单批失败重试次数 |
| `retry_delay` | 5.0 | 重试退避基数(指数退避 2^n) |
| `memory_limit_mb` | 2048 | 内存软限,超 60% 自动降速 |
| `memory_hard_limit_mb` | 4096 | 内存硬限,强制降速 |
| `per_table_timeout` | 86400 (1 天) | 单表超时熔断 |
| `global_timeout` | 432000 (5 天) | 全局超时熔断 |
| `large_table_threshold` | 1000000 | 大表阈值(启用更激进的批大小) |
| `huge_table_threshold` | 10000000 | 巨表阈值(启用分片并行) |
| `checkpoint_dir` | ./.checkpoint | 断点续传目录 |
────────────────────────────────────────
## 四、程序使用
### 4.1 安装
`# 1. 克隆项目`
`git clone <仓库地址> FGO2CDB`
`cd FGO2CDB`
` `
`# 2. 安装 Python 依赖`
`pip install -r requirements.txt`
` `
`# 3. 编译原生 C 引擎`
`make native`
` `
`# 4. 验证安装`
`python3 -m fgo2cdb –version`
### 4.2 命令行操作
#### 4.2.1 全量迁移(DDL + 数据 + 对象)
`python3 -m fgo2cdb convert -c config.yml`
#### 4.2.2 仅生成 DDL 脚本(不执行)
`python3 -m fgo2cdb ddl -c config.yml -o ddl.sql`
#### 4.2.3 仅迁移数据(结构已存在)
`python3 -m fgo2cdb data -c config.yml`
#### 4.2.4 数据校验
`python3 -m fgo2cdb validate -c config.yml`
#### 4.2.5 迁移前评估
`python3 -m fgo2cdb assess -c config.yml -o assess.html`
#### 4.2.6 生成迁移报告
`python3 -m fgo2cdb report -c config.yml -o report.html`
#### 4.2.7 指定表清单迁移
`python3 -m fgo2cdb convert -c config.yml \`
` –table-list t_user,t_order,t_order_item`
#### 4.2.8 断点续传(中断后重启)
`# 直接重跑同一命令,自动加载 checkpoint`
`python3 -m fgo2cdb convert -c config.yml`
#### 4.2.9 使用模板配置
`# 复制模板后修改连接信息即可`
`cp templates/oracle_to_dm.yml my_config.yml`
`vi my_config.yml`
`python3 -m fgo2cdb convert -c my_config.yml`
### 4.3 可视化操作
#### 4.3.1 启动控制台
`# 前台启动`
`python3 webctl.py start`
` `
`# 或指定端口`
`python3 webctl.py start –port 8088`
` `
`# 或用 Python 模块`
`python3 -m fgo2cdb.web –port 8088`
#### 4.3.2 后台守护进程启动
`python3 webctl.py start –daemon`
#### 4.3.3 查看状态 / 停止 / 重启
`python3 webctl.py status`
`python3 webctl.py stop`
`python3 webctl.py restart`
#### 4.3.4 控制台页面
**浏览器访问 `http://<服务器IP>:8088`,可执行:**
**配置编辑:在线编辑 YAML 配置,保存/加载;**
**连接测试:一键测试源端/目标端连通性;**
**迁移评估:扫描源库,输出兼容性评分与风险清单;**
**启动迁移:一键启动全量/数据迁移,SSE 实时进度推送;**
**停止迁移:安全停止当前任务(已迁移数据保留);**
**查看报告:迁移结束后生成 HTML 报告,含错误/警告/不一致表清单。**
#### 4.3.3 Web API 列表
| 方法 | 路径 | 说明 |
| — | — | — |
| GET | `/` | 控制台首页 |
| POST | `/api/test` | 测试源端/目标端连接 |
| POST | `/api/assess` | 迁移前评估,返回评分/风险 |
| GET | `/api/assess/report` | 获取评估 HTML 报告 |
| POST | `/api/convert` | 启动迁移任务 |
| POST | `/api/stop` | 停止当前迁移 |
| POST | `/api/config/save` | 保存配置 YAML |
| GET | `/api/config/load` | 加载配置 YAML |
| GET | `/api/report` | 获取迁移 HTML 报告 |
| GET | `/api/status` | 获取当前状态快照 |
| GET | `/api/progress` | SSE 实时进度流 |
### 4.4 模板文件配置项说明
**所有模板位于项目根目录 `templates/`,命名规则为 `<源库>_to_<目标库>.yml`(如 `oracle_to_oceanbase.yml`)。模板已按目标库族预置端口、字符集、并行度、批量大小等最佳实践值,复制后只需修改连接信息(host/port/username/password/database/schema)即可运行。完整结构如下:**
`# ========== 源端配置 ==========`
`source:`
` type: oracle # 源库逻辑类型:mysql/postgresql/oracle/db2/sqlserver/redis/mongodb`
` host: 10.0.0.10`
` port: 1521`
` username: SOURCE_USER`
` password: Source_Pwd_2024`
` database: ORCL # MySQL/PG/SQL Server 必填;Oracle 一般填 SID`
` schema: SOURCE_USER # Oracle/PG/DB2 必填;MySQL 留空`
` sid: “” # Oracle SID(与 service_name 二选一)`
` service_name: ORCL # Oracle service name`
` charset: UTF8 # 源库字符集(MySQL=utf8mb4 / Oracle=UTF8 / PG=UTF8)`
` connect_timeout: 30 # 连接超时(秒)`
` consistent_snapshot: true # 一致性快照(推荐开启,保证读一致性)`
` extra: # 源端专属参数`
` threaded: true # Oracle 多线程`
` driver: “ODBC Driver 17 for SQL Server” # SQL Server ODBC 驱动`
` encrypt: false # SQL Server 是否加密`
` auth_source: admin # MongoDB 认证库`
` `
`# ========== 目标端配置 ==========`
`target:`
` type: oceanbase # 目标库逻辑类型:dm/kingbase/tidb/tdsql/gbase/opengauss/oceanbase/gaussdb/yashandb/goldendb`
` mode: oracle # ★ OceanBase 专属:mysql(默认)/oracle;其它目标库不需要`
` host: 10.0.0.20`
` port: 2883 # OceanBase OBProxy=2883 / 直连=2881;DM=5236;KingbaseES=54321;TiDB=4000;GBase=5258;YashanDB=1688;GaussDB=25308;TDSQL=15001;GoldenDB=3306`
` username: SYS`
` password: `
` database: target_db`
` schema: SOURCE_USER # PG/Oracle 系必填;MySQL 系留空`
` service_name: “” # Oracle/YashanDB/OceanBase Oracle 模式按需填`
` charset: UTF8 # 目标库字符集`
` connect_timeout: 30`
` extra: # 目标端专属参数`
` ob_tenant_mode: oracle # OceanBase 租户模式(与 mode 对齐)`
` driver: oracle # 显式指定驱动`
` pg_protocol: true # PG 系(KingbaseES/openGauss/GaussDB)走 COPY 批量`
` is_dws: true # GaussDB DWS 数仓模式`
` distribution: hash # GaussDB DWS 分布策略`
` `
`# ========== 转换配置 ==========`
`conversion:`
` options: # 迁移内容开关(true=迁移,false=跳过)`
` tableddl: true # 表结构 DDL`
` data: true # 数据`
` indexes: true # 索引`
` views: false # 视图`
` functions: false # 函数`
` procedures: false # 存储过程(Oracle/OceanBase Oracle/YashanDB 支持)`
` triggers: false # 触发器`
` sequences: false # 序列`
` foreign_keys: false # 外键(默认关闭,迁移阶段避免约束阻塞)`
` validate_data: true # 数据校验(迁移后比对行数)`
` lowercase_tables: false # 是否把表名转为小写(PG 系常用 true)`
` lowercase_columns: false # 是否把列名转为小写`
` skip_existing_tables: true # 跳过已存在的表`
` truncate_before_sync: false # 同步前 truncate 目标表`
` use_table_list: false # 是否启用白名单(table_list)`
` table_list: [] # 白名单表`
` exclude_use_table_list: false`
` exclude_table_list: [] # 黑名单表`
` use_id_as_primary: true # MongoDB 专用:_id 作为主键`
` nested_doc_strategy: json # MongoDB 专用:嵌套文档存为 JSON/JSONB 列`
` limits: # 性能与稳定性`
` concurrency: 8 # 单表内并发度`
` parallel_tables: 4 # 多表并行度`
` batch_insert_size: 50000 # 批量插入大小`
` streaming_cursor: true # 流式游标(防大表内存爆)`
` fetch_size: 10000 # 每批抓取行数`
` queue_size: 4 # 队列深度`
` memory_limit_mb: 2048 # 软内存上限`
` memory_hard_limit_mb: 4096 # 硬内存上限(超过强制降速)`
` retry_times: 3 # 单批重试次数`
` retry_delay: 5.0 # 退避基数(秒)`
` bulk_insert: true # 启用 COPY/bulk 模式`
` large_table_threshold: 1000000 # 大表阈值(行)`
` huge_table_threshold: 10000000 # 巨表阈值(启用分片)`
` per_table_timeout: 86400 # 单表超时(秒)`
` global_timeout: 432000 # 全局超时(秒)`
` checkpoint_dir: “./.checkpoint” # 断点续传目录`
` scale_preset: large # 规模预设:small/medium/large/huge`
` `
`# ========== 运行配置 ==========`
`run: # 日志与运行控制`
` show_progress: true # 控制台进度`
` error_log_path: ./errors.log # 错误日志`
` enable_file_logging: true`
` log_file_path: ./conversion.log`
` show_console_logs: true`
` log_level: INFO # DEBUG/INFO/WARNING/ERROR`
**字段优先级与兼容说明:**
**`target.mode` 是 OceanBase 专属字段,可选 `mysql`(默认,路由到 MySQLTarget)或 `oracle`(路由到 OracleTarget)。其它目标库无需填写,填写也会被忽略。**
**`target.mode` 与 `target.extra.mode` 等价(顶层优先);老模板未升级时仍可读取 `extra.ob_tenant_mode` / `extra.driver` / `extra.compat_mode` 作为参考。**
**`source.type` 必须在 `SOURCE_FAMILIES` 内;`target.type` 必须在 `TARGET_FAMILIES` 内。使用 `python3 -m fgo2cdb version` 可查看支持的类型清单。**
**`sid` 与 `service_name` 二选一:Oracle/YashanDB 优先用 `service_name`,缺省时回退到 `sid`,再回退到 `database`。**
**`schema`:PG 系(KingbaseES/openGauss/GaussDB)与 Oracle 系(Oracle/YashanDB/OceanBase Oracle 模式)必填;MySQL 系(MySQL/TiDB/TDSQL/OceanBase MySQL 模式/GoldenDB)留空。**
**`consistent_snapshot: true` 推荐开启,可在长事务中保证读一致性,避免迁移过程中数据漂移。**
**`limits.scale_preset` 会按预设批量调整 `concurrency` / `batch_insert_size` / `parallel_tables`,手工设置的值优先级更高。**
**`conversion.options.validate_data` 默认开启,迁移完成后自动比对源/目标行数;不通过的表会在报告中列出。**
────────────────────────────────────────
## 五、程序各种案例场景与操作过程
### 5.1 场景一:Oracle → 达梦 DM8(金融核心系统国产化)
**背景:某银行核心系统从 Oracle 19c 迁移到达梦 DM8,数据量 2 TB,要求零停机窗口。**
**步骤:**
`# 1. 使用模板`
`cp templates/oracle_to_dm.yml bank_oracle_dm.yml`
`vi bank_oracle_dm.yml`
`# 修改 host/port/username/password/schema`
` `
`# 2. 迁移前评估(生成评估报告)`
`python3 -m fgo2cdb assess -c bank_oracle_dm.yml -o assess.html`
` `
`# 3. 先迁移表结构(预跑)`
`python3 -m fgo2cdb ddl -c bank_oracle_dm.yml -o ddl.sql`
`# 人工核对 DDL 后在 DM 执行`
` `
`# 4. 全量数据迁移`
`python3 -m fgo2cdb convert -c bank_oracle_dm.yml`
` `
`# 5. 数据校验`
`python3 -m fgo2cdb validate -c bank_oracle_dm.yml`
` `
`# 6. 生成迁移报告`
`python3 -m fgo2cdb report -c bank_oracle_dm.yml -o report.html`
**关键配置(`oracle_to_dm.yml`):**
`source:`
` type: oracle`
` host: 10.0.0.10`
` port: 1521`
` consistent_snapshot: true # 一致快照保证读一致性`
`target:`
` type: dm`
` host: 10.0.0.20`
` port: 5236`
`conversion:`
` limits:`
` concurrency: 8 # 8 表并发`
` batch_insert_size: 50000`
` scale_preset: large # 大规模预设`
### 5.2 场景二:MySQL → TiDB(互联网业务分布式改造)
**背景:电商业务从单机 MySQL 8.0 迁移到 TiDB 7.x 分布式集群,数据量 800 GB。**
`cp templates/mysql_to_tidb.yml shop_mysql_tidb.yml`
`vi shop_mysql_tidb.yml`
`# 修改连接信息`
` `
`# 评估`
`python3 -m fgo2cdb assess -c shop_mysql_tidb.yml`
` `
`# 全量迁移(TiDB 走 MySQL 协议,几乎无类型转换)`
`python3 -m fgo2cdb convert -c shop_mysql_tidb.yml`
` `
`# 校验`
`python3 -m fgo2cdb validate -c shop_mysql_tidb.yml`
**关键配置:**
`source:`
` type: mysql`
` charset: utf8mb4 # 4 字节字符支持`
` consistent_snapshot: true`
`target:`
` type: tidb`
` port: 4000`
` charset: utf8mb4`
` extra:`
` max_allowed_packet: 1073741824 # 1 GB 包大小`
### 5.3 场景三:可视化控制台操作 Oracle → KingbaseES
**步骤:**
`# 1. 启动控制台`
`python3 webctl.py start –port 8088 –daemon`
` `
`# 2. 浏览器访问 http://10.0.0.30:8088`
` `
`# 3. 在配置编辑页粘贴 oracle_to_kingbase.yml 模板,修改连接信息,点击「保存」`
` `
`# 4. 点击「测试连接」,确认源端 Oracle 与目标端 KingbaseES 均可连通`
` `
`# 5. 点击「迁移评估」,等待扫描完成,查看兼容性评分与风险清单`
` `
`# 6. 点击「启动迁移」,实时查看表级进度条、已迁移行数、速率`
` `
`# 7. 迁移完成后点击「查看报告」,下载 HTML 报告`
` `
`# 8. 停止控制台`
`python3 webctl.py stop`
### 5.4 场景四:PostgreSQL → openGauss(信创升级)
**背景:政务系统从 PostgreSQL 14 迁移到 openGauss 3.x(Oracle 兼容模式)。**
`cp templates/postgresql_to_opengauss.yml gov_pg_opengauss.yml`
`vi gov_pg_opengauss.yml`
` `
`python3 -m fgo2cdb convert -c gov_pg_opengauss.yml`
`python3 -m fgo2cdb validate -c gov_pg_opengauss.yml`
**关键配置:**
`target:`
` type: opengauss`
` extra:`
` db_compatibility: oracle # openGauss Oracle 兼容模式`
` pg_protocol: true # 走 PG 协议,可用 COPY 加速`
### 5.5 场景五:SQL Server → GaussDB DWS(数仓上云)
**背景:分析库从 SQL Server 2019 迁移到 GaussDB DWS(MPP 分布式数仓),数据量 3 TB。**
`cp templates/sqlserver_to_gaussdb.yml bi_mssql_gaussdb.yml`
`vi bi_mssql_gaussdb.yml`
` `
`python3 -m fgo2cdb convert -c bi_mssql_gaussdb.yml`
**关键配置:**
`target:`
` type: gaussdb`
` extra:`
` is_dws: true`
` distribution: hash # 哈希分布`
` pg_protocol: true # COPY 批量导入`
### 5.6 场景六:DB2 → 达梦 DM(保险核心改造)
**背景:保险核心库从 IBM DB2 迁移到达梦 DM8,数据量 1.2 TB。**
`cp templates/db2_to_dm.yml ins_db2_dm.yml`
`python3 -m fgo2cdb convert -c ins_db2_dm.yml`
`python3 -m fgo2cdb validate -c ins_db2_dm.yml`
`python3 -m fgo2cdb report -c ins_db2_dm.yml -o report.html`
### 5.7 场景七:MongoDB → 达梦 DM(文档库结构化)
**背景:日志库从 MongoDB 迁移到 DM8,集合 → 表,嵌套文档 → JSON 列。**
`cp templates/mongodb_to_dm.yml log_mongo_dm.yml`
`python3 -m fgo2cdb convert -c log_mongo_dm.yml`
**关键配置:**
`conversion:`
` options:`
` use_id_as_primary: true # _id 作为主键`
` nested_doc_strategy: json # 嵌套文档存为 JSON 列`
### 5.8 场景八:断点续传(大表迁移中断恢复)
**背景:迁移 5 TB 大表时网络抖动中断。**
`# 直接重跑同一命令,自动加载 checkpoint 跳过已完成表`
`python3 -m fgo2cdb convert -c big_table.yml`
`# 日志会显示:[checkpoint] 跳过已完成表 t_order (12345678 rows)`
### 5.9 场景九:Oracle → OceanBase(Oracle 模式,PL/SQL 直接迁移)
**背景:券商核心库从 Oracle 19c 迁移到 OceanBase 4.x Oracle 租户,要求存储过程/包/触发器原样保留,数据量 1.5 TB。**
**关键点:OceanBase 提供两种兼容模式——MySQL 模式与 Oracle 模式。本场景使用 Oracle 模式,程序会按 `target.mode: oracle` 路由到 OracleTarget,走 oracledb 协议,PL/SQL 几乎免改写。**
`# 1. 复制模板(已内置 mode: oracle)`
`cp templates/oracle_to_oceanbase.yml broker_oracle_ob.yml`
`vi broker_oracle_ob.yml`
`# 修改 host/port/username/password/service_name`
` `
`# 2. 评估对象兼容性`
`python3 -m fgo2cdb assess -c broker_oracle_ob.yml`
` `
`# 3. 导出 DDL 给 DBA 评审`
`python3 -m fgo2cdb ddl -c broker_oracle_ob.yml -o ddl.sql`
` `
`# 4. 全量迁移(含过程/触发器/序列)`
`python3 -m fgo2cdb convert -c broker_oracle_ob.yml`
` `
`# 5. 数据校验`
`python3 -m fgo2cdb validate -c broker_oracle_ob.yml`
**关键配置:**
`source:`
` type: oracle`
` host: 10.0.0.10`
` port: 1521`
` service_name: ORCL`
` schema: BROKER`
` consistent_snapshot: true`
`target:`
` type: oceanbase`
` mode: oracle # ★ OceanBase Oracle 兼容模式(路由到 OracleTarget)`
` host: 10.0.0.20`
` port: 2883 # OBProxy 端口`
` username: SYS`
` password: `
` schema: BROKER`
` charset: UTF8`
`conversion:`
` options:`
` procedures: true # OceanBase Oracle 模式支持 PL/SQL`
` triggers: true`
` sequences: true`
### 5.10 场景十:MySQL → OceanBase(MySQL 模式,电商库分布式改造)
**背景:电商业务库从单机 MySQL 8.0 迁移到 OceanBase 4.x MySQL 租户,数据量 600 GB,业务零改造。**
**关键点:使用 OceanBase MySQL 模式,程序按 `target.mode: mysql`(默认)路由到 MySQLTarget,走 PyMySQL 协议,类型/SQL 几乎无转换。**
`cp templates/mysql_to_oceanbase.yml shop_mysql_ob.yml`
`vi shop_mysql_ob.yml`
`python3 -m fgo2cdb assess -c shop_mysql_ob.yml`
`python3 -m fgo2cdb convert -c shop_mysql_ob.yml`
`python3 -m fgo2cdb validate -c shop_mysql_ob.yml`
**关键配置:**
`source:`
` type: mysql`
` host: 10.0.0.10`
` port: 3306`
` charset: utf8mb4`
` consistent_snapshot: true`
`target:`
` type: oceanbase`
` mode: mysql # ★ OceanBase MySQL 兼容模式(默认,可省略)`
` host: 10.0.0.20`
` port: 2881 # 直连端口;OBProxy 用 2883`
` username: root`
` password: `
` database: target_db`
` charset: utf8mb4`
### 5.11 场景十一:PostgreSQL → OceanBase(MySQL 模式,政务系统改造)
**背景:政务系统从 PostgreSQL 14 迁移到 OceanBase 4.x MySQL 租户,数据量 200 GB。**
`cp templates/postgresql_to_oceanbase.yml gov_pg_ob.yml`
`vi gov_pg_ob.yml`
`python3 -m fgo2cdb convert -c gov_pg_ob.yml`
`python3 -m fgo2cdb validate -c gov_pg_ob.yml`
**关键配置:**
`source:`
` type: postgresql`
` host: 10.0.0.10`
` port: 5432`
` schema: public`
`target:`
` type: oceanbase`
` mode: mysql # OceanBase MySQL 模式`
` host: 10.0.0.20`
` port: 2881`
` database: gov_db`
` charset: utf8mb4`
`conversion:`
` options:`
` lowercase_tables: true # PG 大小写敏感 -> OB 小写`
` lowercase_columns: true`
### 5.12 场景十二:SQL Server → OceanBase(MySQL 模式,ERP 改造)
**背景:制造企业 ERP 从 SQL Server 2019 迁移到 OceanBase 4.x MySQL 租户。**
`cp templates/sqlserver_to_oceanbase.yml erp_mssql_ob.yml`
`vi erp_mssql_ob.yml`
`python3 -m fgo2cdb convert -c erp_mssql_ob.yml`
**关键配置:**
`source:`
` type: sqlserver`
` host: 10.0.0.10`
` port: 1433`
` extra:`
` driver: “ODBC Driver 17 for SQL Server”`
` encrypt: false`
` trust_server_certificate: true`
`target:`
` type: oceanbase`
` mode: mysql`
` host: 10.0.0.20`
` port: 2881`
` database: erp_db`
### 5.13 场景十三:Oracle → YashanDB(信创 Oracle 平替)
**背景:某省级政务库从 Oracle 19c 迁移到崖山 YashanDB(Oracle 协议兼容),存储过程/触发器原样保留。**
`cp templates/oracle_to_yashandb.yml gov_oracle_yashan.yml`
`vi gov_oracle_yashan.yml`
`python3 -m fgo2cdb ddl -c gov_oracle_yashan.yml -o ddl.sql # 评审 DDL`
`python3 -m fgo2cdb convert -c gov_oracle_yashan.yml`
`python3 -m fgo2cdb validate -c gov_oracle_yashan.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: GOV`
` consistent_snapshot: true`
`target:`
` type: yashandb`
` host: 10.0.0.20`
` port: 1688`
` username: SYS`
` schema: GOV`
` charset: UTF8`
`conversion:`
` options:`
` procedures: true`
` triggers: true`
` sequences: true`
### 5.14 场景十四:MySQL → GoldenDB(金融分布式改造)
**背景:城商行核心库从 MySQL 5.7 迁移到 GoldenDB 分布式集群,数据量 1.8 TB。**
`cp templates/mysql_to_goldendb.yml bank_mysql_gdb.yml`
`vi bank_mysql_gdb.yml`
`python3 -m fgo2cdb convert -c bank_mysql_gdb.yml`
**关键配置:**
`source:`
` type: mysql`
` charset: utf8mb4`
` consistent_snapshot: true`
`target:`
` type: goldendb`
` host: 10.0.0.20`
` port: 3306 # GoldenDB 兼容 MySQL 协议`
` database: target_db`
`conversion:`
` limits:`
` concurrency: 8`
` batch_insert_size: 50000`
### 5.15 场景十五:MySQL → GBase 8s(政企分析库改造)
**背景:电信分析库从 MySQL 8.0 迁移到 GBase 8s,数据量 400 GB。**
`cp templates/mysql_to_gbase.yml tel_mysql_gbase.yml`
`vi tel_mysql_gbase.yml`
`python3 -m fgo2cdb convert -c tel_mysql_gbase.yml`
`python3 -m fgo2cdb validate -c tel_mysql_gbase.yml`
**关键配置:**
`source:`
` type: mysql`
` host: 10.0.0.10`
` port: 3306`
`target:`
` type: gbase`
` host: 10.0.0.20`
` port: 5258`
` database: target_db`
### 5.16 场景十六:DB2 → KingbaseES(保险核心信创替代)
**背景:保险核心库从 IBM DB2 11.5 迁移到金仓 KingbaseES V8(PG 兼容),数据量 900 GB。**
`cp templates/db2_to_kingbase.yml ins_db2_king.yml`
`vi ins_db2_king.yml`
`python3 -m fgo2cdb assess -c ins_db2_king.yml`
`python3 -m fgo2cdb convert -c ins_db2_king.yml`
`python3 -m fgo2cdb report -c ins_db2_king.yml -o report.html`
**关键配置:**
`source:`
` type: db2`
` host: 10.0.0.10`
` port: 50000`
` database: INSDB`
` schema: INS`
`target:`
` type: kingbase`
` host: 10.0.0.20`
` port: 54321`
` schema: ins`
`conversion:`
` limits:`
` parallel_tables: 6`
` batch_insert_size: 50000`
### 5.17 场景十七:MongoDB → KingbaseES(文档库结构化)
**背景:日志库从 MongoDB 5.0 迁移到 KingbaseES,集合 → 表,嵌套文档 → JSONB 列。**
`cp templates/mongodb_to_kingbase.yml log_mongo_king.yml`
`python3 -m fgo2cdb convert -c log_mongo_king.yml`
**关键配置:**
`conversion:`
` options:`
` use_id_as_primary: true # _id 作为主键`
` nested_doc_strategy: jsonb # 嵌套文档存为 JSONB 列`
### 5.18 场景十八:Redis → KingbaseES(缓存数据落库)
**背景:缓存数据从 Redis 迁移到 KingbaseES,KV → 两列表(key/value)。**
`cp templates/redis_to_kingbase.yml cache_redis_king.yml`
`python3 -m fgo2cdb convert -c cache_redis_king.yml`
### 5.19 场景十九:Oracle → KingbaseES V9 Oracle 兼容版(PL/SQL 平替)
**背景:某省级公积金系统从 Oracle 19c 迁移到金仓 KingbaseES V9R2C14 Oracle 兼容版,要求存储过程/包/触发器原样保留,数据量 1.2 TB。**
**关键点:KingbaseES V9 提供 Oracle/MySQL/SQL Server/PG 四种兼容模式,V9R2C14 为 Oracle 兼容版(默认 Oracle 模式)。程序按 `target.mode: oracle` 路由到 OracleTarget,走 Oracle 协议,PL/SQL 几乎免改写。**
`cp templates/oracle_to_kingbase.yml gov_oracle_kingv9.yml`
`vi gov_oracle_kingv9.yml`
`# 修改 host/port/username/password/schema`
` `
`python3 -m fgo2cdb assess -c gov_oracle_kingv9.yml`
`python3 -m fgo2cdb ddl -c gov_oracle_kingv9.yml -o ddl.sql`
`python3 -m fgo2cdb convert -c gov_oracle_kingv9.yml`
`python3 -m fgo2cdb validate -c gov_oracle_kingv9.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: HOUSING_FUND`
` consistent_snapshot: true`
`target:`
` type: kingbase`
` mode: oracle # ★ KingbaseES V9 Oracle 兼容模式`
` host: 10.0.0.20`
` port: 54321`
` schema: housing_fund`
` extra:`
` compatible_mode: oracle # 对应 kingbase.conf 的 sql_compatibility`
`conversion:`
` options:`
` procedures: true # 存储过程/包/触发器原样迁移`
` triggers: true`
` sequences: true`
### 5.20 场景二十:MySQL → KingbaseES V9 MySQL 兼容版(电商库改造)
**背景:电商平台从 MySQL 8.0 迁移到金仓 KingbaseES V9R3C18 MySQL 兼容版,数据量 500 GB。**
**关键点:V9R3C18 为 MySQL 兼容版,程序按 `target.mode: mysql` 路由到 MySQLTarget,走 PyMySQL 协议,SQL 方言几乎无转换。**
`cp templates/mysql_to_kingbase.yml shop_mysql_kingv9.yml`
`vi shop_mysql_kingv9.yml`
`python3 -m fgo2cdb convert -c shop_mysql_kingv9.yml`
`python3 -m fgo2cdb validate -c shop_mysql_kingv9.yml`
**关键配置:**
`source:`
` type: mysql`
` host: 10.0.0.10`
` port: 3306`
` charset: utf8mb4`
` consistent_snapshot: true`
`target:`
` type: kingbase`
` mode: mysql # ★ KingbaseES V9 MySQL 兼容模式`
` host: 10.0.0.20`
` port: 54321`
` database: shop_db`
` charset: utf8mb4`
` extra:`
` compatible_mode: mysql`
### 5.21 场景二十一:SQL Server → KingbaseES V9 SQL Server 兼容版(ERP 改造)
**背景:制造企业 ERP 从 SQL Server 2019 迁移到金仓 KingbaseES V9R4C19 SQL Server 兼容版,数据量 300 GB。**
**关键点:V9R4C19 为 SQL Server 兼容版,程序按 `target.mode: sqlserver` 路由,T-SQL 语法近乎原样保留。**
`cp templates/sqlserver_to_kingbase.yml erp_mssql_kingv9.yml`
`vi erp_mssql_kingv9.yml`
`python3 -m fgo2cdb convert -c erp_mssql_kingv9.yml`
`python3 -m fgo2cdb validate -c erp_mssql_kingv9.yml`
**关键配置:**
`source:`
` type: sqlserver`
` host: 10.0.0.10`
` port: 1433`
` extra:`
` driver: “ODBC Driver 17 for SQL Server”`
`target:`
` type: kingbase`
` mode: sqlserver # ★ KingbaseES V9 SQL Server 兼容模式`
` host: 10.0.0.20`
` port: 54321`
` database: erp_db`
` extra:`
` compatible_mode: sqlserver`
### 5.22 场景二十二:Oracle → openGauss Oracle 兼容模式(政务信创)
**背景:某市级政务大厅从 Oracle 19c 迁移到 openGauss 6.0 LTS(Oracle 兼容模式 A),数据量 800 GB。**
**关键点:openGauss 通过 `CREATE DATABASE DBCOMPATIBILITY=’A’` 设置 Oracle 兼容模式。程序按 `target.mode: A`(或 `oracle`)路由到 OracleTarget。**
`cp templates/oracle_to_opengauss.yml gov_oracle_og.yml`
`vi gov_oracle_og.yml`
`python3 -m fgo2cdb assess -c gov_oracle_og.yml`
`python3 -m fgo2cdb ddl -c gov_oracle_og.yml -o ddl.sql`
`python3 -m fgo2cdb convert -c gov_oracle_og.yml`
`python3 -m fgo2cdb validate -c gov_oracle_og.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: GOV`
` consistent_snapshot: true`
`target:`
` type: opengauss`
` mode: A # ★ openGauss Oracle 兼容模式(DBCOMPATIBILITY=’A’)`
` host: 10.0.0.20`
` port: 5432`
` schema: gov`
` extra:`
` db_compatibility: A`
`conversion:`
` options:`
` procedures: true`
` triggers: true`
### 5.23 场景二十三:MySQL → openGauss MySQL 兼容模式(互联网改造)
**背景:SaaS 业务从 MySQL 8.0 迁移到 openGauss 6.0(MySQL 兼容模式 B,需安装 dolphin 插件),数据量 200 GB。**
**关键点:openGauss 通过 `DBCOMPATIBILITY=’B’` 设置 MySQL 兼容模式,需安装 dolphin 扩展插件。程序按 `target.mode: B`(或 `mysql`)路由到 MySQLTarget。**
`cp templates/mysql_to_opengauss.yml saas_mysql_og.yml`
`vi saas_mysql_og.yml`
`python3 -m fgo2cdb convert -c saas_mysql_og.yml`
`python3 -m fgo2cdb validate -c saas_mysql_og.yml`
**关键配置:**
`source:`
` type: mysql`
` charset: utf8mb4`
` consistent_snapshot: true`
`target:`
` type: opengauss`
` mode: B # ★ openGauss MySQL 兼容模式(需 dolphin 插件)`
` host: 10.0.0.20`
` port: 5432`
` database: saas_db`
` charset: utf8mb4`
` extra:`
` db_compatibility: B`
` extension: dolphin`
### 5.24 场景二十四:Oracle → GaussDB TPOPS 集中式版(OLTP 信创)
**背景:某股份制银行核心库从 Oracle 19c 迁移到 GaussDB V2.0-8.x 集中式版(TPOPS 部署),Oracle 兼容模式,数据量 2 TB。**
**关键点:GaussDB 集中式版面向 OLTP 场景,通过 TPOPS(云数据库 GaussDB 管理平台)部署。程序按 `target.mode: oracle` 路由到 OracleTarget。**
`cp templates/oracle_to_gaussdb.yml bank_oracle_gauss.yml`
`vi bank_oracle_gauss.yml`
`python3 -m fgo2cdb assess -c bank_oracle_gauss.yml`
`python3 -m fgo2cdb ddl -c bank_oracle_gauss.yml -o ddl.sql`
`python3 -m fgo2cdb convert -c bank_oracle_gauss.yml`
`python3 -m fgo2cdb validate -c bank_oracle_gauss.yml`
`python3 -m fgo2cdb report -c bank_oracle_gauss.yml -o report.html`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: CORE`
` consistent_snapshot: true`
`target:`
` type: gaussdb`
` mode: oracle # ★ GaussDB Oracle 兼容模式`
` host: 10.0.0.20`
` port: 5432`
` schema: core`
` extra:`
` deployment: tpops # TPOPS 部署`
` architecture: centralized # 集中式版`
` db_compatibility: A`
`conversion:`
` options:`
` procedures: true`
` triggers: true`
` sequences: true`
` limits:`
` concurrency: 8`
` batch_insert_size: 50000`
` scale_preset: large`
### 5.25 场景二十五:MySQL → GaussDB TPOPS 分布式版(HTAP 场景)
**背景:社交平台从 MySQL 8.0 迁移到 GaussDB V2.0-8.x 分布式版(TPOPS 部署),MySQL 兼容模式,数据量 1.5 TB。**
**关键点:GaussDB 分布式版面向 HTAP 场景,通过 TPOPS 部署。程序按 `target.mode: mysql` 路由到 MySQLTarget。**
`cp templates/mysql_to_gaussdb.yml social_mysql_gauss.yml`
`vi social_mysql_gauss.yml`
`python3 -m fgo2cdb convert -c social_mysql_gauss.yml`
`python3 -m fgo2cdb validate -c social_mysql_gauss.yml`
**关键配置:**
`source:`
` type: mysql`
` charset: utf8mb4`
` consistent_snapshot: true`
`target:`
` type: gaussdb`
` mode: mysql # ★ GaussDB MySQL 兼容模式`
` host: 10.0.0.20`
` port: 5432`
` database: social_db`
` extra:`
` deployment: tpops # TPOPS 部署`
` architecture: distributed # 分布式版`
` db_compatibility: B`
### 5.26 场景二十六:PostgreSQL → GaussDB DWS(数仓迁移)
**背景:企业数据仓库从 PostgreSQL 14 迁移到 GaussDB(DWS) 8.x OLAP 数仓服务,数据量 4 TB。**
**关键点:DWS(Data Warehouse Service)为 MPP 架构数仓,程序按 `target.mode: pg`(默认)路由到 PostgresTarget,走 COPY 批量导入。**
`cp templates/postgresql_to_gaussdb.yml dw_pg_dws.yml`
`vi dw_pg_dws.yml`
`python3 -m fgo2cdb convert -c dw_pg_dws.yml`
`python3 -m fgo2cdb validate -c dw_pg_dws.yml`
**关键配置:**
`source:`
` type: postgresql`
` host: 10.0.0.10`
` port: 5432`
` schema: public`
`target:`
` type: gaussdb`
` mode: pg # ★ GaussDB PG 兼容模式(DWS 默认)`
` host: 10.0.0.20`
` port: 5432`
` schema: public`
` extra:`
` is_dws: true # ★ DWS 数仓服务`
` distribution: hash # 哈希分布`
` pg_protocol: true # COPY 批量导入`
`conversion:`
` limits:`
` batch_insert_size: 100000`
` scale_preset: xlarge`
### 5.27 场景二十七:Oracle → DM8(政务大表迁移)
**背景:某省级税务系统从 Oracle 19c 迁移到 DM8.1,核心大表 5 亿行,数据量 1.5 TB。**
`cp templates/oracle_to_dm.yml tax_oracle_dm.yml`
`vi tax_oracle_dm.yml`
`python3 -m fgo2cdb assess -c tax_oracle_dm.yml`
`python3 -m fgo2cdb convert -c tax_oracle_dm.yml`
`python3 -m fgo2cdb validate -c tax_oracle_dm.yml`
`python3 -m fgo2cdb report -c tax_oracle_dm.yml -o report.html`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: TAX`
` consistent_snapshot: true`
`target:`
` type: dm`
` host: 10.0.0.20`
` port: 5236`
` schema: tax`
`conversion:`
` limits:`
` concurrency: 16`
` batch_insert_size: 100000`
` scale_preset: large`
### 5.28 场景二十八:MySQL → DM8(中小型业务库迁移)
**背景:OA 系统从 MySQL 5.7 迁移到 DM8.1,数据量 50 GB。**
`cp templates/mysql_to_dm.yml oa_mysql_dm.yml`
`vi oa_mysql_dm.yml`
`python3 -m fgo2cdb convert -c oa_mysql_dm.yml`
`python3 -m fgo2cdb validate -c oa_mysql_dm.yml`
**关键配置:**
`source:`
` type: mysql`
` host: 10.0.0.10`
` port: 3306`
` charset: utf8mb4`
`target:`
` type: dm`
` host: 10.0.0.20`
` port: 5236`
` database: oa_db`
### 5.29 场景二十九:PostgreSQL → DM8(PG 库信创替代)
**背景:物联网平台从 PostgreSQL 15 迁移到 DM8.2,数据量 300 GB。**
`cp templates/postgresql_to_dm.yml iot_pg_dm.yml`
`vi iot_pg_dm.yml`
`python3 -m fgo2cdb convert -c iot_pg_dm.yml`
`python3 -m fgo2cdb validate -c iot_pg_dm.yml`
**关键配置:**
`source:`
` type: postgresql`
` host: 10.0.0.10`
` port: 5432`
` schema: iot`
`target:`
` type: dm`
` host: 10.0.0.20`
` port: 5236`
` schema: iot`
`conversion:`
` options:`
` lowercase_tables: true`
` lowercase_columns: true`
### 5.30 场景三十:SQL Server → DM8(制造 ERP 迁移)
**背景:制造企业 ERP 从 SQL Server 2019 迁移到 DM8.1,数据量 200 GB。**
`cp templates/sqlserver_to_dm.yml erp_mssql_dm.yml`
`vi erp_mssql_dm.yml`
`python3 -m fgo2cdb convert -c erp_mssql_dm.yml`
`python3 -m fgo2cdb validate -c erp_mssql_dm.yml`
**关键配置:**
`source:`
` type: sqlserver`
` host: 10.0.0.10`
` port: 1433`
` extra:`
` driver: “ODBC Driver 17 for SQL Server”`
` encrypt: false`
` trust_server_certificate: true`
`target:`
` type: dm`
` host: 10.0.0.20`
` port: 5236`
` database: erp_db`
### 5.31 场景三十一:Oracle → TiDB(HTAP 分布式改造)
**背景:保险理赔库从 Oracle 19c 迁移到 TiDB 7.x,利用 TiKV + TiFlash 实现 HTAP,数据量 1 TB。**
`cp templates/oracle_to_tidb.yml ins_oracle_tidb.yml`
`vi ins_oracle_tidb.yml`
`python3 -m fgo2cdb assess -c ins_oracle_tidb.yml`
`python3 -m fgo2cdb convert -c ins_oracle_tidb.yml`
`python3 -m fgo2cdb validate -c ins_oracle_tidb.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: CLAIM`
` consistent_snapshot: true`
`target:`
` type: tidb`
` host: 10.0.0.20`
` port: 4000`
` database: claim_db`
` charset: utf8mb4`
` extra:`
` max_allowed_packet: 1073741824`
### 5.32 场景三十二:PostgreSQL → TiDB(互联网库分布式迁移)
**背景:内容平台从 PostgreSQL 14 迁移到 TiDB 8.x,数据量 400 GB。**
`cp templates/postgresql_to_tidb.yml content_pg_tidb.yml`
`vi content_pg_tidb.yml`
`python3 -m fgo2cdb convert -c content_pg_tidb.yml`
`python3 -m fgo2cdb validate -c content_pg_tidb.yml`
**关键配置:**
`source:`
` type: postgresql`
` host: 10.0.0.10`
` port: 5432`
` schema: content`
`target:`
` type: tidb`
` host: 10.0.0.20`
` port: 4000`
` database: content_db`
` charset: utf8mb4`
`conversion:`
` options:`
` lowercase_tables: true`
` lowercase_columns: true`
### 5.33 场景三十三:SQL Server → TiDB(零售系统分布式改造)
**背景:连锁零售 POS 系统从 SQL Server 2019 迁移到 TiDB 7.x,数据量 600 GB。**
`cp templates/sqlserver_to_tidb.yml retail_mssql_tidb.yml`
`vi retail_mssql_tidb.yml`
`python3 -m fgo2cdb convert -c retail_mssql_tidb.yml`
`python3 -m fgo2cdb validate -c retail_mssql_tidb.yml`
**关键配置:**
`source:`
` type: sqlserver`
` host: 10.0.0.10`
` port: 1433`
` extra:`
` driver: “ODBC Driver 17 for SQL Server”`
`target:`
` type: tidb`
` host: 10.0.0.20`
` port: 4000`
` database: retail_db`
` charset: utf8mb4`
### 5.34 场景三十四:DB2 → TiDB(保险历史库迁移)
**背景:保险历史保单库从 IBM DB2 11.5 迁移到 TiDB 7.x,数据量 800 GB。**
`cp templates/db2_to_tidb.yml ins_db2_tidb.yml`
`vi ins_db2_tidb.yml`
`python3 -m fgo2cdb convert -c ins_db2_tidb.yml`
`python3 -m fgo2cdb validate -c ins_db2_tidb.yml`
**关键配置:**
`source:`
` type: db2`
` host: 10.0.0.10`
` port: 50000`
` database: POLICY`
` schema: HISTORY`
`target:`
` type: tidb`
` host: 10.0.0.20`
` port: 4000`
` database: policy_db`
` charset: utf8mb4`
### 5.35 场景三十五:MongoDB → TiDB(文档库结构化迁移)
**背景:用户行为日志从 MongoDB 6.0 迁移到 TiDB 8.x,集合 → 表,嵌套文档 → JSON 列。**
`cp templates/mongodb_to_tidb.yml behavior_mongo_tidb.yml`
`vi behavior_mongo_tidb.yml`
`python3 -m fgo2cdb convert -c behavior_mongo_tidb.yml`
**关键配置:**
`conversion:`
` options:`
` use_id_as_primary: true`
` nested_doc_strategy: json`
### 5.36 场景三十六:Oracle → GBase 8s(信创分析库迁移)
**背景:企业报表库从 Oracle 19c 迁移到 GBase 8s,数据量 500 GB。**
`cp templates/oracle_to_gbase.yml rpt_oracle_gbase.yml`
`vi rpt_oracle_gbase.yml`
`python3 -m fgo2cdb convert -c rpt_oracle_gbase.yml`
`python3 -m fgo2cdb validate -c rpt_oracle_gbase.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: REPORT`
` consistent_snapshot: true`
`target:`
` type: gbase`
` host: 10.0.0.20`
` port: 5258`
` database: report_db`
### 5.37 场景三十七:Oracle → GoldenDB(银行核心分布式迁移)
**背景:农商行核心库从 Oracle 19c 迁移到 GoldenDB 8.x 分布式集群,数据量 1.2 TB。**
`cp templates/oracle_to_goldendb.yml bank_oracle_gdb.yml`
`vi bank_oracle_gdb.yml`
`python3 -m fgo2cdb assess -c bank_oracle_gdb.yml`
`python3 -m fgo2cdb convert -c bank_oracle_gdb.yml`
`python3 -m fgo2cdb validate -c bank_oracle_gdb.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: CORE`
` consistent_snapshot: true`
`target:`
` type: goldendb`
` host: 10.0.0.20`
` port: 3306`
` database: core_db`
`conversion:`
` limits:`
` concurrency: 8`
` batch_insert_size: 50000`
### 5.38 场景三十八:Oracle → TDSQL-C(金融 MySQL 协议迁移)
**背景:支付系统从 Oracle 19c 迁移到 TDSQL-C MySQL 8.0 版,数据量 600 GB。**
`cp templates/oracle_to_tdsql.yml pay_oracle_tdsql.yml`
`vi pay_oracle_tdsql.yml`
`python3 -m fgo2cdb convert -c pay_oracle_tdsql.yml`
`python3 -m fgo2cdb validate -c pay_oracle_tdsql.yml`
**关键配置:**
`source:`
` type: oracle`
` service_name: ORCL`
` schema: PAY`
` consistent_snapshot: true`
`target:`
` type: tdsql`
` host: 10.0.0.20`
` port: 3306`
` database: pay_db`
` charset: utf8mb4`
` extra:`
` engine: mysql # TDSQL-C MySQL 版`
### 5.39 场景三十九:MySQL → TDSQL-C PostgreSQL 版(PG 协议迁移)
**背景:SaaS 平台从 MySQL 8.0 迁移到 TDSQL-C PostgreSQL 15 版,利用 PG 生态工具链,数据量 300 GB。**
`cp templates/mysql_to_tdsql.yml saas_mysql_tdsql.yml`
`vi saas_mysql_tdsql.yml`
`python3 -m fgo2cdb convert -c saas_mysql_tdsql.yml`
`python3 -m fgo2cdb validate -c saas_mysql_tdsql.yml`
**关键配置:**
`source:`
` type: mysql`
` charset: utf8mb4`
` consistent_snapshot: true`
`target:`
` type: tdsql`
` host: 10.0.0.20`
` port: 5432 # PG 协议端口`
` database: saas_db`
` extra:`
` engine: postgresql # TDSQL-C PostgreSQL 版`
### 5.40 场景四十:MySQL → YashanDB(信创 MySQL 协议平替)
**背景:中小企业 ERP 从 MySQL 8.0 迁移到 YashanDB 23.x,数据量 150 GB。**
`cp templates/mysql_to_yashandb.yml erp_mysql_yashan.yml`
`vi erp_mysql_yashan.yml`
`python3 -m fgo2cdb convert -c erp_mysql_yashan.yml`
`python3 -m fgo2cdb validate -c erp_mysql_yashan.yml`
**关键配置:**
`source:`
` type: mysql`
` host: 10.0.0.10`
` port: 3306`
` charset: utf8mb4`
`target:`
` type: yashandb`
` host: 10.0.0.20`
` port: 1688`
` database: erp_db`
### 5.41 场景四十一:PostgreSQL → KingbaseES(PG 原生迁移)
**背景:能源监控系统从 PostgreSQL 16 迁移到 KingbaseES V9 PG 兼容模式,数据量 350 GB。**
`cp templates/postgresql_to_kingbase.yml energy_pg_king.yml`
`vi energy_pg_king.yml`
`python3 -m fgo2cdb convert -c energy_pg_king.yml`
`python3 -m fgo2cdb validate -c energy_pg_king.yml`
**关键配置:**
`source:`
` type: postgresql`
` host: 10.0.0.10`
` port: 5432`
` schema: monitor`
`target:`
` type: kingbase`
` mode: pg # ★ KingbaseES V9 PG 兼容模式(默认)`
` host: 10.0.0.20`
` port: 54321`
` schema: monitor`
` extra:`
` compatible_mode: pg`
### 5.42 场景四十二:PostgreSQL → YashanDB(PG 库信创替代)
**背景:物流系统从 PostgreSQL 14 迁移到 YashanDB 23.x,数据量 200 GB。**
`cp templates/postgresql_to_yashandb.yml logistics_pg_yashan.yml`
`vi logistics_pg_yashan.yml`
`python3 -m fgo2cdb convert -c logistics_pg_yashan.yml`
`python3 -m fgo2cdb validate -c logistics_pg_yashan.yml`
**关键配置:**
`source:`
` type: postgresql`
` host: 10.0.0.10`
` port: 5432`
` schema: logistics`
`target:`
` type: yashandb`
` host: 10.0.0.20`
` port: 1688`
` database: logistics_db`
### 5.43 场景四十三:DB2 → GaussDB DWS(数仓迁移)
**背景:保险分析库从 IBM DB2 11.5 迁移到 GaussDB(DWS) 8.x OLAP 数仓,数据量 2.5 TB。**
`cp templates/db2_to_gaussdb.yml ins_db2_dws.yml`
`vi ins_db2_dws.yml`
`python3 -m fgo2cdb convert -c ins_db2_dws.yml`
`python3 -m fgo2cdb validate -c ins_db2_dws.yml`
**关键配置:**
`source:`
` type: db2`
` host: 10.0.0.10`
` port: 50000`
` database: ANA`
` schema: REPORT`
`target:`
` type: gaussdb`
` mode: pg`
` host: 10.0.0.20`
` port: 5432`
` schema: report`
` extra:`
` is_dws: true`
` distribution: hash`
` pg_protocol: true`
`conversion:`
` limits:`
` batch_insert_size: 100000`
` scale_preset: xlarge`
### 5.44 场景四十四:SQL Server → KingbaseES(ERP 信创改造)
**背景:制造企业 MES 从 SQL Server 2019 迁移到 KingbaseES V9 通用版(PG 兼容),数据量 250 GB。**
`cp templates/sqlserver_to_kingbase.yml mes_mssql_king.yml`
`vi mes_mssql_king.yml`
`python3 -m fgo2cdb convert -c mes_mssql_king.yml`
`python3 -m fgo2cdb validate -c mes_mssql_king.yml`
**关键配置:**
`source:`
` type: sqlserver`
` host: 10.0.0.10`
` port: 1433`
` extra:`
` driver: “ODBC Driver 17 for SQL Server”`
`target:`
` type: kingbase`
` mode: pg # KingbaseES V9 通用版 PG 兼容`
` host: 10.0.0.20`
` port: 54321`
` database: mes_db`
` extra:`
` compatible_mode: pg`
### 5.45 场景四十五:可视化控制台暂停与恢复迁移
**背景:迁移 3 TB 大库时业务高峰来临,需要暂停迁移释放目标端资源,业务低峰再恢复。**
**操作步骤:**
`# 1. 启动控制台并启动迁移`
`python3 webctl.py start –port 8088 –daemon`
`# 浏览器访问 http://10.0.0.30:8088,点击「启动迁移」`
` `
`# 2. 业务高峰来临,点击「暂停迁移」`
`# 系统在当前批次完成后阻塞,不退出迁移线程`
` `
`# 3. 业务低峰,点击「继续迁移」恢复`
`# 系统清除暂停标志,从断点继续`
` `
`# 4. 紧急情况点击「停止迁移」终止`
`# 已迁移数据保留,下次重跑自动跳过已完成表`
**关键说明:**
**暂停迁移:当前批次写完后阻塞,不退出线程,目标端连接保持**
**继续迁移:清除暂停标志并唤醒阻塞线程,从断点继续**
**停止迁移:终止当前迁移,已迁移数据保留,下次重跑自动跳过已完成表**
**暂停期间可通过 SSE 实时查看已迁移行数与进度**
────────────────────────────────────────
## 5.56 场景五十六:Oracle → OceanBase(Oracle) 独立目标类型(PL/SQL 平替)
背景:某银行核心库从 Oracle 19c 迁移到 OceanBase 4.x Oracle 兼容租户,PL/SQL 存储过程直接平替,配置时希望以独立目标类型显式声明 Oracle 兼容模式,避免与 MySQL 模式混淆。**操作步骤:**`# 1. 复制 Oracle → OceanBase(Oracle) 模板“cp templates/oracle_to_oceanbase.yml config.yml“# 2. 修改 target.type 为 oceanbase_oracle(独立类型,无需 mode 切换)“# target:“# type: oceanbase_oracle # 独立目标类型:直接路由到 OracleTarget“# host: 10.0.0.20“# port: 2883 # OBProxy Oracle 模式端口“# schema: SCOTT # Oracle 系 schema 必填“# 3. 执行完整迁移“python3 -m fgo2cdb migrate -c config.yml“# 4. 校验数据一致性“python3 -m fgo2cdb validate -c config.yml`**关键说明:**• oceanbase_oracle 是独立目标类型,族 = oracle,无需 target.mode 切换• 相比 type: oceanbase + mode: oracle 写法,独立类型配置语义更清晰• 走 OracleTarget + oracledb 协议,PL/SQL 存储过程/函数/包/触发器原样保留• 端口默认 2883(OBProxy Oracle 模式),直连端口仍可用 2881• 失败对象登记到 result[“manual_fix”] 供人工处理
## 5.57 场景五十七:Percona → OceanBase(Oracle) 独立类型(Percona OLTP 转 OB 分布式 OLAP)
背景:某电商客户 Percona Server for MySQL 8.0 的 OLTP 业务库,需要将历史分析数据迁移到 OceanBase 4.x Oracle 兼容租户做分布式 OLAP 分析。**操作步骤:**`# 1. 复制 Percona → OceanBase 模板并改 target.type 为 oceanbase_oracle“cp templates/percona_to_oceanbase.yml config.yml“# 2. 修改源端 Percona 和目标端 OceanBase(Oracle)“# source: { type: percona, host: 10.0.0.10, port: 3306 }“# target:“# type: oceanbase_oracle # 独立 Oracle 模式类型“# host: 10.0.0.20“# port: 2883“# schema: ANALYTICS“# 3. 迁移 + 校验“python3 -m fgo2cdb migrate -c config.yml && python3 -m fgo2cdb validate -c config.yml`**关键说明:**• 源端 Percona 自动路由到 MySQLSource(族 mysql)• 目标端 oceanbase_oracle 自动路由到 OracleTarget(族 oracle)• 跨族转换:MySQL IFNULL/DATE_FORMAT/GROUP_CONCAT 自动重写为 Oracle NVL/TO_CHAR/LISTAGG• 全链路 UTF-8 强制,emoji 与中文不乱码• 大表通过流式游标 + 批量 INSERT 写入,支持断点续传5.58 场景五十八:可视化控制台选择 OceanBase(Oracle) / GreatSQL / GaussDB(DWS/TPOPS)背景:运维人员通过 Web 控制台完成 Percona → OceanBase(Oracle)、MySQL → GreatSQL、Oracle → GaussDB(DWS) 三种新目标类型的迁移任务,需熟悉下拉框选项与兼容模式切换。**操作步骤:**`# 1. 启动可视化控制台“python3 -m fgo2cdb web -H 0.0.0.0 -p 8088“# 浏览器访问 http://10.0.0.30:8088`**目标端下拉框新增选项(用户友好标签):**• OceanBase (MySQL) — value=oceanbase,路由 MySQLTarget• OceanBase (Oracle) — value=oceanbase_oracle,路由 OracleTarget(独立类型,无需 mode 切换)• GreatSQL (MySQL) — value=greatsql,路由 MySQLTarget(万里数据库,MGR 集群)• GaussDB (DWS) — value=gaussdb_dws,路由 PostgresTarget(数仓服务 OLAP)• GaussDB (TPOPS) — value=gaussdb_tpops,路由 PostgresTarget(集中式 + 分布式 HTAP)• GaussDB (TPOPS) — value=gaussdb,旧别名,等同 gaussdb_tpops**关键说明:**• 源端下拉框新增 Percona (MySQL) 选项,value=percona,自动路由到 MySQLSource• 多模式国产库选中后自动显示「兼容模式」二级下拉框• OceanBase (Oracle) 作为独立类型,无需二级兼容模式选择,配置更简洁• 端口自动填充:OceanBase(Oracle)→2883,GreatSQL→3306,GaussDB(DWS/TPOPS)→25308• 表单点击「启动迁移」后通过 SSE 实时显示行数、速率、阶段进度六、常用问题与排查
### 6.1 连接问题
| 现象 | 原因 | 排查 |
| — | — | — |
| 源端连接超时 | 网络/防火墙 | `telnet <host> <port>` 测试端口 |
| Oracle ORA-12541 | 监听未启动 | 检查 `lsnrctl status` |
| DM 连接失败 | 默认端口 5236 | 确认 `disql SYSDBA/SYSDBA001@localhost:5236` |
| SQL Server SSL 错误 | ODBC 驱动加密 | 配置 `encrypt: false, trust_server_certificate: true` |
| MongoDB auth 失败 | 认证库不对 | 检查 `auth_source: admin` |
| Redis 权限错误 | 需要密码 | 配置 `password` 字段 |
### 6.2 编码乱码问题
| 现象 | 原因 | 解决 |
| — | — | — |
| 中文变 ? | 源端 charset 不对 | 源端配置 `charset: utf8mb4`(MySQL)/ `UTF8`(Oracle) |
| emoji 丢失 | MySQL 用 utf8 而非 utf8mb4 | 改为 `utf8mb4` |
| 目标端乱码 | 目标库字符集不对 | 目标端 `charset: UTF-8` / `UTF8` |
| COPY 模式报错 | 含制表符/换行 | 工具已自动转义 `\t \n \\ \N`,检查是否禁用了 streaming_cursor |
### 6.3 性能问题
| 现象 | 原因 | 解决 |
| — | — | — |
| 迁移速度慢 | 并发太低 | 提高 `concurrency: 10-16` |
| 单表慢 | fetch_size 太小 | `fetch_size: 10000-50000` |
| 目标写入慢 | 未用 COPY | PG 系目标确保 `streaming_cursor: true` |
| 内存爆 | queue 太大 | 降 `queue_size: 2`,设 `memory_hard_limit_mb` |
| 源端 CPU 100% | 全表扫描 | 源端加索引或分批迁移 |
| 大表卡死 | 无主键无法分批 | 评估阶段已提示,需人工指定分布键 |
### 6.4 数据一致性问题
| 现象 | 原因 | 解决 |
| — | — | — |
| 行数不一致 | 源端有写入 | 开启 `consistent_snapshot: true` |
| 抽样比对失败 | 浮点精度 | 工具已按类型容差比对,检查 NUMBER/FLOAT 精度 |
| 大字段丢失 | BLOB 未直传 | 检查目标端是否用 BLOB/CLOB 接收 |
| 序列不连续 | 序列未同步 | 确保开启 `sequences: true` |
### 6.5 稳定性问题
| 现象 | 原因 | 解决 |
| — | — | — |
| 中断后重跑从头开始 | checkpoint 丢失 | 确认 `checkpoint_dir` 可写,不要用 /tmp |
| 死锁 | 目标端并发冲突 | 降 `concurrency`,关闭 `foreign_keys: false` |
| 连接耗尽 | 连接池太小 | 提高 `max_open_conns: 100-200` |
| 长事务超时 | per_table_timeout 太小 | 提高 `per_table_timeout: 86400`(1 天) |
### 6.6 类型映射问题
| 现象 | 原因 | 解决 |
| — | — | — |
| 某字段变 TEXT | 类型未识别 | 查看评估报告 unmapped 列表,手动映射 |
| Oracle NUMBER → DM 数值溢出 | NUMBER(38,0) 超 BIGINT | 工具自动映射为 DECIMAL/NUMERIC |
| MySQL JSON → PG 报错 | PG 需 jsonb 类型 | 工具自动映射为 JSON/JSONB |
| SQL Server IMAGE → 目标乱码 | 未用二进制列 | 工具自动映射为 BLOB/BYTEA,bytes 直传 |
### 6.7 可视化控制台问题
| 现象 | 原因 | 解决 |
| — | — | — |
| 页面打不开 | 端口未放行 | 检查防火墙 `firewall-cmd –add-port=8088/tcp` |
| 进度不刷新 | SSE 被代理缓冲 | Nginx 加 `proxy_buffering off` |
| 任务卡住 | 后台线程异常 | `python3 webctl.py status` 查日志,`restart` 重启 |
| 配置保存失败 | 目录无写权限 | 确认 `config.yml` 所在目录可写 |
### 6.8 通用排查命令
`# 1. 查看迁移日志`
`tail -f conversion.log`
` `
`# 2. 查看错误日志`
`tail -f errors.log`
` `
`# 3. 查看检查点状态`
`ls -la .checkpoint/`
` `
`# 4. 验证安装`
`python3 -m fgo2cdb –version`
`python3 -c “from fgo2cdb import native; print(native.engine_version(), native.native_loaded())”`
` `
`# 5. 查看控制台日志`
`python3 webctl.py logs`
` `
`# 6. 清理检查点(重新全量迁移)`
`rm -rf .checkpoint/`
────────────────────────────────────────
## 七、目录结构
`FGO2CDB/`
`├── fgo2cdb/ # Python 主包`
`│ ├── __init__.py # 版本/族定义`
`│ ├── __main__.py # 模块入口`
`│ ├── cli.py # 命令行接口`
`│ ├── config.py # 配置数据类`
`│ ├── converter.py # 迁移编排核心`
`│ ├── pipeline.py # 并发管道`
`│ ├── typemap.py # 类型映射`
`│ ├── funcmap.py # 函数映射`
`│ ├── assessor.py # 迁移前评估`
`│ ├── report.py # 迁移报告`
`│ ├── checkpoint.py # 断点续传`
`│ ├── native.py # C 引擎绑定`
`│ ├── web.py # Flask 可视化`
`│ ├── source/ # 源端连接器`
`│ │ ├── mysql.py / oracle.py / postgresql.py`
`│ │ ├── db2.py / sqlserver.py / mongodb.py / redis.py`
`│ └── target/ # 目标端写入器`
`│ ├── dm.py / postgres.py / mysql.py / oracle.py / gbase.py`
`├── native/ # 原生 C 引擎`
`│ ├── fgconv.c / fgconv.h`
`│ ├── libfgo2cdb.so`
`│ └── Makefile`
`├── templates/ # 迁移模板配置(40+ 模板)`
`│ ├── oracle_to_dm.yml / oracle_to_kingbase.yml …`
`│ ├── mysql_to_tidb.yml / mysql_to_dm.yml …`
`│ └── postgresql_to_dm.yml / db2_to_dm.yml …`
`├── docs/ # 文档`
`│ ├── README.md # 本说明手册`
`│ └── README.docx # Word 版本`
`├── config.example.yml # 示例配置`
`├── webctl.py # 可视化控制脚本`
`├── fgo2cdb.py # 快捷入口`
`├── Makefile # 构建自动化`
`└── requirements.txt # Python 依赖`
────────────────────────────────────────
## 八、版本与致谢
**当前版本:1.0.0**
**作者:风哥(微信 itpux-com / QQ 113257174)**
**官方网站:http://www.fgedu.net.cn | http://www.itpux.com**
**数据库教程:https://edu.51cto.com/lecturer/8020378.html**
────────────────────────────────────────
***FGO2CDB — 让国产数据库迁移更简单、更快速、更可靠。***