Practice 22- Using Oracle GoldenGate in a Multitenant Container Database
Practice 22- Using Oracle GoldenGate in a Multitenant Container Database
Practice Overview
In this practice, you will implement two tasks at the same time:
• Configure an Oracle GoldenGate 19c replication between an Oracle 12c PDB and an Oracle 19c
PDB, including tables and sequences.
• Use Oracle GoldenGate for database upgrade with nearly zero downtime.
Pre-requisites
To implement this practice, we need to have the following two virtual machines (vms):
• Source database: is an Oracle 12c CDB database on Linux x86-64. It has one user PDB.
• Destination database: is an Oracle 19c CDB database on Linux x86-64. It has one user PDB.
Regardless of the way you chose to build up the environment, ultimately you should have an environment
with the following specifications:
VM Specification Value
ogg1 (source) Hostname ogg1
OS Linux 7
OS Linux 7
Memory 4GB
It is recommended to increase it
to at least 6 GB
(*) In the downloadable environment, there is a cron job which runs every 2nd hour to clean up the
archivelogs.
If you downloaded the environment from my website, you need to update the network settings of each
appliance because the network adapter name is different from its name in your machine.
1. Make sure the ogg1 and ogg2 appliances are turned off. If not, shut them down.
Click on "Settings" button ([Ctl]+[s]), "Network", from the Name drop list, select
the adapter that matches your environment, click on OK button.
Note: If you are using VMs from my website, do not implement the steps in this section. They are already
implemented in the VMs.
3. Make sure the ogg1 and ogg2 appliances are turned off. If not, shut them down.
Click on "Settings" button, "General", "Advanced" tab, and set the "Shared
Clipboard" to "Bidirectional", click on OK button.
Note: If you are using VMs from my website, do not implement the steps in this section. They are already
implemented in the VMs.
In the following steps you will create a staging directory in the hosting PC. This directory will be accessed
by the VirtualBox appliances ogg1 and ogg2. This task is not needed for this practice but it might be
useful for future needs.
5. In your hosting machine, under a disk drive letter of your choice, create a staging directory.
6. In the VirtualBox Manager, for each appliance, open the "Settings", click on "Shared Folders" link
in the right-hand pane. Add shared folder by pressing "plus" icon. Then select the path to directory
created in the preceding step, and mark the "Auto-mount" box. Change the "Folder Name" to
"staging"
7. Perform the following steps to add oracle user to the vboxsf group. This group has privilege to
access the shared folder.
This task might be needed if you are using the VMs downloaded from my website.
The VMs are configured with static IP addresses. In the following steps you will verify that the network
configuration works fine in your environment and make the necessary changes if needed.
8. In the VirtualBox window of ogg1, click on Application > System Tools > Settings > Network >
under the Wired section, click on the gear button > click on the IPv4 address tab
9. Check the static IP address and make sure it is acceptable in your network and pingable by your
hosting PC. Modify the IP address, if needed. If you change the IP address, you must perform the
following:
a. In the network setting, under the Wired section, enable and disable the network card so that the
new IP address takes effect.
c. Fix the IP address of the vm in the /etc/hosts file in the other vms.
E. Installing Swingbench
Swingbench is a free Java-based benchmark application. You will use it as the sample application for this
practice.
In the following steps, you will install Swingbench on your hosting PC.
11. Download Swingbench 2.6 from one of the following sources: Course downloadable
resources section OR Dominic Giles portal
12. In your hosting PC, copy the software zip file to the disk drive where you want to install the
software.
13. Extract the zip file into the selected drive letter.
If you use the installation file attached to the course, the application files should be extracted into
a folder named as ‘swingbench2.6’. This folder will be referred to as $SWINGHOME folder.
14. In the hosting PC, open a command prompt window and change the directory to
$SWINGHOME\winbin
cd D:\swingbench2.6\winbin
If you are using the VMs from my website, the Swingbench schema (soe) is already
installed in PDB1. In this case, skip the following steps. If the soe is not installed in your
environment, perform the following step to install it:
Note: Implement the following steps only if soe is not installed in the source database.
Respond to the wizard windows as follows to create soe schema and load data into it.
After the wizard finishes its execution, you should see a message that informs all the objects are
valid.
17. When you see the following window, select the option “SOE_Client_Side”.
18. Under the User Details tab, set the fields to the values as in the following screenshot. Click on
Test Connection button.
21. Observe that the "Transactions Per Minute" chart is increasing by time and it eventually gets
saturated.
Note: Please do not proceed without taking snapshots to your VMs. You will perform significant
changes on the VMs. Snapshots will help you to quickly recover your VMs in case an issue is raised.
25. In ogg1 and ogg2, invoke SQL*Plus from the GG home and login to the root container as sysdba.
cd $GG_HOME
sqlplus / as sysdba
In real life scenario, use the following formula to calculate the value that you should set to
STREAMS_POOL_SIZE:
(MAX_SGA_SIZE * # of integrated Extracts) + 25% head room
To set a value to this parameter, use the following command. You need to restart the database
instance afterwards. In the pre-built environment, this parameter is set to 128 M.
ALTER SYSTEM SET STREAMS_POOL_SIZE=<value> SCOPE=SPFILE;
show parameter STREAMS_POOL_SIZE
28. In ogg1 and ogg2, create a database user that will be used by Oracle GoldenGate.
This is a common user that will have access to all the PDBs included in the replication in
the source database. Sometimes it is referred to as the c## user.
CREATE USER c##ggadmin IDENTIFIED BY oracle DEFAULT TABLESPACE USERS TEMPORARY
TABLESPACE TEMP QUOTA UNLIMITED ON USERS;
34. In ogg1, create a user that will be used for replicating sequences and grant the required
privileges to it.
Note: If the system you are replicating does not need synchronizing the sequences, do
skip this step.
conn / as sysdba
ALTER SESSION SET CONTAINER=pdb1;
CREATE USER GGATE IDENTIFIED BY oracle DEFAULT TABLESPACE USERS TEMPORARY
TABLESPACE TEMP QUOTA UNLIMITED ON USERS CONTAINER=CURRENT;
GRANT CONNECT, RESOURCE, DBA TO GGATE ;
@sequence
GRANT EXECUTE on ggate.updateSequence TO c##ggadmin;
35. In ogg1, issue the following statement. This step is needed only when replicating
sequences is required.
conn / as sysdba
ALTER TABLE sys.seq$ ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
36. In ogg2, create a user that will be used for replicating sequences and grant the required
privileges to it.
Note: If the system you are replicating does not need synchronizing the sequences, do
skip this step.
conn / as sysdba
ALTER SESSION SET CONTAINER=PDB1;
CREATE USER GGATE IDENTIFIED BY oracle DEFAULT TABLESPACE USERS TEMPORARY
TABLESPACE TEMP QUOTA UNLIMITED ON USERS CONTAINER=CURRENT;
GRANT CONNECT, RESOURCE, DBA TO GGATE;
@sequence
GRANT EXECUTE ON GGATE.REPLICATESEQUENCE TO C##GGADMIN;
Note: Granting these privileges are not part of the standard procedure for replicating
sequences. However, without those privileges, the Replicat either hangs on replicating
sequences or abends with ORA-01031 error.
conn / as sysdba
GRANT SELECT ANY SEQUENCE TO C##GGADMIN CONTAINER=ALL;
GRANT ALTER ANY SEQUENCE TO C##GGADMIN CONTAINER=ALL;
38. In ogg1, verify that all the tables in soe schema have primary key constraints.
Observe that the tables ORDERENTRY_METADATA and LOGON do not have a primary keys.
conn soe/soe@pdb1ogg1
SELECT TABLE_NAME FROM USER_TABLES T
WHERE NOT EXISTS (SELECT 1
FROM USER_CONSTRAINTS C
WHERE C.TABLE_NAME= T.TABLE_NAME AND C.CONSTRAINT_TYPE = 'P');
40. In soe schema, make sure all the primary key constraints are enabled and validated:
Only validated primary key constraints are considered by GoldenGate capture. For
some reason, Swingbench creates its primary key constraints invalidated.
col TABLE_NAME format a20
col CONSTRAINT_NAME format a35
41. Run the following code to enable and validate the primary keys:
BEGIN
FOR R IN (SELECT TABLE_NAME, CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE
CONSTRAINT_TYPE='P') LOOP
EXECUTE IMMEDIATE 'ALTER TABLE '|| R.TABLE_NAME || ' ENABLE VALIDATE
CONSTRAINT ' || R.CONSTRAINT_NAME;
END LOOP;
END;
/
-- verify:
SELECT TABLE_NAME, CONSTRAINT_NAME, STATUS, VALIDATED
FROM USER_CONSTRAINTS WHERE CONSTRAINT_TYPE='P';
For security reasons, it is recommended to create a credential store to save the user
passwords in it. This is much better than entering the user password in the parameter file.
42. In ogg1, run the following commands to create a credential store and save the GG
admin user credential in it.
ggsci
add credentialstore
alter credentialstore add user c##ggadmin password oracle alias c##ggadminogg1
dblogin useridalias c##ggadminogg1
43. In ogg2, run the following commands to create a credential store. Create two aliases in
it. One for the root container and one for the destination pdb (PDB1).
ggsci
add credentialstore
alter credentialstore add user c##ggadmin password oracle alias c##ggadminogg2
# this is the account that will be used by the replicat to pdb1
alter credentialstore add user c##ggadmin@pdb1ogg2 password oracle alias
c##ggadminpdb1
# to verify:
info credentialstore
44. In ogg1, enable schema-level supplemental logging for all soe tables.
Note: Do not ignore the displayed information. Read them and make sure they do not
represent an issue. One of the common messages that you would look for is the
following message:
"No unique key is defined for table <table_name>"
You will see this message for tables that do not have primary keys or unique indexes.
You will also see it for the tables with invalided or disabled primary key or unique
constraints.
If you build an index on a table to fix this message, you need first to drop the logging
configuration using the following command and build it again:
delete schematrandata pdb1.soe
45. In ogg1 and ogg2, create a GLOBALS file and set the GGSCHEMA parameter in it to the user used for
synchronizing sequences. You must restart the ggsci after creating or modifying this file.
Note: The documentation sometimes refers to this schema as DDLuser.
Note: Observe the GLOBALS parameter file exists in the GG home, not in the dirprm subdirectory.
GGSCHEMA ggate
46. In ogg1 and ogg2, exit from ggsci then invoke it again so that the GLOBALS file is read and make
sure it does not have syntax error.
47. In ogg2, copy the script recreate_soe.sql to the staging folder. Run the script in SQL*Plus as
sysdba to create the soe schema in the destination database.
sqlplus / as sysdba
@ /media/sf_staging/recreate_soe.sql
49. In ogg1, edit the manager process parameter file and add the code that follows to it.
edit param mgr
Port 7810
DynamicPortList 9500-9520
PurgeOldExtracts ./dirdat/*, UseCheckpoints, MinKeepDays 5
Info mgr
51. Repeat the same steps to create and start the Manager process in the target database system
ogg2.
-- in ogg2:
sh mkdir ./dirdat/rtogg1
53. In ogg1, create the Extract parameter file and add the code that follows to it.
edit param eogg1
Extract eogg1
USERIDALIAS c##ggadminogg1
ReportCount Every 30 Minutes, Rate
Report at 01:00
ReportRollover at 01:15 on SUNDAY
-- if timezone cannot be obtained from pdb, assume it is the same as the root:
TRANLOGOPTIONS USE_ROOT_CONTAINER_TIMEZONE
-- include scheduling col values: pk, unq, and fk
LOGALLSUPCOLS
-- include before and after images in the same record
UPDATERECORDFORMAT COMPACT
ExtTrail ./dirdat/es/es
Sequence pdb1.soe.*;
Table pdb1.soe.*;
55. Create the Data Pump parameter file and add the code that follows to it.
edit param pogg1
Extract pogg1
Passthru
RmtHost ogg2, MgrPort 7810
RmtTrail ./dirdat/rtogg1/ra
SEQUENCE pdb1.soe.*;
TABLE pdb1.soe.*;
57. Start the Extract process and flush the sequences immediately after starting the
Extract.
As always, the first tool to look into for troubleshooting any issue is the file ggserr.log
dblogin useridalias c##ggadminogg1
start extract eogg1
-- If you are not synchronizing the sequences, skip flushing the sequences
flush sequence pdb1.soe.*
info extract eogg1
58. Look in the trail directory and verify that local trail(s) are created.
sh ls -al dirdat/es
59. Start the Data Pump process group and make sure it is running fine.
start extract pogg1
info ER *
info all
60. In ogg1, check on the warning or error messages. Make sure no action is required to fix
them.
Tip: In vi editor, to go to the end of the file, press on the keys [Shift]+[g]
sh vi ggserr.log
62. In ogg2, create the Replicat parameter file and add the parameters that follows to it.
edit param rpdb1
Replicat rpdb1
USERIDALIAS c##ggadminpdb1
ReportCount Every 30 Minutes, Rate
Report at 01:00
ReportRollover at 01:15 on SUNDAY
DBOPTIONS INTEGRATEDPARAMS(max_sga_size 200, COMMIT_SERIALIZATION FULL)
DiscardFile ./dirrpt/rogg2.dsc, purge
Map pdb1.soe.*, Target soe.*;
In this practice section, you will use Data Pump utilities to perform the initial loading.
64. In ogg1 and ogg2, create a staging directory to save the dump files into it.
mkdir ~/staging
sqlplus / as sysdba
ALTER SESSION SET CONTAINER=PDB1;
CREATE DIRECTORY STAGING AS '/home/oracle/staging';
grant read,write on directory staging to soe;
grant read,write on directory staging to system;
65. In ogg1, obtain the current SCN value and take a note of it.
conn / as sysdba
SELECT CURRENT_SCN FROM V$DATABASE;
66. In ogg1, export soe schema up to the SCN value obtained in the preceding step.
It is always recommended to encrypt the generated dump files with a password.
expdp soe/soe@pdb1ogg1 schemas=soe directory=STAGING parallel=2
dumpfile=soe%u.dmp logfile=soe.log encryption_pwd_prompt=yes logtime=all
flashback_scn=<scn>
67. In ogg2, copy the produced dump files into the staging directory.
scp oracle@ogg1:/home/oracle/staging/soe*.dmp /home/oracle/staging
71. In ogg2, start the Replicat after the obtained SCN value.
ggsci
start replicat rpdb1, aftercsn <scn>
info rpdb1
lag rpdb1
75. Wait for a minute and make sure all the GoldenGate processes are working fine.
# in ogg1:
# run the following ggsci command several times and make sure the rba is
# increamenting
Info *
# in ogg2:
# run the following ggsci command several times and make sure the rba is
# increamenting
info rpdb1
Now you have the application sessions running as normal and the replication going on from
the current production database (12c) to the new database release (19c). When we are
ready for migrating to the new database, we start with the following steps. This where the
downtime of this procedure starts.
77. In ogg1, use the lag command to make sure that the Extract captured all the pending
transactions. Then stop the Extract.
lag eogg1
-- stop if EOF is reported in the lag command output. If not, try the lag
-- command again.
stop eogg1
lag pogg1
stop pogg1
78. In ogg2, make sure the Replicat processed all the pending transactions in the trial files.
lag rpdb1
stop rpdb1
79. Change the connection configuration in Swingbench so that it connects to pdb1 in ogg2.
sqlplus soe/soe@pdb1ogg2
DROP TABLE TEST;
DROP SEQUENCE TEST_SEQ;
Summary