13 Preparing and Configuring the System for Oracle GoldenGate
Topics:
- Database User for Oracle GoldenGate Processes for MySQL
- Ensuring Data Availability
- Setting Logging Parameters
- Database Connection
- Setting the Session Character Set
- Preparing Tables for Processing
- Changing the Log-Bin Location
- Configure Bi-Directional Replication
- Configuring MySQL for Remote Capture
- Configuring a Two-way SSL Connection in MySQL Capture and Delivery
- Capturing using a MySQL Replication Slave
- Other Oracle GoldenGate Parameters for MySQL
- Positioning Extract to a Specific Start Point
Parent topic: Using Oracle GoldenGate for MySQL
Database User for Oracle GoldenGate Processes for MySQL
Requirements for the database user for Oracle GoldenGate processes are as follows:
-
Create a database user that is dedicated to Oracle GoldenGate. It can be the same user for all the Oracle GoldenGate processes that must connect to a database.
-
To support DDL replication, the MySQL user must have privileges to install the database plug-ins. The required permissions for the plug-in is only required with MySQL 5.7. The
INSERT
privilege is required on themysql.plugin
system table. -
To preserve the security of your data, and to monitor Oracle GoldenGate processing accurately, do not permit other users, applications, or processes to log on as, or operate as, the Oracle GoldenGate database user.
-
Keep a record of the database users. They must be specified in the Oracle GoldenGate parameter files with the
USERID
parameter. -
The Oracle GoldenGate user requires read access to the
INFORMATION_SCHEMA
database. -
The Oracle GoldenGate user requires the following user privileges.
Privilege Source Extract Target Replicat Purpose SELECT
Yes
Yes
Connect to the database and select object definitions
REPLICATION SLAVE
Yes
NA
Connect and receive updates from the replication master’s binary log.
CREATE
CREATE VIEW
EVENT
INSERT
UPDATE
DELETE
Yes
Yes
Source and target database heartbeat and checkpoint table creation, and data record generation and purging
DROP
Yes Yes Dropping a Replicat checkpoint table or deleting a heartbeat table implementation
EXECUTE
Yes Yes To execute stored procedures.
INSERT, UPDATE, DELETE
on target tablesNA
Yes
Apply replicated DML to target objects
DDL privileges on target objects (if using DDL support)
NA
Yes
Issue replicated DDL on target objects
-
To capture binary log events, an Administrator must provide the following privileges to the Extract user:
-
Read and Execute permissions for the directory where the MySQL configuration file (
my.cnf
) is located -
Read permission for the MySQL configuration file (
my.cnf
). -
Read and Execute permissions for the directory where the binary logs are located.
-
Read and Execute permission for the
tmp
directory. Thetmp
directory is/tmp
. The MySQL database connection requires access to the/tmp/mysql.sock
file for versions prior to MySQL 8.0.
-
Ensuring Data Availability
Retain enough binary log data so that if you stop Extract or there is an unplanned outage, Extract can start again from its checkpoints. Extract must have access to the binary log that contains the start of the oldest uncommitted unit of work, and all binary logs thereafter. The recommended retention period is at least 24 hours worth of transaction data, including both active and archived information. You might need to do some testing to determine the best retention time given your data volume and business requirements.
If data that Extract needs during processing was not retained, either in active or backup logs, one of the following corrective actions might be required:
-
Alter Extract to capture from a later point in time for which binary log data is available (and accept possible data loss on the target).
-
Resynchronize the source and target tables, and then start the Oracle GoldenGate environment over again.
To determine where the Extract checkpoints are, use the INFO EXTRACT
command. For more information, see INFO EXTRACT in Command Line Interface Reference for Oracle
GoldenGate.
Setting Logging Parameters
To capture from the MySQL transaction logs, the Oracle GoldenGate Extract process must be able to find the index file, which contains the paths of all binary log files.
Extract expects that all of the table columns are in the binary log. As a
result, only binlog_row_image
set as full
is
supported and this is the default. Other values of binlog_row_image
are not supported.
Note:
Oracle recommends that the binary log is retained for at least 24 hours.In MySQL 5.7, the
server_id
option must be specified along with
log-bin
, otherwise the server will not start. For MySQL 8.0,
the server_id
is enabled by default.
Extract checks the following parameter settings to get this index file path:
Database Connection
Oracle GoldenGate gets the name of the
database it is supposed to connect to from the SOURCEDB
parameter.
To configure the connection for the SOURCEDB
parameter, use the
following format:
SOURCEDB
dbname
@
hostname:port, USERID mysqluser, PASSWORD welcome
The dbname
is the name of the MySQL instance,
hostname
is the name or IP address of the MySQL database
server, port
is the port number of the MySQL instance. If using an
unqualified host name, that name must be properly configured in the DNS database.
Otherwise, use the fully qualified host name, for example
myhost.company.com
.
Setting the Session Character Set
The GGSCI
, Extract and Replicat processes use a session character set when connecting to the database. For MySQL, the session character set is taken from the SESSIONCHARSET
option of SOURCEDB
and TARGETDB
. Make certain you specify a session character set in one of these ways when you configure Oracle GoldenGate.
Preparing Tables for Processing
This section describes how to prepare the tables for processing. Table preparation requires these tasks:
Ensuring Row Uniqueness for Tables
Oracle GoldenGate requires some form of unique row identifier on the source and target tables to locate the correct target rows for replicated updates and deletes.
KEYCOLS
clause is used in the
TABLE
or MAP
statement, Oracle GoldenGate selects
a row identifier to use in the following order of priority:
-
Primary key
-
First unique key alphanumerically that does not contain a timestamp or non-materialized computed column.
-
If none of the preceding key types exist (even though there might be other types of keys defined on the table) Oracle GoldenGate constructs a pseudo key of all columns that the database allows to be used in a unique key, excluding those that are not supported by Oracle GoldenGate in a key or those that are excluded from the Oracle GoldenGate configuration.
Note:
If there are other, non-usable keys on a table or if there are no keys at all on the table, Oracle GoldenGate logs an appropriate message to the report file. Constructing a key from all of the columns impedes the performance of Oracle GoldenGate on the source system. On the target, this key causes Replicat to use a larger, less efficientWHERE
clause. -
If a table does not have an appropriate key, or if you prefer that the existing key(s) are not used, you can define a substitute key, if the table has columns that always contain unique values. You define this substitute key by including a KEYCOLS clause within the Extract
TABLE
parameter and the ReplicatMAP
parameter. The specified key will override any existing primary or unique key that Oracle GoldenGate finds. See TABLE | MAP in Reference for Oracle GoldenGate.
- Tables with a Primary Key Derived from a Unique Index
- How to Specify Your Own Key for Oracle GoldenGate to Use
Parent topic: Preparing Tables for Processing
Tables with a Primary Key Derived from a Unique Index
In the absence of a primary key on a table, MySQL will promote a unique index to primary key if the indexed column is NOT NULL
. If there are more than one of these not-null indexes, the first one that was created becomes the primary key. To avoid Replicat errors, create these indexes in the same order on the source and target tables.
For example, assume that source and target tables named ggvam.emp
each have columns named first, middle, and last, and all are defined as NOT NULL
. If you create unique indexes in the following order, Oracle GoldenGate will abend on the target because the table definitions do not match.
Source:
mysql> create unique index uq1 on ggvam.emp(first); mysql> create unique index uq2 on ggvam.emp(middle); mysql> create unique index uq3 on ggvam.emp(last);
Target:
mysql> create unique index uq1 on ggvam.emp(last); mysql> create unique index uq2 on ggvam.emp(first); mysql> create unique index uq3 on ggvam.emp(middle);
The result of this sequence is that MySQL promotes the index on the source "first" column to primary key, and it promotes the index on the target "last" column to primary key. Oracle GoldenGate will select the primary keys as identifiers when it builds its metadata record, and the metadata will not match. To avoid this error, decide which column you want to promote to primary key, and create that index first on the source and target.
Parent topic: Ensuring Row Uniqueness for Tables
How to Specify Your Own Key for Oracle GoldenGate to Use
If a table does not have one of the preceding types of row identifiers, or if you prefer those identifiers not to be used, you can define a substitute key if the table has columns that always contain unique values. You define this substitute key by including a KEYCOLS
clause within the Extract TABLE
parameter and the Replicat MAP
parameter. The specified key will override any existing primary or unique key that Oracle GoldenGate finds.
Parent topic: Ensuring Row Uniqueness for Tables
Limiting Row Changes in Tables That Do Not Have a Key
If a target table does not have a primary key or a unique key, duplicate rows can exist. In this case, Oracle GoldenGate could update or delete too many target rows, causing the source and target data to go out of synchronization without error messages to alert you. To limit the number of rows that are updated, use the DBOPTIONS
parameter with the LIMITROWS
option in the Replicat parameter file. LIMITROWS
can increase the performance of Oracle GoldenGate on the target system because only one row is processed.
Parent topic: Preparing Tables for Processing
Triggers and Cascade Constraints Considerations
Triggers
Disable triggers on the target tables, or alter them to ignore changes made by the Oracle GoldenGate database user. Oracle GoldenGate replicates DML that results from a trigger. If the same trigger gets activated on the target table, then it becomes redundant because of the replicated version, and the database returns an error.
Cascade Constraints Considerations
Cascading updates and deletes captured by Oracle GoldenGate are not logged in binary log, so they are not captured. This is valid for both MySQL and MariaDB. For example, when you run the delete statement in the parent table with a parent child relationship between tables, the cascading deletes (if there are any) happens for child table, but they are not logged in binary log. Only the delete or update record for the parent table is logged in the binary log and captured by Oracle GoldenGate.
See https://mariadb.com/kb/en/replication-and-foreign-keys/ and https://dev.mysql.com/doc/refman/8.0/en/innodb-and-mysql-replication.html for details.
To properly handle replication of cascading operations, it is recommended to disable cascade deletes and updates on the source and code your application to explicitly delete or update the child records prior to modifying the parent record. Alternatively, you must ensure that the target parent table has the same cascade constraints configured as the source parent table, but this could lead to an out-of-sync condition between source and target, especially in cases of bi-directional replication.
Parent topic: Preparing Tables for Processing
Changing the Log-Bin Location
Modifying the binary log location by using the log-bin
variable in the MySQL configuration file might result in two different path entries inside the index file, which could result in errors. To avoid any potential errors, change the log-bin location by doing the following:
- Stop any new DML operations.
- Let the extract finish processing all of the existing binary logs. You can verify this by noting when the checkpoint position reaches the offset of the last log.
- After Extract finishes processing the data, stop the Extract group and, if necessary, back up the binary logs.
- Stop the MySQL database.
- Modify the
log-bin
path for the new location. - Start the MySQL database.
- To clean the old log name entries from index file, use
flush master
orreset master
(based on your MySQL version). - Start Extract.
Configure Bi-Directional Replication
In a bidirectional configuration, there are Extract and Replicat processes on both
the source and target systems to support the replication of transactional changes on
each system to the other system. To support this configuration, each Extract must be
able to filter the transactions applied by the local Replicat, so that they are not
recaptured and sent back to their source in a continuous loop. Additionally, tables
whose key columns are AUTO_INCREMENT
columns must be set so that
there is no conflict between the values on each system.
Configuring MySQL for Remote Capture
Oracle GoldenGate remote capture for MySQL, Amazon RDS for MySQL, Amazon Aurora MySQL, Azure Database for MySQL are used to capture transaction log data from a database located remotely to the Oracle GoldenGate installation.
Database Server Configuration
For remote capture to work, configure the MySQL server as follows:
-
Grant access permissions to the Oracle GoldenGate remote capture user.
Run the following statements against the remote database to create the user and grant the permissions needed for remote capture.
mysql > CREATE USER 'username'@'host' IDENTIFIED BY 'Password'; mysql > GRANT ALL PRIVILEGES ON *.* TO 'username'@'host’ WITH GRANT OPTION; mysql > FLUSH PRIVILEGES;
-
The
server_id
value of the remote MySQL server should be greater than 0. This value can be verified by issuing the following statement on the MySQL remote server:mysql > show variables like ‘server_id’;
If the
server_id
value is 0, modify themy.cnf
configuration file to set to a value greater than 0.
Oracle GoldenGate Configuration
Oracle GoldenGate configuration has the following steps:
-
Provide the remote database's connection information in the Extract's parameter file.
SOURCEDB remotedb@mysqlserver.company.com:port, USERID username, PASSWORD password
-
Add the following parameter to the Extract's parameter file, after the connection information.
TRANLOGOPTIONS ALTLOGDEST REMOTE
Limitations of Oracle GoldenGate Remote Capture for MySQL
Co-existence of Oracle GoldenGate for MySQL remote capture with the MySQL’s native replication slave is supported with following conditions and limitations:
-
The native replication slave should be assigned a different server_id than the currently running slaves. The slave server_id values can be seen using the following MySQL command on the master server.
mysql> show slave hosts;
-
If the Oracle GoldenGate capture abends with error
"A slave with the same server_uuid or server_id as this slave has connected to the master"
, then change the capture's name and restart the capture. -
If the native replication slave dies with the error
"A slave with the same server_uuid or server_id as this slave has connected to the master"
, then change the native replication slave’sserver_id
and restart it.
-
-
Remote capture is supported for Oracle GoldenGate on running on Linux and can support databases running on Linux or Windows.
Configuring a Two-way SSL Connection in MySQL Capture and Delivery
ca.pem
), the client certificate (client-cert.pem
)
and the client key (client-key.pem
) files to the capture and delivery.
https://dev.mysql.com/doc/refman/5.7/en/creating-ssl-rsa-files-using-mysql.html
You need to provide these paths in the Extract and Replicat parameter
files using the SETENV
parameter.
Following are the SETENV
environment parameters to set
the two-way SSL connection:
-
OGG_MYSQL_OPT_SSL_CA
: Sets the full path of the certification authority. -
OGG_MYSQL_OPT_SSL_CERT
: Sets the full path of the client certificate. -
OGG_MYSQL_OPT_SSL_KEY
: Sets the full path of the client key.
SETENV (OGG_MYSQL_OPT_SSL_CA='/var/lib/mysql.pem')
SETENV (OGG_MYSQL_OPT_SSL_CERT='/var/lib/mysql/client-cert.pem')
SETENV (OGG_MYSQL_OPT_SSL_KEY='/var/lib/mysql/client-key.pem')
For a MySQL user
configured with X509 encryption scheme, the MySQL database requires the
ssl-key
and ssl-cert
options at the time of
logging in. So, when an Oracle GoldenGate credential store entry is created for
this user, the SSL options in the credential store alias must mandatorily include
sslKey
and sslCert
regardless of
sslMode
used.
Capturing using a MySQL Replication Slave
You can configure a MySQL replication slave to capture the master's binary log events from the slave.
Typically, the transactions applied by the slave are logged into the relay logs and not into the slave's binlog
. For the slave to write transactions in its binlog
, that it receives from the master , you must start the replication slave with the log-slave-updates
option as 1
in my.cnf
in conjunction with the other binary logging parameters for Oracle GoldenGate. After the master's transactions are in the slave's binlog
, you can set up a regular Oracle GoldenGate capture on the slave to capture and process the slave's binlog
.
Other Oracle GoldenGate Parameters for MySQL
The following parameters may be of use in MySQL installations, and might be required if non-default settings are used for the MySQL database. Other Oracle GoldenGate parameters will be required in addition to these, depending on your intended business use and configuration.
Parameter | Description |
---|---|
|
Required to specify to the VAM the TCP/IP connection port number of the MySQL instance to which an Oracle GoldenGate process must connect if MySQL is not running on the default of 3306. DBOPTIONS CONNECTIONPORT 3307 |
|
Specifies the DNS name or IP address of the system hosting MySQL to which Replicat must connect. |
|
Prevents Replicat from abending when replicated LOB data is too large for a target MySQL |
|
Specifies database connection information consisting of the database, user name and password to use by an Oracle GoldenGate process that connects to a MySQL database. If MySQL is not running on the default port of 3306, you must specify a complete connection string that includes the port number:
If you are not running the MySQL database on port 3306, you must also specify the connection port of the MySQL database in the DBLOGIN SOURCEDB dbname@hostname:port, USERID user, PASSWORD password For example: GGSCI> DBLOGIN SOURCEDB mydb@mymachine:3307, USERID myuser, PASSWORD mypassword |
|
To enable Replicat to bypass the MySQL connection timeout, configure the following command in a
Where: |
Global
variable |
For heartbeattable to work in MySQL 5.7 , MySQL global variable
These values must be removed by issuing the following
command:
|
Positioning Extract to a Specific Start Point
You can position the Extract to a specific start point in the transaction logs using
the ADD/ALTER EXTRACT
commands:
{ADD | ALTER EXTRACT}
group
, LOGNUM
log_num
, LOGPOS
log_pos
-
group
is the name of the Oracle GoldenGate Extract group for which the start position is required. -
LOGNUM
is the log file number. For example, if the required log file name istest.000034
, theLOGNUM
value is 34. Extract will search for this log file.Note:
In Microservices Architecture,ADD EXTRACT
will fail if theLOGNUM
value contains zeroes preceding the value. For example,ADD EXTRACT ext1, TRANLOG, LOGNUM 000001, LOGPOS 0
will fail. Instead, setLOGNUM
to 1 for this example to succeed. -
LOGPOS
is an event offset value within the log file that identifies a specific transaction record. Event offset values are stored in the header section of a log record. To position at the beginning of abinlog
file, set theLOGPOS
as 0.
In MySQL logs, an event offset value can be unique only within a given binary file. The combination of the position value and a log number will uniquely identify a transaction record. Maximum Log number length is 8 bytes unsigned integer and Maximum Log offset length is 8 bytes unsigned integer. Log number and Log offset are separated by a pipe (‘|’) delimiter. Transactional records available after this position within the specified log will be captured by Extract. In addition, you can position an Extract using a timestamp.