【OGG】常用参数、函数

常用extract 参数文件

GGSCI (EPCDB1) 2> view param extgh

 

extractextgh

useridggs, password ggs

TRANLOGOPTIONS CONVERTUCS2CLOBS               

--本地字符集为UTF,同步数据类型有CLOB,需要加此参数(OGG11版本以后就不用了)

warnlongtrans2h, checkinterval 3m

fetchoptionsnousesnapshot

THREADOPTIONSMAXCOMMITPROPAGATIONDELAY  30000IOLATENCY 30000

tranlogoptionsaltarchivelogdest primary instance epcdb /arch

discardfile  ./dirrpt/extgh.dsc,append,megabytes 10

getupdatebefores

ignorereplicates

exttrail/u01/ggsdmp/ext/gh/e1

numfiles4000

dynamicresolution

DDLINCLUDE MAPPED

 

tableGH.APP_INFO;

 

常用datapump参数文件

GGSCI (EPCDB1) 2> view param dpgh

 

extractdpgh

rmthost192.168.131.44, mgrport 7809

rmttrail/u01/ggsdmp/gh/r2

passthru       

dynamicresolution

tableGH.APP_INFO;

 

 

常用replicat 参数文件

GGSCI (testrac2) 2> view param repgh

 

replicatrepgh

useridggs, password ggs

sqlexec"alter session set constraints=deferred"

discardfile./dirrpt/repgh.dsc,append, megabytes 100

numfiles4000

assumetargetdefs

dynamicresolution

APPLYNOOPUPDATES

checksequencevalue

allownoopupdates

batchsql

DDLINCLUDE MAPPED

DDLERRORdefault ABEND

REPERROR(-1403, discard)

 

mapGH.APP_INFO, target GUARD.APP_INFO;


 

附录—列转换函数列表

ColumnConversion Functions

. . . . .. . . . . . . . . .

Using the columnconversion functions of Oracle GoldenGate, you can manipulate source valuesinto the appropriate format for target columns. These functions enable you to manipulatenumbers and characters, perform tests, extract parameter values, return environmentinformation, and more.

Summary ofcolumn-conversion functions

This summary isorganized according to the types of processing that can be performed with theOracle GoldenGate functions. An alphabetical reference begins on page 431.

 

Table 43 Performing tests

Function           Description

CASE                Selects a valuedepending on a series of value tests.

EVAL                 Selects a value based ona series of independent tests.

IF                        Selectsone of two values depending on whether a conditional statement

returns TRUE or FALSE.

 

Table 44   Handling missing columns

Function           Description

COLSTAT         Returns an indicatorthat a column is MISSING, NULL, or INVALID.

COLTEST         Performs conditionalcalculations to test whether a column is PRESENT,

                     MISSING, NULL,or INVALID.

 

Table 45 Working with dates

Function           Description

DATE                Returns a date and timebased on the format passed into the source column.

DATEDIFF        Returns the difference between two dates ordatetimes.

DATENOW       Returnsthe current date and time.

 

Table 46 Performing arithmeticcalculations

Function           Description

COMPUTE       Returnsthe result of an arithmetic expression.

 

Table 47 Working with strings

Function                    Description

NUMBIN                    Converts a binary stringinto a number.

NUMSTR                   Converts a string into anumber.

STRCAT                     Concatenates one or morestrings.

STRCMP                    Compares two strings.

STREXT                     Extracts a portion of astring.

STREQ                       Determines whether ornot two strings are equal.

STRFIND                   Finds the occurrence ofa string within a string.

STRLEN                     Returns the length of astring.

STRLTRIM                 Trims leading spaces.

STRNCAT                  Concatenates one or morestrings to a maximum length.

STRNCMP                 Compares two stringsbased on a specified number of characters.

STRNUM                   Converts a number into astring.

STRRTRIM                 Trims trailing spaces.

STRSUB                    Substitutes one stringfor another.

STRTRIM            Trimsleading and trailing spaces.

STRUP                       Changes a string to uppercase.

VALONEOF               Comparesa string or string column to a list of values.

 

Table 48 Other functions

Function                             Description

BINARY                               Maintainssource binary data as binary data in the target column

                                   when the sourcecolumn is defined as a character column.

BINTOHEX                Convertsa binary string to a hexadecimal string.

GETENV                                      Returnsenvironmental information.

GETVAL                              Extractsparameters from a stored procedure as input to a FILTER

or COLMAP clause.

HEXTOBIN                         Converts a hexadecimal stringto a binary string.

HIGHVAL | LOWVAL        Constrains a value to a high or low value.

RANGE                                Dividesrows into multiple groups of data for parallel processing.

TOKEN                                Retrievestoken data from a trail record header.


 

1. FETCHCOLS--抓取所需要的列

Use FETCHCOLS and FETCHCOLSEXCEPT to fetch column values from the database when the valuesare not present in the transaction log record. Use this option if the databaseuses compressed updates (where column values are not logged unless theychanged), but you need to ensure that other columnvalues required for FILTER operationsare available.

FETCHCOLSfetchesthe specified column(s).

FETCHCOLSEXCEPTfetchesall columns except those specified. For tables with numerous columns, FETCHCOLSEXCEPT may be more efficient than listing eachcolumn with FETCHCOLS.

 

Syntax     TABLE

, {FETCHCOLS | FETCHCOLSEXCEPT}( [, ...]) ;

 

TABLEGUARD.TEST, FETCHCOLS (col_1, col_2, col_3)

 

2. SQLEXEC--执行sql、procedure

Use SQLEXEC to execute aSQL stored procedure or query from within a MAPstatement

during Oracle GoldenGate processing. SQLEXEC enables OracleGoldenGate to communicate directly with the database to perform any functionsupported by the database. The database function can be part of thesynchronization process, such as retrieving values for column conversion, or itcan be independent of extracting or replicating data.

When used within a MAP statement, theprocedure or query that is executed can accept input parameters from source ortarget rows and pass output parameters.

NOTE A query or procedure must be structuredcorrectly when executing a SQLEXEC statement. If Replicat encounters a problemwith the query or procedure, the process will immediately abend, regardless ofany error-handling rules that are in place.

 

Syntax Procedures:

SQLEXEC (

SPNAME

[, ID]

{, PARAMS | NOPARAMS}

[,

)

Syntax Queries:

SQLEXEC (

ID

, QUERY“

{, PARAMS| NOPARAMS}

[,

)

 

--源端获得id,通过tokens写入trail,一同传到目标端

, sqlexec(id ifid , query "select gh. SEQ_CMS_INFOS_ID.nextval id from dual" ,noparams)

, tokens(tk_ifid = ifid.id)

 

--目标端执行sql获得id,映射到列

, sqlexec(id icid , query "select GUARD.SEQ_CMSBIZTAG_ID.nextval id fromdual", noparams)

, colmap(id = icid.id)

 

--带参数的sqlexec

, sqlexec(id ctimeb , query "select create_time from epb.v_booking where epb_id =:veidb" , params (veidb=epb_id))

 

3. FILTER--条件筛选

Use FILTER to select orexclude records based on a numeric value. Afilter expression can use conditional operators, Oracle GoldenGatecolumn-conversion functions, or both.

NOTETo filter based on a string, use a string function or usethe WHERE option.

Separate all FILTER componentswith commas.

filter后面的条件只能为数字,即与数字作比较。若是其他如字符类型,可以用where来进行筛选。

Syntax     MAP

, TARGET , FILTER (

[, ON INSERT | ON UPDATE| ON DELETE]

[, IGNORE INSERT | IGNORE UPDATE |IGNORE DELETE]

,

[, RAISEERROR ]

);

 

--选出info_type中以MOBILE开头的数据(@STRFIND查找数据位置)

, FILTER(@STRFIND(info_type,"MOBILE") = 1)

 

4. WHERE—条件筛选

Use WHEREto selectrecords based on a conditional statement. For more information on using a WHERE clause and thecolumn data that can be used, see the Oracle GoldenGateWindows and UNIXAdministrator’s Guide.

Oracle GoldenGate does not support WHERE for columnsthat have a multi-byte character set or a character set that is incompatiblewith the character set of the local operating system.

Literal strings used in WHERE must be enclosed within double quotesunless the USEANSISQLQUOTES parameter is used in the GLOBALSfile. Thisparameter enforces SQL-92 rules for identifiers and literals.

 

Syntax     MAP

, TARGET
,

WHERE ();

 

-- where后面可以直接进行column test,@NULL, @PRESENT, @ABSENT (column isnull, present or absent in the record).

 

--选出info_type中以MOBILE开头的数据(@STRFIND查找数据位置)

, where (@STRFIND (info_type, "MOBILE") = 1)

 

--选出info_status为9的数据

, where (info_status = "9" );

 

5. assumetargetdefs—源端与目标端表结构相同

Valid for Replicat

Use the ASSUMETARGETDEFSparameter whenthe source and target tables specified with a MAPstatement haveidentical column structure, such as when synchronizing a hot site. It directsOracle GoldenGate not to look up source structures from a source-definitionsfile.

If source and target tables do nothave the same structure, use the SOURCEDEFSparameter instead of ASSUMETARGETDEFS. See“SOURCEDEFS” on page 330.

To find out what makes source andtarget tables identical or different in Oracle GoldenGate terms, see“Associating replicated data with metadata” in the Oracle GoldenGateWindowsand UNIX Administrator’s Guide.

Default    None

Syntax     ASSUMETARGETDEFS

 

在replicat中配置,目标端与源端的表结构完全相同,用了此参数就不会去寻找源定义文件了。

如果源端与目标端的表结构不同,那么就需要使用SOURCEDEFS参数。

 

6. SOURCEDEFS--源端与目标端的表结构异构

Valid for Extract data pump and Replicat.

Use the SOURCEDEFS parameter to specify the name of a file thatcontains definitions of source tables or files. Source definitions are requiredwhen using Oracle GoldenGate to replicate data between heterogeneous source andtargets. Use SOURCEDEFS for one or more of thefollowing processes, depending on your Oracle GoldenGate configuration:

A Replicat process on the target system

A data pump on a source or intermediarysystem.

To generate thesource-definitions file, use the DEFGEN utility.Transfer the file to the intermediary or target system before starting a datapump or Replicat.

You can have multiple SOURCEDEFS statements in the parameter file if more thanone source-definitions file will be used, for example if each SOURCEDEFS file holds the definitions for a distinctapplication.

See also ASSUMETARGETDEFS on page 127.

For more informationabout how Oracle GoldenGate make use of metadata, see the Oracle GoldenGateWindowsand UNIX Administrator’s Guide.

Default    None

Syntax     SOURCEDEFS

 

SOURCEDEFS/u01/goldengate/dirdef/gh.def

 

1). 生成def文件步骤

1.        ggsci输入edit paramsdefgen

--格式如下

CHARSET --DEFGEN读取文件时采用的字符集,默认为local OS字符集

DEFSFILE [APPEND |PURGE] [CHARSET ] --指定data-def文件名,charset标注产生的def文件字符集,默认为local os字符集

[{SOURCEDB | TARGETDB} ] USERID[, PASSWORD []]

TABLE .

[, {DEF |TARGETDEF}