【OGG】Using the Oracle GoldenGate for SQL Server CDC Capture Replication
Before You Begin
This tutorial shows you how to use the CDC Capture replication, which utilizes the SQL Server Change Data Capture feature to read DML from the transaction log and load it into individual staging tables for each user table enabled with supplemental logging. The CDC Extract then reads the DML from the staging tables and reconstructs transactions then writes the data into trail files.
This tutorial takes approximately 15 minutes to complete.
Background
Previously, only Classic Capture was possible with SQL Server databases. With the Oracle GoldenGate 12c (12.3.0.1) release, the CDC Capture replication is introduced.
What Do You Need?
Before starting this tutorial:
Using the following tasks, you create both a Uni-Directional and a Bi-Directional SQL Server to SQL Server Replication.
一、Setting Up the Uni-Directional CDC Extract
Create a system DSN to the source database and set the change the default database to option to the source database. Use a Windows or SQL Server login that has
sysadmin
rights for this connection. You can alter the permissions todbowner
at a later time, if you want to use the same account for the Extract and are not allowed to have Extract running withsysadmin
.Unzip the
ggs_Windows_x64_MSSQL_64bit_CDC.zip
file to a new Oracle GoldenGate installation directory.Create a
GLOBALS
file in the base Oracle GoldenGate installation directory, and set theGGSCHEMA
parameter to that of an existing or new schema in the source database. Oracle recommends that you create a specific schema for Oracle GoldenGate objects.For example -
1CREATE SCHEMA ggs. Do not to use the dbo schema.
1GGSCI> EDIT PARAMS ./GLOBALSSave the GLOBALS file.
Using
GGSCHEMA
in theGLOBALS
file is a new requirement for Oracle GoldenGate for SQL Server CDC Capture. It is required so thatADD TRANDATA
can identify which schema to create necessary objects under then Extract knows which schema to call those objects from during runtime. Classic Extract does not have this requirement.Start
ggsci.exe
and create the necessary sub directories.1GGSCI> CREATE SUBDIRSCreate the Manager parameter file; list a valid
PORT
for the Manager to use, then save the file. For example,PORT 7809
1GGSCI> EDIT PARAMS MGRConnect to the source database from GGSCI and enable supplemental logging for the user tables to be captured from using one of the following:
For a SQL Server Authenticated DSN, the
USERID
andPASSWORD
are optional:12GGSCI> DBLOGIN SOURCEDB sourcedsn [USERID user PASSWORD password]GGSCI> ADD TRANDATA dbo.*Or for a Windows Authenticated DSN:
12GGSCI> DBLOGIN SOURCEDB sourcedsnGGSCI> ADD TRANDATA dbo.*In the Management Studio, within a query window for the source database. You must manually drop the SQL Server CDC cleanup job for the database because it may cause data loss for the Extract.
1EXECUTE sys.sp_cdc_drop_job 'cleanup';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. Theggschema
name used must be the same that you used with theGGSCHEMA
parameter of theGLOBALS
file. You must use a SQL Server authenticated user that hassysadmin
rights.1d:\>OGG\ogg_cdc_cleanup_setup.bat createJob username password databasename servername\instancename ggschemaCreate and save a new Extract parameter file using this sample of the minimum required parameters for a uni-directional implementation.
123456GGSCI> EDIT PARAMS cdcextEXTRACT cdcextSOURCEDB sourcedsn [USERID user PASSWORD password]EXTTRAIL ./dirdat/ceTABLE dbo.*;Do Not wildcard the
TABLE
statement if you are using the same schema withGGSCHEMA TABLE dbo.*;
.Add the Extract to the Oracle GoldenGate installation.
12GGSCI> ADD EXTRACT cdcext, TRANLOG, BEGIN NOWGGSCI> ADD EXTTRAIL ./dirdat/ce, EXTRACT cdcext
二、Setting Up the Uni-Directional Pump and Replicat
Create and save a new pump parameter file using the following sample of the minimum required parameters for a uni-directional implementation.
12345EXTRACT cdcpmpRMTHOST servername MGRPORT 7809RMTTRAIL ./dirdat/cpTABLE dbo.*;Create a system DSN to the target database, as you did for the source database in Step 1.
Create and save a new Replicat parameter file using the following command and sample of the minimum required parameters for a uni-directional implementation. The
USERID
andPASSWORD
are optional.1GGSCI> EDIT PARAMS cdcrep123REPLICAT cdcrepTARGETDB targetdsn [USERID user PASSWORD password]MAP dbo.*, TARGET dbo.*;Add the pump to the Oracle GoldenGate installation.
12GGSCI> ADD EXTRACT cdcpmp, EXTTRAILSOURCE ./dirat/ceGGSCI> ADD RMTTRAIL ./dirdat/cp, EXTRACT cdcpmpAdd the Replicat to the Oracle GoldenGate installation.
123GGSCI> DBLOGIN SOURCEDB targetdsn [USERID user PASSWORD password]GGSCI> ADD CHECKPOINTTABLE ggs.ggcheckGGSCI> ADD REPLICAT cdcrep, EXTTRAIL ./dirdat/cp,CHECKPOINTTABLE ggs.ggcheckStart and verify that the processes are running.
123GGSCI>START MGRGGSCI>START *GGSCI>INFO ALL
三、Setting Up the Bi-Directional CDC Extract
Follow all of the steps for configuring Uni-Directional replication in Step 1 and Step 1.
Add a checkpoint table to all of your source databases that the Replicat will use when adding the Replicat to deliver to the source database.
1GGSCI> ADD CHECKPOINTTABLE ggs.ggcheckEnable supplemental logging for the checkpoint table.
1GGSCI> ADD TRANDATA ggs.ggcheckEdit your Extract parameter files to add the following entries, and then save the file.
12IGNOREREPLICATESTRANLOGOPTIONS FILTERTABLE ggs.ggcheckWhen you create the Replicat that delivers to this source database, you must use the same checkpoint table for the Replicat that is specified by the Extract's
FILTERTABLE
parameter.1GGSCI> ADD REPLICAT cdcrep, EXTTRAIL ./dirdat/cp, CHECKPOINTTABLE ggs.ggcheck
四、Troubleshooting Issues
You may encounter these issues and can use this information to correct them.
TRANDATA commands are failing with the following message:
1ERROR OGG-05263 No GGSCHEMA clause was specified in the GLOBALS file...This message appears when either there is no
GLOBALS
file, or there is aGLOBALS
file that does not have aGGSCHEMA
entry supplied with a schema namea. Ensure that the
GLOBALS
file exists, that there is a validGGSCHEMA
entry, and that the schema listed is a valid schema in the database, restart GGSCI and re-issue theTRANDATA
commands.
b. Ensure that the schema has been created in the source Database. For example,CREATE SCHEMA ggs
.Extract is running, but
STATS
reports that no data is captured.a. Verify that the Extract has checkpointed with a valid LSN. When Extract first starts, if there has not been any DML for tables enabled with
TRANDATA
since Extract was created, it will not checkpoint until new DML operations are picked up by the CDC Capture job and loaded into the staging tables.1INFO EXTRACT cdcext SHOWCHExtract has not checkpointed:
1Current Checkpoint (position of last record read in the data source): Timestamp: 2017-08-15 14:12:26.454000Extract has checkpointed:
本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!123Current Checkpoint (position of last record read in the data source):Timestamp: 2017-09-27 09:17:37.640000LSN: 0000f525:00000930:0007-0000f525:00000930:0007, Tran: 0000:0b475e72b. Verify that the
TABLE
statement for Extract includes tables that are actually enabled withTRANDATA
.1INFO TRANDATAc. Ensure that if the
TABLE
statement includes wildcards, that it is not for the schema that is used with theGGSCHEMA
parameter of theGLOBALS
file.