本文档风哥主要介绍Oracle GoldenGate迁移相关知识,包括GoldenGate迁移的概念、GoldenGate迁移组成、GoldenGate迁移使用、GoldenGate迁移配置、GoldenGate迁移监控、GoldenGate迁移故障处理等内容,由风哥教程参考Oracle官方文档Install and Upgrade内容编写,适合DBA人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。
Part01-基础概念与理论知识
1.1 GoldenGate迁移的概念
Oracle GoldenGate是Oracle提供的企业级数据复制和迁移工具。GoldenGate可以实现实时数据复制、数据同步、数据迁移等功能。GoldenGate迁移可以实现零停机或最小停机时间的数据库迁移,特别适合关键业务系统的迁移。更多视频教程www.fgedu.net.cn
- 实时复制:支持实时数据复制
- 零停机迁移:支持零停机时间迁移
- 异构支持:支持异构数据库迁移
- 数据过滤:支持数据过滤和转换
- 高可用性:支持高可用架构
1.2 GoldenGate迁移组成
Oracle GoldenGate迁移组成:
- Manager:管理GoldenGate进程
- Extract:从源数据库提取数据
- Data Pump:传输数据到目标
- Replicat:将数据应用到目标数据库
- Trail文件:存储提取的数据
1. Manager
– 管理GoldenGate进程
– 启动和停止进程
– 管理端口和报告
– 管理Trail文件
– 必须首先启动
2. Extract
– 从源数据库提取数据
– 支持初始加载
– 支持增量捕获
– 写入Trail文件
– 可以配置多个
3. Data Pump
– 传输数据到目标
– 读取本地Trail文件
– 写入远程Trail文件
– 支持数据过滤
– 支持数据转换
4. Replicat
– 将数据应用到目标数据库
– 读取Trail文件
– 执行DML和DDL
– 支持数据转换
– 可以配置多个
5. Trail文件
– 存储提取的数据
– 顺序文件格式
– 支持压缩
– 支持加密
– 可以配置大小
1.3 GoldenGate迁移使用
Oracle GoldenGate迁移使用:
- 零停机迁移:实现零停机时间迁移
- 最小停机迁移:实现最小停机时间迁移
- 跨平台迁移:跨平台数据库迁移
- 跨版本迁移:跨版本数据库迁移
- 异构迁移:异构数据库迁移
Part02-生产环境规划与建议
2.1 GoldenGate迁移规划
Oracle GoldenGate迁移规划要点:
– 迁移评估:评估迁移的必要性和可行性
– 迁移准备:准备迁移所需资源
– 迁移测试:在测试环境中测试
– 迁移执行:执行迁移过程
# 迁移评估规划
– 数据量评估:评估数据量大小
– 时间评估:评估迁移所需时间
– 资源评估:评估所需资源
– 风险评估:评估迁移风险
# 迁移准备规划
– 软件准备:安装GoldenGate软件
– 网络准备:准备网络环境
– 权限准备:准备用户权限
– 时间准备:准备迁移时间
# 迁移测试规划
– 测试环境:在测试环境中测试
– 测试数据:使用测试数据
– 测试用例:制定测试用例
– 测试验证:验证迁移结果
# 迁移执行规划
– 迁移时间:选择合适的迁移时间
– 迁移方式:选择合适的迁移方式
– 迁移监控:监控迁移过程
– 迁移验证:验证迁移结果
2.2 GoldenGate迁移场景
Oracle GoldenGate迁移场景:
- 零停机迁移:实现零停机时间迁移
- 最小停机迁移:实现最小停机时间迁移
- 跨平台迁移:跨平台数据库迁移
- 跨版本迁移:跨版本数据库迁移
- 异构迁移:异构数据库迁移
1. 零停机迁移
– 实现零停机时间迁移
– 业务连续运行
– 切换时间极短
– 适合关键业务
– 风险最低
2. 最小停机迁移
– 实现最小停机时间迁移
– 停机时间短
– 切换时间可控
– 适合一般业务
– 风险较低
3. 跨平台迁移
– 跨平台数据库迁移
– 如Linux到Windows
– 支持异构平台
– 操作复杂
– 风险适中
4. 跨版本迁移
– 跨版本数据库迁移
– 如11g到19c
– 支持版本升级
– 操作复杂
– 风险适中
5. 异构迁移
– 异构数据库迁移
– 如Oracle到MySQL
– 支持多种数据库
– 操作复杂
– 风险较高
2.3 GoldenGate迁移最佳实践
Oracle GoldenGate迁移最佳实践:
- 充分测试:在测试环境中充分测试
- 备份数据:迁移前备份数据
- 文档记录:记录迁移过程
- 验证数据:验证迁移后数据完整性
- 经验总结:总结迁移经验
Part03-生产环境项目实施方案
3.1 GoldenGate迁移配置
3.1.1 配置源数据库
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
# 2. 启用补充日志
SQL> alter database add supplemental log data;
Database altered.
SQL> alter database add supplemental log data (all) columns;
Database altered.
# 3. 启用强制日志
SQL> alter database force logging;
Database altered.
# 4. 创建GoldenGate用户
SQL> create user ggs_admin identified by password default tablespace users;
User created.
SQL> grant connect, resource to ggs_admin;
Grant succeeded.
SQL> grant select any dictionary to ggs_admin;
Grant succeeded.
SQL> grant select any table to ggs_admin;
Grant succeeded.
SQL> grant execute on dbms_flashback to ggs_admin;
Grant succeeded.
# 5. 启用GoldenGate支持
SQL> alter system set enable_goldengate_replication = true scope=spfile;
System altered.
SQL> shutdown immediate;
SQL> startup;
# 6. 检查GoldenGate支持
SQL> select name, value from v$parameter where name = ‘enable_goldengate_replication’;
NAME VALUE
—————————— ——————————
enable_goldengate_replication TRUE
3.1.2 配置GoldenGate进程
$ cd /oracle/app/oracle/goldengate
$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054
Linux, x64, 64bit (optimized), Oracle 19c on Oct 17 2019 14:04:56
Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
GGSCI (source) 1>
# 2. 创建子目录
GGSCI (source) 1> create subdirs
Creating subdirectories under current directory /oracle/app/oracle/goldengate
Parameter files /oracle/app/oracle/goldengate/dirprm: created
Report files /oracle/app/oracle/goldengate/dirrpt: created
Checkpoint files /oracle/app/oracle/goldengate/dirchk: created
Process status files /oracle/app/oracle/goldengate/dirpcs: created
SQL script files /oracle/app/oracle/goldengate/dirsql: created
Database definitions files /oracle/app/oracle/goldengate/dirdef: created
Extract data files /oracle/app/oracle/goldengate/dirdat: created
Temporary files /oracle/app/oracle/goldengate/dirtmp: created
Credential store files /oracle/app/oracle/goldengate/dircrd: created
Command files /oracle/app/oracle/goldengate/dircom: created
Output files /oracle/app/oracle/goldengate/dirout: created
# 3. 配置Manager
GGSCI (source) 2> edit params mgr
PORT 7809
PURGEOLDEXTRACTS ./dirdat/*, usecheckpoints
# 4. 启动Manager
GGSCI (source) 3> start mgr
Manager started.
GGSCI (source) 4> info mgr
Manager is running (IP port source.7809, Process ID 12345).
# 5. 配置Extract进程
GGSCI (source) 5> edit params ext1
EXTRACT ext1
USERID ggs_admin, PASSWORD password
EXTTRAIL ./dirdat/lt
TABLE scott.*;
# 6. 添加Extract进程
GGSCI (source) 6> add extract ext1, tranlog, begin now
EXTRACT added.
GGSCI (source) 7> add exttrail ./dirdat/lt, extract ext1
EXTTRAIL added.
# 7. 启动Extract进程
GGSCI (source) 8> start ext1
Sending START request to MANAGER …
EXTRACT EXT1 starting
GGSCI (source) 9> info ext1
EXTRACT EXT1 Last Started 2026-03-31 10:00:00 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:00 ago)
Process ID 12346
Log Read Checkpoint Oracle Redo Logs
2026-03-31 10:00:00 Seqno 123, RBA 12345678
SCN 0.12345678 (12345678)
# 8. 配置Data Pump进程
GGSCI (source) 10> edit params dp1
EXTRACT dp1
USERID ggs_admin, PASSWORD password
RMTHOST target, MGRPORT 7809
RMTTRAIL ./dirdat/rt
TABLE scott.*;
# 9. 添加Data Pump进程
GGSCI (source) 11> add extract dp1, exttrailsource ./dirdat/lt
EXTRACT added.
GGSCI (source) 12> add rmttrail ./dirdat/rt, extract dp1
RMTTRAIL added.
# 10. 启动Data Pump进程
GGSCI (source) 13> start dp1
Sending START request to MANAGER …
EXTRACT DP1 starting
GGSCI (source) 14> info dp1
EXTRACT DP1 Last Started 2026-03-31 10:00:00 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:00 ago)
Process ID 12347
Log Read Checkpoint File ./dirdat/lt000000000
2026-03-31 10:00:00 RBA 12345
# 11. 配置Replicat进程(目标端)
GGSCI (target) 1> edit params rep1
REPLICAT rep1
USERID ggs_admin, PASSWORD password
ASSUMETARGETDEFS
MAP scott.*, TARGET scott.*;
# 12. 添加Replicat进程
GGSCI (target) 2> add replicat rep1, exttrail ./dirdat/rt, checkpointtable ggs_admin.checkpoint
REPLICAT added.
# 13. 启动Replicat进程
GGSCI (target) 3> start rep1
Sending START request to MANAGER …
REPLICAT REP1 starting
GGSCI (target) 4> info rep1
REPLICAT REP1 Last Started 2026-03-31 10:00:00 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:00 ago)
Process ID 12348
Log Read Checkpoint File ./dirdat/rt000000000
2026-03-31 10:00:00 RBA 12345
3.1.3 执行初始加载
$ expdp system/password directory=datapump_dir dumpfile=initial_load.dmp logfile=initial_load.log schemas=scott flashback_scn=12345678
Export: Release 19.0.0.0.0 – Production on Tue Mar 31 10:00:00 2026
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 19c Enterprise Edition Release 19.3.0.0.0 – Production
Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″: system/******** directory=datapump_dir dumpfile=initial_load.dmp logfile=initial_load.log schemas=scott flashback_scn=12345678
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . exported “SCOTT”.”EMP” 8.570 KB 14 rows
. . exported “SCOTT”.”DEPT” 6.031 KB 4 rows
. . exported “SCOTT”.”SALGRADE” 5.960 KB 5 rows
. . exported “SCOTT”.”BONUS” 5.960 KB 0 rows
Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/datapump/initial_load.dmp
Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully completed at Tue Mar 31 10:05:00 2026 elapsed 0 00:05:00
# 2. 使用Data Pump导入数据
$ impdp system/password directory=datapump_dir dumpfile=initial_load.dmp logfile=initial_import.log schemas=scott
Import: Release 19.0.0.0.0 – Production on Tue Mar 31 10:05:00 2026
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 19c Enterprise Edition Release 19.3.0.0.0 – Production
Master table “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ successfully loaded/unloaded
Starting “SYSTEM”.”SYS_IMPORT_SCHEMA_01″: system/******** directory=datapump_dir dumpfile=initial_load.dmp logfile=initial_import.log schemas=scott
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported “SCOTT”.”EMP” 8.570 KB 14 rows
. . imported “SCOTT”.”DEPT” 6.031 KB 4 rows
. . imported “SCOTT”.”SALGRADE” 5.960 KB 5 rows
. . imported “SCOTT”.”BONUS” 5.960 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ successfully completed at Tue Mar 31 10:10:00 2026 elapsed 0 00:05:00
# 3. 启动Replicat进程
GGSCI (target) 5> start rep1, aftercsn 12345678
Sending START request to MANAGER …
REPLICAT REP1 starting
# 4. 验证数据同步
SQL> select count(*) from scott.emp;
COUNT(*)
———-
14
SQL> select count(*) from scott.dept;
COUNT(*)
———-
4
3.2 GoldenGate迁移监控
3.2.1 配置GoldenGate迁移监控脚本
$ vi /home/oracle/scripts/monitor_ogg.sh
#!/bin/bash
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# GoldenGate迁移监控脚本
export ORACLE_HOME=/oracle/app/oracle/product/19c/dbhome_1
export OGG_HOME=/oracle/app/oracle/goldengate
export PATH=$ORACLE_HOME/bin:$OGG_HOME:$PATH
LOG_DIR=”/home/oracle/ogg_monitor”
mkdir -p $LOG_DIR
DATE=$(date +%Y%m%d)
LOG_FILE=”$LOG_DIR/ogg_monitor_$DATE.log”
echo “$(date): Starting GoldenGate monitor…” > $LOG_FILE
# 检查GoldenGate状态
cd $OGG_HOME
echo “info all” | ./ggsci >> $LOG_FILE
# 检查Extract状态
echo “info ext1” | ./ggsci >> $LOG_FILE
# 检查Replicat状态
echo “info rep1” | ./ggsci >> $LOG_FILE
# 检查延迟
echo “lag ext1” | ./ggsci >> $LOG_FILE
echo “lag rep1” | ./ggsci >> $LOG_FILE
echo “$(date): GoldenGate monitor completed.” >> $LOG_FILE
# 发送报告
mail -s “GoldenGate Monitor Report – $DATE” admin@fgedu.net.cn < $LOG_FILE
# 2. 设置脚本权限
$ chmod +x /home/oracle/scripts/monitor_ogg.sh
# 3. 测试脚本
$ /home/oracle/scripts/monitor_ogg.sh
# 4. 设置定期监控
$ crontab -e
# 每小时监控GoldenGate状态
0 * * * * /home/oracle/scripts/monitor_ogg.sh >> /home/oracle/ogg_monitor/cron.log 2>&1
3.3 GoldenGate迁移故障处理
3.3.1 GoldenGate迁移常见问题
# 错误信息
ERROR OGG-00446: Oracle GoldenGate Capture for Oracle, ext1.prm: No data selecting positions from redo log.
# 解决方案
# 1. 检查归档日志
SQL> archive log list;
# 2. 检查Extract状态
GGSCI (source) 1> info ext1
# 3. 检查Extract报告
GGSCI (source) 2> view report ext1
# 4. 重启Extract
GGSCI (source) 3> stop ext1
GGSCI (source) 4> start ext1
# 问题2:Replicat进程停止
# 错误信息
ERROR OGG-01154: Oracle GoldenGate Delivery for Oracle, rep1.prm: OCI error ORA-00001: unique constraint (SCOTT.PK_EMP) violated.
# 解决方案
# 1. 检查Replicat状态
GGSCI (target) 1> info rep1
# 2. 检查Replicat报告
GGSCI (target) 2> view report rep1
# 3. 处理冲突数据
SQL> delete from scott.emp where empno = 7369;
# 4. 重启Replicat
GGSCI (target) 3> start rep1
# 问题3:延迟过大
# 错误信息
Lag 01:00:00
# 解决方案
# 1. 检查延迟
GGSCI (source) 1> lag ext1
# 2. 检查系统资源
$ top
$ iostat
# 3. 增加并行度
GGSCI (source) 2> stop ext1
GGSCI (source) 3> alter ext1, threads 4
GGSCI (source) 4> start ext1
Part04-生产案例与实战讲解
4.1 GoldenGate迁移案例
在生产环境中使用GoldenGate迁移的完整案例:
4.1.1 场景描述
某企业需要将Oracle数据库从11g迁移到19c,使用GoldenGate实现零停机迁移。
4.1.2 分析步骤
$ vi /home/oracle/scripts/auto_ogg_migration.sh
#!/bin/bash
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# GoldenGate迁移自动化脚本
export ORACLE_HOME=/oracle/app/oracle/product/19c/dbhome_1
export OGG_HOME=/oracle/app/oracle/goldengate
export PATH=$ORACLE_HOME/bin:$OGG_HOME:$PATH
LOG_DIR=”/home/oracle/ogg”
mkdir -p $LOG_DIR
DATE=$(date +%Y%m%d_%H%M%S)
LOG_FILE=”$LOG_DIR/ogg_$DATE.log”
echo “========================================” > $LOG_FILE
echo “GoldenGate Migration Report” >> $LOG_FILE
echo “Date: $(date)” >> $LOG_FILE
echo “========================================” >> $LOG_FILE
# 检查GoldenGate状态
echo “” >> $LOG_FILE
echo “Checking GoldenGate status…” >> $LOG_FILE
cd $OGG_HOME
echo “info all” | ./ggsci >> $LOG_FILE
# 执行初始加载
echo “” >> $LOG_FILE
echo “Performing initial load…” >> $LOG_FILE
expdp system/password directory=datapump_dir dumpfile=initial_load.dmp schemas=scott flashback_scn=$(echo “info ext1” | ./ggsci | grep “SCN” | awk ‘{print $3}’) >> $LOG_FILE
# 验证迁移结果
echo “” >> $LOG_FILE
echo “Verifying migration…” >> $LOG_FILE
sqlplus -s / as sysdba <
set linesize 200
set pagesize 100
select count(*) from scott.emp;
select count(*) from scott.dept;
EOF
echo “” >> $LOG_FILE
echo “GoldenGate migration completed at $(date)” >> $LOG_FILE
# 发送报告
mail -s “GoldenGate Migration Report – $DATE” admin@fgedu.net.cn < $LOG_FILE
# 2. 设置脚本权限
$ chmod +x /home/oracle/scripts/auto_ogg_migration.sh
# 3. 测试脚本
$ /home/oracle/scripts/auto_ogg_migration.sh
4.2 GoldenGate迁移故障处理
在GoldenGate迁移故障处理过程中的方法和技巧:
4.2.1 故障处理流程
# 1. 识别问题
# – 查看GoldenGate报告
# – 查看错误信息
# – 检查进程状态
# 2. 收集信息
# – 收集错误信息
# – 收集诊断数据
# – 收集系统信息
# 3. 分析原因
# – 分析错误原因
# – 分析迁移过程
# – 分析配置问题
# 4. 制定方案
# – 制定修复方案
# – 制定回滚方案
# – 制定预防措施
# 5. 执行修复
# – 执行修复操作
# – 验证修复结果
# – 记录修复过程
# 示例:处理Extract进程停止
# 1. 识别问题
GGSCI (source) 1> view report ext1
# 2. 收集信息
SQL> archive log list;
# 3. 分析原因
— 归档日志被删除
# 4. 制定方案
— 恢复归档日志或重新初始化
# 5. 执行修复
GGSCI (source) 2> stop ext1
GGSCI (source) 3> alter extract ext1, begin now
GGSCI (source) 4> start ext1
4.3 GoldenGate迁移优化
优化GoldenGate迁移配置的最佳实践:
4.3.1 优化GoldenGate迁移管理
SQL> create or replace procedure manage_ogg_results(
p_migration_date in date,
p_source_database in varchar2,
p_target_database in varchar2,
p_migration_status in varchar2
) as
begin
dbms_output.put_line(‘— GoldenGate Migration Results Management —‘);
dbms_output.put_line(‘Migration Date: ‘ || to_char(p_migration_date, ‘YYYY-MM-DD HH24:MI:SS’));
dbms_output.put_line(‘Source Database: ‘ || p_source_database);
dbms_output.put_line(‘Target Database: ‘ || p_target_database);
dbms_output.put_line(‘Migration Status: ‘ || p_migration_status);
— 可以扩展为记录到表中
end manage_ogg_results;
/
Procedure created.
# 2. 执行管理存储过程
SQL> set serveroutput on
SQL> exec manage_ogg_results(sysdate, ’11g’, ’19c’, ‘SUCCESS’);
— GoldenGate Migration Results Management —
Migration Date: 2026-03-31 10:00:00
Source Database: 11g
Target Database: 19c
Migration Status: SUCCESS
PL/SQL procedure successfully completed.
# 3. 创建GoldenGate迁移历史表
SQL> create table ogg_history (
id number primary key,
migration_date date,
source_database varchar2(50),
target_database varchar2(50),
migration_status varchar2(50),
migration_duration number,
notes varchar2(4000)
);
Table created.
SQL> create sequence ogg_history_seq;
Sequence created.
# 4. 记录迁移历史
SQL> insert into ogg_history values (
ogg_history_seq.nextval,
sysdate,
’11g’,
’19c’,
‘SUCCESS’,
120,
‘GoldenGate migration from 11g to 19c’
);
1 row created.
SQL> commit;
Commit complete.
# 5. 查看迁移历史趋势
SQL> column migration_date format a20
SQL> select migration_date, source_database, target_database, migration_status
from ogg_history
order by migration_date desc
fetch first 12 rows only;
MIGRATION_DATE SOURCE_DATABASE TARGET_DATABASE MIGRATION_STATUS
——————– ————— ————— —————-
2026-03-31 10:00:00 11g 19c SUCCESS
2026-03-30 10:00:00 12c 19c SUCCESS
2026-03-29 10:00:00 10g 11g SUCCESS
Part05-风哥经验总结与分享
5.1 GoldenGate迁移总结
Oracle GoldenGate是实现零停机迁移的重要工具,具有以下特点:
- 实时复制:支持实时数据复制
- 零停机迁移:支持零停机时间迁移
- 异构支持:支持异构数据库迁移
- 数据过滤:支持数据过滤和转换
- 高可用性:支持高可用架构
5.2 GoldenGate迁移检查清单
Oracle GoldenGate迁移检查清单:
- 充分测试:在测试环境中充分测试
- 备份数据:迁移前备份数据
- 文档记录:记录迁移过程
- 验证数据:验证迁移后数据完整性
- 经验总结:总结迁移经验
- 定期检查:定期检查迁移状态
5.3 GoldenGate迁移工具推荐
Oracle GoldenGate迁移工具推荐:
- GoldenGate:数据复制和迁移工具
- Data Pump:初始加载工具
- GGSCI:GoldenGate命令行工具
- Shell脚本:自动化迁移过程
- 监控脚本:监控迁移过程
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
