环境介绍

数据库版本 主机 ogg版本
sql server 2012 enterprise windows server 2016 19.1
oracle 19c oracle linux 7 19.1

预先准备工作

1.安装sqlserver

sqlserver 2008-2014 必须企业版才能支持cdc ,2016 standard 必须修复bug才能做ogg
https://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/goldengate/12c/sql_cdcrep/sql_cdcrep.html

2.创建数据库

create database test

3.创建同步使用ogg用户

注意必须添加sysadmin
image.png
image.png
image.png
image.png

4.创建测试数据

  1. create table [dbo].[emp] (
  2. [id] [smallint] not null,
  3. [first_name] varchar(50) not null,
  4. [last_name] varchar(50) not null,
  5. constraint [emp_pk] primary key clustered (
  6. [id] asc
  7. ) with (pad_index = off, statistics_norecompute=off, ignore_dup_key=off, allow_row_locks=on, allow_page_locks=on) on [primary]
  8. ) on [primary]
  9. go
  10. -- TEST DATA
  11. INSERT INTO [dbo].[emp] ([id], [first_name], [last_name]) VALUES (1,'Dave','Mustaine')
  12. INSERT INTO [dbo].[emp] ([id], [first_name], [last_name]) VALUES (2,'Chris','Broderick')
  13. INSERT INTO [dbo].[emp] ([id], [first_name], [last_name]) VALUES (3,'David','Ellefson')
  14. INSERT INTO [dbo].[emp] ([id], [first_name], [last_name]) VALUES (4,'Shawn','Drover')
  15. GO

oracle 安装配置ogg

1.添加环境变量

Linux 上安装 Oracle GoldenGate 与您刚才在 Windows 上进行的安装大同小异。您需要下载适用于 Linux 上的 Oracle 的 GoldenGate 介质包。创建一个安装目录并将压缩包解压缩到该目录。在本示例中,我使用 /opt/ogg 目录,因为 ORACLE_BASE 指向 /opt/ogg。完成该操作后,需要设置 PATH 和 LD_LIBRARY_PATH 环境变量,如下所示:
12c之后ogg可以进行图形化界面安装

  1. export PATH=$PATH:/opt/ogg
  2. export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/opt/ogg
  3. alias ggsci='rlwrap ggsci'

2.添加用户创建表结构

  1. create tablespace ogg;
  2. create user ogg IDENTIFIED by "12345" DEFAULT TABLESPACE ogg;
  3. grant connect,resource,dba to ogg;
  4. create table ogg.emp (id number not null, first_name varchar2(50), last_name varchar2(50));

3.修改数据库enable_goldengate_replication 参数

  1. alter system set enable_goldengate_replication=TRUE scope=both;

ogg配置

sqlserver ogg配置

1.安装

在希望安装 Oracle GoldenGate 的位置(在本示例中为 C:\GG)解压缩下载的压缩包。然后打开命令提示符,转到 C:\ogg 目录,启动 GGSCI(GoldenGate 命令界面):

  1. C:\ogg>ggsci
  2. Oracle GoldenGate Command Interpreter for SQL Server
  3. Version 19.1.0.0.200204 OGGCORE_19.1.0.0.0OGGBP_PLATFORMS_200122.0600
  4. Windows x64 (optimized), Microsoft SQL Server on Jan 22 2020 20:24:58
  5. Operating system character set identified as GBK.
  6. Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
  7. GGSCI (WIN-0Q34MJVFKBA) 1> create subdirs
  8. Creating subdirectories under current directory C:\ogg
  9. Parameter file C:\ogg\dirprm: created.
  10. Report file C:\ogg\dirrpt: created.
  11. Checkpoint file C:\ogg\dirchk: created.
  12. Process status files C:\ogg\dirpcs: created.
  13. SQL script files C:\ogg\dirsql: created.
  14. Database definitions files C:\ogg\dirdef: created.
  15. Extract data files C:\ogg\dirdat: created.
  16. Temporary files C:\ogg\dirtmp: created.
  17. Credential store files C:\ogg\dircrd: created.
  18. Masterkey wallet files C:\ogg\dirwlt: created.
  19. Dump files C:\ogg\dirdmp: created.
  20. GGSCI (WIN-0Q34MJVFKBA) 2> exit

2.创建管理服务

根据官方文档,GGSCI 支持每个 Oracle GoldenGate 实例最多 300 个并发的 Extract 和 Replicat 进程。不过,有一个进程负责控制其他进程;这个进程被称作 Manager 进程。虽然您可以手动运行此进程,但最好将其安装为服务,否则当启动该进程的用户注销时,该进程将停止。
要将 Manager 进程添加为 Windows 服务,请在 GoldenGate 安装目录中执行 INSTALL ADDSERVICE 命令。

  1. edit params mgr
  2. PORT 7809
  3. DYNAMICPORTLIST 7840-7850
  4. purgeoldextracts ./dirdat/*, usecheckpoints,minkeepdays 3
  5. AUTORESTART EXTRACT *, RETRIES 3, WAITMINUTES 2, RESETMINUTES 30
  6. lagcriticalminutes 10
  7. lagreporthours 1
  8. ACCESSRULE, PROG *, IPADDR 192.168.5.*, ALLOW
  9. --------------------------------------------------------------------------------------
  10. C:\ogg>INSTALL ADDSERVICE
  11. Service 'GGSMGR' created.
  12. Install program terminated normally.

3.创建GLOBALS文件

注意如果不创建GLOBALS文件执行add trandata 命令会报错

  1. GGSCI (WIN-0Q34MJVFKBA) 10> edit param ./GLOBALS
  2. GGSCHEMA dbo ##ogg为之前创建的schema
  3. checkpointtable dbo.ogg_chkpt

4.设置端口

  1. GGSCI (WIN-0Q34MJVFKBA) 6> edit params MGR
  2. port 7809
  3. AUTOSTART ER * --MGR启动时自动启动所有进程
  4. DYNAMICPORTLIST 7840-7850
  5. AUTORESTART ER *, WAITMINUTES 5, RETRIES 5

5.sqlserver 服务器创建dsn

  1. Microsoft SQL Server ODBC 驱动程序版本 10.00.14393
  2. 数据源名称: ogg
  3. 数据源描述: 1
  4. 服务器: 192.168.5.41
  5. 数据库: test
  6. 语言: (Default)
  7. 翻译字符数据: Yes
  8. 日志长运行查询: No
  9. 日志驱动程序统计: No
  10. 使用区域设置: No
  11. 预定义的语句选项: 在断开时删除临时存储过程
  12. 使用故障转移服务器: No
  13. 使用 ANSI 引用的标识符: Yes
  14. 使用 ANSI 的空值,填充和警告: Yes
  15. 数据加密: No

6.启用cdc

  1. EXECUTE sys.sp_cdc_enable_db

7.删除数据库自带 cdc job

You must manually drop the SQL Server CDC cleanup job for the database because it may cause data loss for the Extract.

  1. EXECUTE sys.sp_cdc_drop_job 'cleanup';

8.添加新的job

Use the ogg_cdc_cleanup_setup.bat utility (in the Oracle GoldenGate installation directory) to create the Oracle GoldenGate CDC cleanup job and associated objects. The ggschema name used must be the same that you used with the GGSCHEMA parameter of the GLOBALS file. You must use a SQL Server authenticated user that has sysadmin rights.

  1. Example:
  2. ogg_cdc_cleanup_setup.bat createJob user1 pword1 dbname1 HOSTNAME\INSTANCE oggschema
  3. ogg_cdc_cleanup_setup.bat dropJob user1 pword1 dbname1 HOSTNAME\INSTANCE oggschema
  4. C:\ogg>ogg_cdc_cleanup_setup.bat createjob ogg 12345 test 192.168.5.41 dbo
  5. Oracle GoldenGate CDC cleanup job setup script
  6. ==============================================
  7. Command: createjob
  8. The Microsoft provided SQL Server Change Data Capture Cleanup job is enabled for database 'test'.
  9. Disable or drop the Microsoft SQL Server Change Data Capture Cleanup job for database 'test' and re-run this program.

9.添加检查表

  1. dblogin sourcedb ogg
  2. add checkpointtable dbo.ogg_chkpt
  3. ADD TRANDATA dbo.ogg_chkpt

10.启动管理进程

如果创建了前面的ggsci 的服务则不用手动启动进程,在计算机启动时自动运行

  1. ggsci
  2. start mgr

11. 添加表

  1. cd c:ogg > cmd
  2. ggsci.exe
  3. GGSCI (WIN-0Q34MJVFKBA) 1> dblogin sourcedb ogg
  4. 2021-01-13 15:11:05 INFO OGG-03036 Database character set identified as windows-936. Locale: zh_CN.
  5. 2021-01-13 15:11:05 INFO OGG-03037 Session character set identified as GBK.
  6. Successfully logged into database.
  7. add trandata dbo.emp

12.创建defgen类型转换参数文件

  1. edit params DEFGEN
  2. 追加如下信息
  3. -----------------------------------
  4. defsfile c:\ogg\dirdef\emp.def
  5. sourcedb ogg ####ojdbc 名称
  6. table dbo.emp;
  7. ------------------------------------
  8. defgen paramfile c:\ogg\dirprm\defgen.prm ##创建类型转换参数文件
  9. C:\ogg>defgen paramfile c:\ogg\dirprm\defgen.prm
  10. ***********************************************************************
  11. Oracle GoldenGate Table Definition Generator for SQL Server
  12. Version 19.1.0.0.200204 OGGCORE_19.1.0.0.0OGGBP_PLATFORMS_200122.0600
  13. Windows x64 (optimized), Microsoft SQL Server on Jan 22 2020 21:27:01
  14. Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
  15. Starting at 2021-01-06 21:19:28
  16. ***********************************************************************
  17. Operating System Version:
  18. Microsoft Windows Server 2016, on x64
  19. Version 10.0 (Build 14393)
  20. Process id: 1764
  21. ***********************************************************************
  22. ** Running with the following parameters **
  23. ***********************************************************************
  24. defsfile c:\ogg\dirdef\emp.def
  25. sourcedb ogg
  26. 2021-01-06 21:19:29 INFO OGG-03036 Database character set identified as windows-936. Locale: zh_CN.
  27. 2021-01-06 21:19:29 INFO OGG-03037 Session character set identified as GBK.
  28. table ogg.emp;
  29. Retrieving definition for ogg.emp.
  30. Definitions generated for 1 table in c:\ogg\dirdef\emp.def.

emp.def 文件内容如下所示

  1. *+- Defgen version 7.0, Encoding GBK
  2. *
  3. * Definitions created/modified 2021-01-06 21:19
  4. *
  5. * Field descriptions for each column entry:
  6. *
  7. * 1 Name
  8. * 2 Data Type
  9. * 3 External Length
  10. * 4 Fetch Offset
  11. * 5 Scale
  12. * 6 Level
  13. * 7 Null
  14. * 8 Bump if Odd
  15. * 9 Internal Length
  16. * 10 Binary Length
  17. * 11 Table Length
  18. * 12 Most Significant DT
  19. * 13 Least Significant DT
  20. * 14 High Precision
  21. * 15 Low Precision
  22. * 16 Elementary Item
  23. * 17 Occurs
  24. * 18 Key Column
  25. * 19 Sub Data Type
  26. * 20 Native Data Type
  27. * 21 Character Set
  28. * 22 Character Length
  29. * 23 LOB Type
  30. * 24 Partial Type
  31. *
  32. Database type: MSSQL
  33. Character set ID: windows-936
  34. National character set ID: UTF-16
  35. Locale: zh_CN
  36. Case sensitivity: 00 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00
  37. TimeZone: Asia/Shanghai
  38. *
  39. Definition for table ogg.emp
  40. Record length: 121
  41. Syskey: 0
  42. Columns: 3
  43. id 134 23 0 0 0 1 0 8 8 8 0 0 0 0 1 0 1 0 5 -1 0 0 0
  44. first_name 64 50 11 0 0 1 0 50 50 0 0 0 0 0 1 0 0 0 12 5001 0 0 0
  45. last_name 64 50 66 0 0 1 0 50 50 0 0 0 0 0 1 0 0 0 12 5001 0 0 0
  46. End of definition

拷贝文件到linux 目标端/opt/ogg/dirdef/ 目录下

13.配置 Extract 进程

首先在源计算机上配置 Extract 进程。将进程命名为 INEXT(表示 INitial EXTract,初始提取)。接下来,按照为 DEFGEN 实用程序创建参数文件的方式创建一个参数文件。文件名为 INEXT.PRM。

SOURCEISTABLE 参数指示 Extract 进程直接从表而不是从事务日志获取数据。这是我们为执行完整提取所期望的行为。SOURCEDB 指向包含数据的数据库。RMTHOST 和 MGRPORT 指定远程计算机和 Manager 端口。RMTFILE 指定所提取的数据将写入的文件。

  1. EDIT PARAMS INEXT
  2. SOURCEISTABLE
  3. SOURCEDB ogg
  4. RMTHOST 192.168.5.41, MGRPORT 7809
  5. RMTFILE /opt/ogg/dirdat/ex
  6. TABLE dbo.emp;

oracle ogg 配置

1.Manager 进程

  1. ggsci
  2. GGSCI (orcl) 1> EDIT PARAM MGR
  3. PORT 7809

2.启动管理进程

  1. GGSCI (orcl) 1> START MANAGER
  2. Manager started.

3.配置replicat进程

接下来需要为 Replicat 进程设置参数。为此,创建一个新的参数文件并将其命名为 INLOAD(表示 INitial LOADing,初始加载)

SPECIALRUN 参数定义一个初始加载进程(这是不使用检查点的一次性加载)。文件中的下一行指示 Replicat 进程在加载完成后终止。
接下来提供了数据库用户和口令、提取文件以及表定义。最后一个参数 MAP 指示 Replicat 将表 dbo.EMP 重新映射到 ogg.EMP。

  1. EDIT PARAMS INLOAD
  2. SPECIALRUN
  3. END RUNTIME
  4. USERID ogg, PASSWORD 12345
  5. EXTFILE /opt/ogg/dirdat/ex
  6. SOURCEDEFS /opt/ogg/dirdef/emp.def
  7. MAP dbo.emp, TARGET ogg.emp;

初始化同步

sqlserver运行初始提取和加载

数据库和进程均已配置完成。现在可以启动初始加载,查看实际的数据复制过程。
首先需要运行 Extract 进程;它将提取 SQL Server 的 EMP 表中的所有数据,并将其写入 Linux 主机上的 RMTFILE (/opt/ogg/dirdat/ex) 中。
通过运行 EXTRACT 命令并提供参数和日志文件作为命令行参数来启动 Extract。

  1. C:\ogg>extract paramfile dirprm\inext.prm reportfile dirrpt\inext.rpt
  2. 2021-01-14 08:36:53 INFO OGG-01017 Wildcard resolution set to IMMEDIATE because SOURCEISTABLE is used.
  3. ***********************************************************************
  4. Oracle GoldenGate Capture for SQL Server
  5. SQL Server Log Mining Method: CDC
  6. Version 19.1.0.0.200204 OGGCORE_19.1.0.0.0OGGBP_PLATFORMS_200122.0600
  7. Windows x64 (optimized), Microsoft SQL Server on Jan 22 2020 21:38:19
  8. Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
  9. Starting at 2021-01-14 08:36:52
  10. ***********************************************************************
  11. Operating System Version:
  12. Microsoft Windows Server 2016, on x64
  13. Version 10.0 (Build 14393)
  14. Process id: 3236
  15. Description:
  16. ***********************************************************************
  17. ** Running with the following parameters **
  18. ***********************************************************************
  19. 2021-01-14 08:36:53 INFO OGG-03059 Operating system character set identified as GBK.
  20. 2021-01-14 08:36:53 INFO OGG-02695 ANSI SQL parameter syntax is used for parameter parsing.
  21. 2021-01-14 08:36:53 INFO OGG-01360 EXTRACT is running in Initial Load mode.
  22. 2021-01-14 08:36:53 INFO OGG-01889 Flush size (max message size) is set to 27,985.
  23. 2021-01-14 08:36:53 INFO OGG-03036 Database character set identified as windows-936. Locale: zh_CN.
  24. 2021-01-14 08:36:53 INFO OGG-03037 Session character set identified as GBK.
  25. 2021-01-14 08:36:53 INFO OGG-01851 filecaching started: thread ID: 1498749716960.
  26. 2021-01-14 08:36:53 INFO OGG-01815 Virtual Memory Facilities for: COM
  27. anon alloc: MapViewOfFile anon free: UnmapViewOfFile
  28. file alloc: MapViewOfFile file free: UnmapViewOfFile
  29. target directories:
  30. C:\ogg\dirtmp.
  31. 2021-01-14 08:36:54 WARNING OGG-01842 CACHESIZE PER DYNAMIC DETERMINATION (32G) LESS THAN RECOMMENDED: 64G (64bit system)
  32. vm found: 50.85G
  33. Check swap space. Recommended swap/extract: 128G (64bit system).
  34. 2021-01-14 08:36:54 INFO OGG-25340
  35. Database Version:
  36. Microsoft SQL Server - Enterprise Edition
  37. Version 11.00.2100 (2012)
  38. ODBC Version 03.80.0000
  39. Driver Information:
  40. SQLSRV32.DLL
  41. Version 10.00.14393
  42. ODBC Version 03.52.
  43. 2021-01-14 08:36:54 INFO OGG-06509 Using the following key columns for source table dbo.emp: id.
  44. 2021-01-14 08:37:01 INFO OGG-01888 TCP network is configured as
  45. OS DEFAULT SPECIFIED ACTUAL VALUE
  46. IP_DSCP N/A N/A N/A
  47. IP_TOS N/A N/A N/A
  48. TCP_NODELAY 768 N/A 768
  49. SO_SNDBUF 65536 N/A 65536
  50. SO_RCVBUF 65536 N/A 65536.
  51. 2021-01-14 08:37:01 INFO OGG-01478 Output file /opt/ogg/dirdat/ex is using format RELEASE 19.1.
  52. 2021-01-14 08:37:02 INFO OGG-02911 Processing table dbo.emp.
  53. ***********************************************************************
  54. * ** Run Time Statistics ** *
  55. ***********************************************************************
  56. Report at 2021-01-14 08:37:02 (activity since 2021-01-14 08:36:54)
  57. Output to /opt/ogg/dirdat/ex:
  58. From Table dbo.emp:
  59. # inserts: 4
  60. # updates: 0
  61. # deletes: 0
  62. # upserts: 0
  63. # discards: 0

oracle 运行replicat

要将所提取的数据应用于目标数据库,请运行 replicat 命令并提供准备好的参数文件

  1. cd /opt/ogg
  2. ./replicat paramfile dirprm/inload.prm

确认数据导入到oracle

  1. select * from ogg.emp;

实时数据捕获配置

Oracle Database 现在已有了 SQL Server 的 EMP 表的一个精确副本,可以创建实时捕获配置了。我们将 Extract 和 Replicat 进程配置成一直运行并不断传输/应用 EMP 表的更改。
为了实现这一新配置,需要为提取和复制创建新的参数文件。不过首先必须在 SQL Server 上另外执行两个步骤:确认数据库已设置为完全恢复,然后执行 EMP 数据库的完整数据库备份。如果执行完整备份失败,将阻碍 Extract 进程捕获实时数据更改

1. sqlserver创建新的extract 参数文件

这里不同的是我们省略了 SOURCEISTABLE 参数并引入一个新参数:TRANLOGOPTIONS MANAGESECONDARYTRUNCATIONPOINT。此选项告诉 Extract 进程定期检查和删除 CDC 捕获作业,从而提高性能并减小捕获数据所占用的空间

  1. EDIT PARAMS MSEXT
  2. EXTRACT MSEXT
  3. SOURCEDB ogg
  4. TRANLOGOPTIONS MANAGESECONDARYTRUNCATIONPOINT
  5. RMTHOST 192.168.5.150, MGRPORT 7809
  6. RMTTRAIL /opt/ogg/dirdat/ms
  7. EOFDELAYCSECS 10
  8. TABLE dbo.EMP;

2.添加日志组

  1. ADD EXTRACT MSEXT, TRANLOG, BEGIN NOW
  2. ADD RMTTRAIL /opt/ogg/dirdat/ms, EXTRACT MSEXT

3. oracle上创建一个检查点表

  1. DBLOGIN USERID ogg, PASSWORD 12345
  2. ADD CHECKPOINTTABLE ogg.chkpt

4.添加一个 Replicat 组并设置其参数

  1. ADD REPLICAT MSREP, EXTTRAIL /opt/ogg/dirdat/ms, CHECKPOINTTABLE ogg.chkpt
  2. EDIT PARAMS MSREP
  3. REPLICAT MSREP
  4. SOURCEDEFS /opt/ogg/dirdef/emp.def
  5. USERID ogg, PASSWORD 12345
  6. MAP dbo.emp, TARGET ogg.emp;

配置现已完成。下面我们来启动 Extract 和 Replicat 执行一些测试
准备实时同步
启动并测试联机事务复制

1.sqlserver 启动 Extract 进程

  1. start mgr
  2. START EXTRACT MSEXT

2.oracle 启动 replicate 进程

  1. START REPLICAT MSREP

重新配置同步

1.删除抽取进程和同步表

  1. delete msext
  2. delete trandata dbo.emp1

2.删除同步进程

  1. dblogin userid ogg password 12345
  2. delete msrep

3.初始化同步后重新添加抽取和同步进程

注意先删除之前初始化的文件,要不然会有重复数据

  1. add trandata dbo.emp1 -----一定要在配置初始化同步之前添加,不然同步过程中新增的数据无法同步过去
  2. ADD EXTRACT MSEXT, TRANLOG, BEGIN NOW
  3. ADD RMTTRAIL /opt/ogg/dirdat/ms, EXTRACT MSEXT
  4. --------------------------------------
  5. ADD REPLICAT MSREP, EXTTRAIL /opt/ogg/dirdat/ms, CHECKPOINTTABLE ogg.chkpt

生产环境正式配置

1.sqlserver

1.GLOBALS文件

  1. GGSCI (WIN-0Q34MJVFKBA) 10> edit param ./GLOBALS
  2. GGSCHEMA dbo ##ogg为之前创建的schema
  3. checkpointtable dbo.ogg_chkpt

2.mgr文件

  1. edit params mgr
  2. PORT 7809
  3. DYNAMICPORTLIST 7840-7850
  4. purgeoldextracts c:\ogg\dirdat\*, usecheckpoints,minkeepdays 3
  5. AUTORESTART EXTRACT *, RETRIES 3, WAITMINUTES 2, RESETMINUTES 30
  6. lagcriticalminutes 10
  7. lagreporthours 1
  8. ACCESSRULE, PROG *, IPADDR 192.168.5.*, ALLOW

2.extract 导出进程

  1. EDIT PARAMS MSEXT
  2. EXTRACT MSEXT
  3. SOURCEDB ogg
  4. TRANLOGOPTIONS MANAGESECONDARYTRUNCATIONPOINT
  5. REPORTCOUNT EVERY 1 MINUTES, RATE
  6. --每隔1分钟生成统计信息,用于STATS查看报告使用
  7. EXTTRAIL c:\ogg\dirdat\ms
  8. EOFDELAYCSECS 10
  9. TABLE dbo.EMP;
  1. ADD EXTRACT MSEXT, TRANLOG, BEGIN NOW
  2. ADD EXTTRAIL C:\ogg\dirdat\ms, EXTRACT MSEXT

3.添加投递进程配置文件

  1. edit param mspump
  2. EXTRACT mspump
  3. RMTHOST 192.168.5.150, MGRPORT 7809
  4. RMTTRAIL /opt/ogg/dirdat/cp
  5. TABLE dbo.emp1;
  6. TABLE dbo.emp;

4.注册投递进程

  1. ADD EXTRACT mspump, EXTTRAILSOURCE C:\ogg\dirdat\ms
  2. ADD RMTTRAIL /opt/ogg/dirdat/cp, EXTRACT mspump,megabytes 20

oracle 配置

1.oracle mgr 配置文件

  1. ggsci
  2. GGSCI (orcl) 1> EDIT PARAM MGR
  3. PORT 7809
  4. DYNAMICPORTLIST 7840-7850
  5. AUTORESTART ER *, WAITMINUTES 5, RETRIES 5
  6. --自动重启所有的replicat进程,每隔5分钟重试,重试次数5
  7. purgeoldextracts /opt/ogg/dirdat/*, usecheckpoints,minkeepdays 3

2.replicat配置文件

  1. EDIT PARAM MSREP
  2. REPLICAT MSREP
  3. SOURCEDEFS /opt/ogg/dirdef/emp.def
  4. USERID ogg, PASSWORD 12345
  5. reperror default,abend
  6. discardfile /opt/ogg
  7. /dirrpt/rep_error.dsc,append,megabytes 20
  8. MAP dbo.emp, TARGET ogg.emp;
  9. MAP dbo.emp1, TARGET ogg.emp1;

3.注册恢复进程

注意没有进行前面测试步骤直接进行配置生产环境的话需要添加checkpoint table

oracle上创建一个检查点表

  1. DBLOGIN USERID ogg, PASSWORD 12345
  2. ADD CHECKPOINTTABLE ogg.chkpt
  1. ADD REPLICAT MSREP, EXTTRAIL ./dirdat/cp,CHECKPOINTTABLE ogg.chkpt

异常处理
1.2021-01-06 09:33:29 ERROR OGG-05263 No GGSCHEMA clause was specified in the GLOBALS file. Specify a GGSCHEMA schema name.
添加GLOBALS文件

  1. edit param ./GLOBALS

2.extract 加入Manager管理进程start extract 失败
2021-01-14T23:17:48.102+0800 ERROR OGG-00551 Oracle GoldenGate Capture for SQL Server, MSEXT.prm: Database operation failed: Couldn’t connect to ogg. ODBC error: SQLSTATE 37000 native database error 4060. [Microsoft][ODBC SQL Server Driver][SQL Server]无法打开登录所请求的数据库 “test”。登录失败。.
2021-01-14T23:17:48.149+0800 ERROR OGG-01668 Oracle GoldenGate Capture for SQL Server, MSEXT.prm: PROCESS ABENDING.

image.png
打开Microsoft SQL Server Management Studio,在安全性->登录名->选择NT AUTHORITY\SYSTEM->右键->属性->服务器角色->勾选sysadmin就可以了
产生这个问题的原因在于GoldenGate的 manager(mgr)服务是以服务的方式运行的,在windows下是SYSTEM账户运行的,而SYSTEM账户可能没有权限访问Sql server数据库
3. The SQL Server (sqlsrv32.dll) driver is not supported for SQL Server 2012
2021-01-15T13:35:21.669+0800 ERROR OGG-05312 Oracle GoldenGate Capture for SQL Server, MSEXT.prm: The SQL Server (sqlsrv32.dll) driver is not supported for SQL Server 2012. Supported drivers are SQL Server Native Client 11.0 (sqlncli11.dll), ODBC Driver 11 for SQL Server (msodbcsql11.dll), ODBC Driver 13 for SQL Server (msodbcsql13.dll), ODBC Driver 17 for SQL Server (msodbcsql17.dll).
2021-01-15T13:35:21.702+0800 ERROR OGG-01668 Oracle GoldenGate Capture for SQL Server, MSEXT.prm: PROCESS ABENDING.
解决方法:
更换odbc驱动

image.png

异常处理

1.sql server端 删除extract 抽取进程后重新添加进程

help add extract 对于sql server 通过lsn 添加抽取进程的描述

  1. Positioning by timestamp in a SQL Server transaction log is affected by the
  2. following characteristics of SQL Server:
  3. The timestamps recorded in the SQL Server transaction log
  4. use a 3.3333 microsecond (ms) granularity. This level of granularity may
  5. not allow positioning by time between two transactions, if the
  6. transactions began in the same 3.3333 ms time interval.
  7. Timestamps are not recorded in every SQL Server log
  8. record, but only in the records that begin and commit the transaction,
  9. as well as some others that do not contain data.
  10. SQL Server timestamps are not from the system clock, but
  11. instead are from an internal clock that is specific to the individual
  12. processors in use. This clock updates several times a second, but
  13. between updates it could get out of sync with the system clock. This
  14. further reduces the precision of positioning by time.
  15. Timestamps recorded for log backup files may not precisely
  16. correspond to times recorded inside the backup (however this imprecision
  17. is less than a second).
  18. Positioning to an LSN is precise.
  19. LSN value
  20. Valid for SQL Server. Specifies the LSN in a transaction log at which to
  21. start capturing data. The specified LSN should exist in a log backup or the online
  22. log. An alias for this option is EXTLSN.
  23. For SQL Server, an LSN is composed of one of these, depending on how the
  24. database returns it:
  25. Colon separated hex string (8:8:4) padded with
  26. leading zeroes and 0X prefix, as in
  27. 0X00000d7e:0000036b:01bd
  28. Colon separated decimal string (10:10:5) padded with
  29. leading zeroes, as in 0000003454:0000000875:00445
  30. Colon separated hex string with 0X prefix and
  31. without leading zeroes, as in 0Xd7e:36b:1bd
  32. Colon separated decimal string without leading zeroes, as in
  33. 3454:875:445
  34. Decimal string, as in 3454000000087500445
  35. In the preceding, the first value is the virtual log file number, the
  36. second is the segment number within the virtual log, and the third is the entry
  37. number.
  38. You can find the LSN for named transactions by using a query like:
  39. select [Current LSN], [Transaction Name], [Begin Time] from fn_dblog(null, null)
  40. where Operation = 'LOP_BEGIN_XACT' and [Begin Time] >= 'time'
  41. The time format that you should use in the query should be similar to
  42. '2015/01/30 12:00:00.000' and not '2015-01-30 12:00:00.000'.
  43. You can determine the time that a particular transaction started, then
  44. find the relevant LSN, and then position between two transactions with the same
  45. begin time.
  46. LSN value

(1)停止并删除抽取进程

  1. stop msext
  2. delete msext
  3. 查看停止进程的时间点

2、查看离停止时间最近的事务前一个事务
通过日志查看进程停止时间例如2021-06-30 12:52:16.205 注意将时间”-“改为”/“

  1. select [Current LSN], [Transaction Name], [Begin Time] from fn_dblog(null, null)
  2. where Operation = 'LOP_BEGIN_XACT' and [Begin Time] between '2021/06/30 12:52:00'
  3. and '2021/06/30 12:53:00';

image.png
3.将lsn 16位事务日志转为10进制

  1. DECLARE @LSN16 VARCHAR(50)
  2. DECLARE @LSN10 NUMERIC(25, 0)
  3. DECLARE @LSN VARCHAR(25)
  4. Set @LSN16 = '000000d8:0000004a:0001' ---输入上面查询的lsn编号
  5. SELECT @LSN10 = CONVERT(INT, CONVERT(VARBINARY, '0X' + SUBSTRING(@LSN16, 1, 8), 1)) * 1000000000000000
  6. + CONVERT(INT, CONVERT(VARBINARY, '0X' + SUBSTRING(@LSN16, 10, 8), 1)) * 100000
  7. + CONVERT(INT, CONVERT(VARBINARY, '0X' + SUBSTRING(@LSN16, 19, 4), 1))
  8. SELECT @LSN10
  9. SELECT @LSN = RIGHT('0000000000' + CONVERT(VARCHAR, @LSN10), 25)
  10. SELECT CONVERT(VARCHAR(50), CONVERT(VARBINARY, CONVERT(INT, SUBSTRING(@LSN, 1, 10))), 2) + ':'
  11. + CONVERT(VARCHAR(50), CONVERT(VARBINARY, CONVERT(INT, SUBSTRING(@LSN, 11, 10))), 2) + ':'
  12. + CONVERT(VARCHAR(50), CONVERT(VARBINARY, CONVERT(INT, SUBSTRING(@LSN, 21, 5))), 2)

4.重新添加抽取进程

  1. ADD EXTRACT MSEXT TRANLOG lsn 216000000007400001
  2. --------------------------------------------------------------
  3. 如果是停业务状态,没有新事务,也可以直接用时间添加
  4. ADD EXTRACT MSEXT, TRANLOG, BEGIN 2021-06-30 10:39:06