Oracle GoldenGate: Using macros

Source: Internet
Author: User

Ogg macros, like macros in C, provide function encapsulation, which means that some configuration parameters can be organized into a macro and then shared across multiple parameter files, particularly useful for environments with complex or multiple replication points. Below we will show you how to create a library of macros and how to use the macro library created in the Ogg parameter file.
A macro library is a collection of macros that can be defined as a library file that contains multiple macros, or multiple library files, including different macro definitions. It is recommended that you store the library file in the Dirmac directory of Ogg, and that the library file uses the. mac suffix. This makes it easy to identify when referencing.

The following is an example of a macro in which everything is stored in a library file: "$OGG _base/dirmac/macrolib.mac".

MACRO #dbconnect
BEGIN
UserID gguser, password aacaaaaaaaaaaahaaifboiyamcgimare, encryptkey default
END;

MACRO #bpsettings
BEGIN
Statoptions Resetreportstats

--Generate a every day at 1 minute after midnight.
--This report would contain the number of operations, by operation
--type, performed on each table.
Report at 00:01

Reportrollover at 00:01
Reportcount every SECONDS, rate

--End of "Best Practices" sections
END;

MACRO #funcsmap
PARAMS (#src_table, #target_table)
BEGIN
MAP #src_table, TARGET #target_table,
Colmap (Usedefaults,
Orders_trans_ts = @GETENV ("Ggheader", "Committimestamp"),
Trans_rec_loc8tr = @STRCAT (@GETENV ("RECORD", "fileseqno"),
@GETENV ("RECORD", "Filerba")),
Extract_lag_ms = @TOKEN ("Tkn-extlag-msec"),
Replicat_lag_ms = @GETENV ("Lag", "MSEC"),
Src_db_name = @TOKEN ("Tkn-src-dbname"),
Src_db_version = @TOKEN ("Tkn-src-dbversion"),
SRC_TXN_CSN = @TOKEN ("TKN-TXN-CSN")
);
END;

All macros start with the key "macro" keyword, followed by the name of the macro, defined as "#name", and the contents of the macro are "begin...end;" Keyword contains, the above three macro definitions are #dbconnect, #bpsettings, and #funcsmap, respectively. which
#dbconnect宏定义了一个DB连接的语句, use the default key for password encryption;
#bpsettings宏定义了OGG中配置时的一些最佳建议, such as reporting replication on a daily or hourly basis;
#funcsmap宏定义了一个map映射, it is important to note that it requires two parameters to be used;

The following is the use of the macro on a Replicat side:

Nolist
Include./dirmac/macrolib.mac
List

Replicat RFUNCB
#dbconnect ()
#bpsettings ()
Sourcedefs./dirdef/mydefs.defs
Discardfile./DIRRPT/RFUNCB.DSC, purge
#funcsmap (Amer.orders, Euro.funcs_test)

When the RFUNCB delivery process starts, the include statement loads the library file:./dirmac/macrolib.mac. The parameter nolist means to tell the delivery process not to write the subsequent execution to the log file, while the list parameter requires that subsequent execution statements be written to the log.
If there is no list statement in this parameter file, the entire delivery process will not have any log output to the file.
When the delivery process reads the REPLICAT parameter file, it replaces the referenced macro with the statement definition in the library file, so "#dbconnect ()", "#bpsettings ()" and "#funcsmap (Amer.orders, Euro.funcs_ Test) "will be replaced with the corresponding statement.

The #funcsmap macro uses two parameters, representing both the source table and the target table, respectively. The params keyword tells the user that the macro needs to have parameters to run. For the use of parameters, there are a few things to note:

    • Parameter names are case-insensitive;
    • Quotation marks cannot be used in parameter names;
    • Parameters are not required in the macro definition;
    • A macro can have up to 99 parameters, and the length of all parameters cannot exceed 9999 bytes;
    • All parameters must be defined in the params statement, and when the macro is called, all parameters must be assigned values.


Summary
Ogg macros are a good technique when using and configuring the Ogg parameters, especially for multiple profiles and complex environments, where a common set of operations can be defined in one file and then used in all environments to reduce operational complexity.

Oracle GoldenGate: Using macros

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.