Sunday 15 October 2023

Oracle GoldenGate HUB Configuration

Oracle GoldenGate HUB Configuration

In this post, we will provide the steps to set up an Oracle GoldenGate hub for Uni-Directional Replication.

In our environment, we have an Oracle Database 21c multi-tenant (container CDB) as both the source and target databases on seperated servers. We also have a GoldenGate hub server with the latest Oracle client installed on it. For this configuration, we will be using "pdb1" on both the source and target databases, and a demo schema named "TEST."

Information:

  • Source:
    • Hostname: dbsource
    • IP: 192.168.220.09
    • DB: pdb1
    • Schema: Test
    • Oracle: Oracle Database 21c
  • GoldenGate HUB:
    • Hostname: goldengate-server
    • IP: 192.168.220.10
    • DB: proddb
    • Oracle: Oracle Client 21c
  • Target:
    • Hostname: dbtarget
    • IP: 192.168.220.11
    • DB: pdb1
    • Schema: Test
    • Oracle: Oracle Database 21c

Steps:

  1. Edit .bash profile for client installation.

  2. Download and install Oracle GoldenGate 21c.

  3. Download and install Oracle Client 21c.

  4. Configure tnsnames.ora file with entries for source and target DBs.

  5. Configure GoldenGate settings and configuration.

Download the latest version of Oracle GoldenGate and Oracle Client software.

Verify Certification: Certification Link


Create a gg_home directory at /u01/app/oracle/product/21.0.0/


Unzip the zip file and install GoldenGate at gg Home:

Install Oracle Golden Gate 21c at gg_home directory

/u01/app/oracle/product/21.0.0/gg_home


Client Installation:

Install Oracle Client 21c or a later version at the client home directory

/u01/app/oracle/product/21.0.0/client_1/


Update the .bash profile with Oracle settings:

####################################################
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=goldengate-server; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/21.0.0/client_1; export ORACLE_HOME
TNS_ADMIN=$ORACLE_BASE/product/21.0.0/client_1/network/admin; export TNS_ADMIN
OGGHOME=/u01/app/oracle/product/21.0.0/gg_home; export OGGHOME
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib: export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
    

Make specific changes in both databases while in mount mode:

SQL> alter system set recyclebin=off scope=spfile;
SQL> alter database add supplemental log data;
SQL> alter database archivelog;
SQL> ALTER DATABASE FORCE LOGGING;
SQL> alter system set ENABLE_GOLDENGATE_REPLICATION=true;

SQL> alter database open;
    

Create tablespaces and user script for container databases:

We need to create the required tablespaces and admin user on source and target in CDB as well as in all PDBs.

In CDB:
SQL> create tablespace ggtbs datafile '/u01/app/oracle/oradata/CDB1/ggtbs01.dbf' size 1G autoextend on;
SQL> create temporary tablespace ggtemp tempfile '/u01/app/oracle/oradata/CDB1/ggtemp01.dbf' size 1G autoextend on;

In PDBs:
SQL> alter session set container=pdb1;
SQL> create tablespace ggtbs datafile '/u01/app/oracle/oradata/CDB1/pdb1/ggtbs01.dbf' size 1G autoextend on;
SQL> create temporary tablespace ggtemp tempfile '/u01/app/oracle/oradata/CDB1/pdb1/ggtemp01.dbf' size 1G autoextend on;

SQL> alter session set container=pdb2;
SQL> create tablespace ggtbs datafile '/u01/app/oracle/oradata/CDB1/pdb2/ggtbs01.dbf' size 1G autoextend on;
SQL> create temporary tablespace ggtemp tempfile '/u01/app/oracle/oradata/CDB1/pdb2/ggtemp01.dbf' size 1G autoextend on;

Create a Globale User:
SQL> CREATE USER c##ggadmin IDENTIFIED BY ggadmin container=all  default tablespace ggtbs temporary tablespace ggtemp;

Grant privileges:
SQL> GRANT CONNECT, RESOURCE, DBA TO c##ggadmin container=all;
SQL> ALTER USER c##ggadmin QUOTA unlimited ON ggtbs;
SQL> exec dbms_goldengate_auth.grant_admin_privilege('c##ggadmin',container=>'all');
SQL> ALTER USER c##ggadmin SET CONTAINER_DATA=all CONTAINER=current;
    

Create subdirectories golden gate server:

mkdir /u01/app/oracle/product/21.0.0/gg_home/dirdat/tr
(we will using this directory for trail files)

cd $GGHome
[oracle@goldengate-server gg_home]$ ./ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 21.3.0.0.0 OGGCORE_21.3.0.0.0_PLATFORMS_210728.1047_FBO
Oracle Linux 7, x64, 64bit (optimized), Oracle Database 21c and lower supported versions on Jul 29 2021 03:59:23
Operating system character set identified as UTF-8.

Copyright (C) 1995, 2021, Oracle and/or its affiliates. All rights reserved.

GGSCI (goldengate-server) 1> create subdirs

Creating subdirectories under current directory ./gg_home

Parameter files                ./gg_home/dirprm: already exists
Report files                   ./gg_home/dirrpt: created
Checkpoint files               ./gg_home/dirchk: created
Process status files           ./gg_home/dirpcs: created
SQL script files               ./gg_home/dirsql: created
Database definitions files     ./gg_home/dirdef: created
Extract data files             ./gg_home/dirdat: created
Temporary files                ./gg_home/dirtmp: created
Stdout files                   ./gg_home/dirout: created
    

Run scripts for creating necessary objects for supporting DDL replication on both servers:

@marker_setup.sql
@ddl_setup.sql
@role_setup.sql
@ddl_enable.sql
    

Add GoldenGate User to CredentialStore:

We need to add login information in GoldenGate creating a credentialstore and aliases source and target databases:
(Note: Check the tns file at the bottom for database connections).

./ggsci GGSCI (goldengate-server) 2> add credentialstore Credential store created. GGSCI (goldengate-server) 3> alter credentialstore add user c##ggadmin@ggtarget alias ggtarget Password: Credential store altered. GGSCI (goldengate-server) 4> alter credentialstore add user c##ggadmin@ggsource alias ggsource Password: Credential store altered. GGSCI (goldengate-server) 5> info credentialstore Reading from credential store: Default domain: OracleGoldenGate Alias: ggtarget Userid: c##ggadmin@ggtarget Alias: ggsource Userid: c##ggadmin@ggsource

Configure the manager and start the service:

GGSCI (goldengate-server) 55> Edit params mgr
port 7809

GGSCI (goldengate-server) 55> start mgr

GGSCI (goldengate-server) 55> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING

    

Configure the extract process and start it:

GGSCI (goldengate-server) 1> dblogin useridalias ggsource

GGSCI (goldengate-server) 1> edit params ext1
extract ext1
exttrail /u01/app/oracle/product/21.0.0/gg_home/dirdat/tr
discardfile /u01/app/oracle/product/21.0.0/gg_home/dirrpt/discard01.dsc, append megabytes 50
logallsupcols
DDL include mapped
useridalias ggsource
table test.*;


GGSCI (goldengate-server as c##ggadmin@cdb1) 7> register extract ext1 database

GGSCI (goldengate-server as c##ggadmin@cdb1) 8> add extract ext1, integrated tranlog, begin now
Integrated Extract added.

GGSCI (goldengate-server as c##ggadmin@cdb1) 9>  Add EXTTRAIL /u01/app/oracle/product/21.0.0/gg_home/dirdat/tr, extract ext1
EXTTRAIL added.

-- to view 
ggsci> view params ext1
    

Configure the Replicat process:

login to target db
GGSCI (goldengate-server) 1> dblogin useridalias ggtarget
Successfully logged into database.

-- Parameter file for Replicat:
GGSCI (goldengate-server as c##ggadmin@cdb1) 3> edit params rep1

REPLICAT rep1
ASSUMETARGETDEFS
HANDLECOLLISIONS
DISCARDFILE ./dircrd/rep_discard.txt, append, megabytes  10
DDL include ALL
USERIDALLIAS ggtarget
MAP test.*, TARGET test.*;

-- Create checkpoint Table
GGSCI (goldengate-server as c##ggadmin@cdb1) 8> add checkpointtable c##ggadmin.checkpoint
Successfully created checkpoint table c##ggadmin.checkpoint.

-- Add Replicats:
GGSCI (goldengate-server as c##ggadmin@cdb1) 9> ADD REPLICAT rep1 integrated exttrail 
/u01/app/oracle/product/21.0.0/gg_home/dirdat/tr CHECKPOINTTABLE c##ggadmin.checkpoint

Integrated Replicat added.

-- Register Replicats to database:
GGSCI (goldengate-server as c##ggadmin@cdb1) 10> register replicat REP1 database
2023-10-13 17:21:06  INFO    OGG-02528  Replicat group REP1 successfully registered with database as inbound server OGG$REP1.
    

Table creation for demo:

CREATE TABLE Test.t1(
    id NUMBER GENERATED BY DEFAULT AS IDENTITY,
    dt VARCHAR2(50) NOT NULL,
    PRIMARY KEY(id)
);
    

Add supplemental logging for a table or all schemas:

GGSCI (goldengate-server) 1> add SCHEMATRANDATA test
    

Start the Extract and Replicat process:

GGSCI (goldengate-server) 6> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING
EXTRACT     STOPPED     EXT1        00:14:23      00:00:14
REPLICAT    STOPPED     REP1        00:00:00      00:00:06

GGSCI (goldengate-server) 7> start ext1

Sending START request to Manager ...
Extract group EXT1 starting.

GGSCI (goldengate-server) 10> start rep1

Sending START request to Manager ...
Replicat group REP1 starting.


GGSCI (goldengate-server) 11> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING
EXTRACT     RUNNING     EXT1        00:14:23      00:01:24
REPLICAT    RUNNING     REP1        00:00:00      00:01:15
    

Insert some data on source and check the replication:

SQL> insert into t1 values(1,sysdate);
SQL> commit;
SQL> select * from t1;
        ID DT
---------- ---------------------------
         1 13-OCT-23

Check on Target DB:
$  sqlplus test/test@ggtarget

SQL*Plus: Release 21.0.0.0.0 - Production on Sat Oct 14 02:23:02 2023
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle.  All rights reserved.

Last Successful login time: Fri Oct 13 2023 23:48:18 -04:00

Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0

SQL> select * from t1;

        ID DT
---------- ---------------------------
         1 13-OCT-23
         
         

Replicatoin is successfull. You can test it for all DML and DDL operation...


TNS file use in this demo:

[oracle@goldengate-server gg_home]$ cat /u01/app/oracle/product/21.0.0/client_1/network/admin/tnsnames.ora
GGSOURCE=
   (DESCRIPTION=
        (ENABLE=BROKEN)
        (ADDRESS_LIST=
            (ADDRESS=(PROTOCOL=TCP)(HOST=dbsource)(PORT=1522)))
        (CONNECT_DATA=(SERVICE_NAME=pdb1))
    )

GGTARGET =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dbtarget)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdb1)
    )
  )
    


Saturday 23 September 2023

Configure Oracle 11g Enterprise Manager database console manually

Follow the following steps. 
 
1. Drop dbcontrol configuration 
2. Create the OEM repository 
3. Configure EM db control 

Step 1. Drop the existing configuration. 
 [oracle@dbserver bin]$ emca -deconfig dbcontrol db -repos drop
 

Step 2. Create the OEM repository. 
[oracle@dbserver bin]$ emca -repos create





















Step 3. Configure db control. 
[oracle@dbserver ~]$ emca -config dbcontrol db

























On any web browser try the em URL to verify the configuration.

To check the status of EM.
[oracle@dbserver ~]$ emctl status dbconsole



 



Start EM.
[oracle@dbserver ~]$ emctl start dbconsole

Stop EM.
[oracle@dbserver ~]$ emctl stop dbconsole


Monday 1 May 2023

Oracle Database 19c Data Guard Setup Using the Data Guard Broker

=========================================================================

Setup for following demonstraton:

Primary:

--Host Name: Linux1

--DB Name: orcl

--Db_Unique_Name: orcl

--Service Name: ORCL

------------------------------------------------------------------------------------------------------------------------

==Standby:

--Host Name: Linux2

--DB Name: orcl

--Db_Unique_Name: orcldr

--Service Name: ORCL_STBY 

=========================================================================

------------------------------------------------------------------------------------------------------------------------
Primary Server Setup

Logging:

Switch archivelog mode:

select log_mode from v$database;

alter database archivelog;


Enable force logging:

alter database force logging;


Set FRA for recovery and flashback

SQL> alter system set db_recovery_file_dest_size=10G scope=both sid='*';

SQL> alter system set db_recovery_file_dest='+DATA' scope=both sid='*';

System altered.


Enable Flashback on:

alter database flashback on;

------------------------------------------------------------------------------------------------------------------------

Create Standby redo logs:

SQL> alter database add standby logfile thread 1 group 10 ('/u01/app/oracle/oradata/ORCL/standby_redo01.log') size 50m;

SQL> alter database add standby logfile thread 1 group 11 ('/u01/app/oracle/oradata/ORCL/standby_redo02.log') size 50m;

SQL> alter database add standby logfile thread 1 group 12 ('/u01/app/oracle/oradata/ORCL/standby_redo03.log') size 50m;

SQL> alter database add standby logfile thread 1 group 13 ('/u01/app/oracle/oradata/ORCL/standby_redo04.log') size 50m;

------------------------------------------------------------------------------------------------------------------------

Initialization Parameters

Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. 

In this case they are both set to "orcl" on the primary database.


Make sure the STANDBY_FILE_MANAGEMENT parameter is set.

alter system set standby_file_management=auto;

------------------------------------------------------------------------------------------------------------------------

Service Setup

Following entries for the primary and standby databases are needed in the tnsnames.ora files on all servers.


ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = linux1)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SID = orcl)

    )

  )


ORCL_STBY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = linux2)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SID = orcl)

    )

  )

------------------------------------------------------------------------------------------------------------------------

The "$ORACLE_HOME/network/admin/listener.ora" file on the primary server contains the following configuration.  

    

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1)

      (SID_NAME = orcl)

    )

        (SID_DESC =

      (GLOBAL_DBNAME = orcl_DGMGRL)

      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1)

      (SID_NAME = orcl)

    )

  )



Add Following to Standby Listerer.ora: 


SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = orcldr)

      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1)

      (SID_NAME = orcl)

    )

        (SID_DESC =

      (GLOBAL_DBNAME = orcldr_DGMGRL)

      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1)

      (SID_NAME = orcl)

    )

  )

------------------------------------------------------------------------------------------------------------------------

Standby Server Setup

Create a parameter file for the standby database called "/u01/mypfile.ora" with the following contents.


*.db_name='cdb1'


Create a password file, with the SYS password matching that of the primary database.

$ orapwd file=/u01/app/oracle/product/19.0.0/db_1/dbs/orapwcdb1 password=Password1 entries=10

Or

copy from primary using scp

------------------------------------------------------------------------------------------------------------------------

Start the auxiliary instance on the standby server by starting it using the above created pfile "mypfile.ora"

$ export ORACLE_SID=orcl

$ sqlplus / as sysdba

SQL> STARTUP NOMOUNT PFILE='/u01/mypfile.ora';

------------------------------------------------------------------------------------------------------------------------

Connect to RMAN, specifying a full connect string for both the TARGET and AUXILIARY instances.

[oracle@linux1 admin]$ rman target sys/oracle@orcl auxiliary sys/oracle@orcl_stby


Use following rman commands to strat duplication of database from live primary database.

RMAN> duplicate target database

for standby from active database

dorecover

spfile

set db_unique_name='orcl_stby' comment 'Is Standby'

nofilenamecheck;

------------------------------------------------------------------------------------------------------------------------

Enable broker on primary and standby database:

alter system set dg_broker_start=true;

------------------------------------------------------------------------------------------------------------------------

Broker configuration:

[oracle@linux1 admin]$ dgmgrl sys/oracle@orcl


DGMGRL> create configuration dg_config as primary database is orcl connect identifier is orcl;

Configuration "dg_config" created with primary database "orcl"


DGMGRL> add database orcl_stby as connect identifier is orcl_stby maintained as physical;

Database "orcl_stby" added


add database orcl_stby2 as connect identifier is orcl_stby2 maintained as physical;


DGMGRL> enable configuration;


DGMGRL> show configuration;

------------------------------------------------------------------------------------------------------------------------

Stop/Start Managed Recovery

-- Stop managed recovery.

alter database recover managed standby database cancel;


-- Start managed recovery.

alter database recover managed standby database disconnect;

or

alter database recover managed standby database disconnect nodelay;

------------------------------------------------------------------------------------------------------------------------

Database Switchover

Before process switchover or failover, always validate that everything is okay with my DataGuard environment.


DGMGRL> validate database orcl_stby


DGMGRL> switchover to orcl_stby;


$ dgmgrl sys/Password1@cdb1_stby

------------------------------------------------------------------------------------------------------------------------

Database Failover

DGMGRL> failover to orcl_stby;

------------------------------------------------------------------------------------------------------------------------

After using above failover, since the standby database is now the primary database it should be backed up immediately.


The original primary database can now be configured as a standby. If flashback database was enabled on the primary database, then this can be done relatively easily with the following command.


DGMGRL> reinstate database orcl;

------------------------------------------------------------------------------------------------------------------------

Read-Only Standby and Active Data Guard:

Once a standby database is configured, it can be opened in read-only mode to allow query access.


shutdown immediate;

startup mount;

alter database open read only;

alter database recover managed standby database disconnect from session;

------------------------------------------------------------------------------------------------------------------------

Verify Sync:


SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference" FROM (SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,(SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL WHERE ARCH.THREAD# = APPL.THREAD# ORDER BY 1;

------------------------------------------------------------------------------------------------------------------------

Check all the above changed parameters:


set linesize 500 pages 0

col value for a90

col name for a50

 

select name, value

from v$parameter

where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2',

   'log_archive_dest_3', 'log_archive_dest_4',

               'log_archive_dest_state_1','log_archive_dest_state_2', 'remote_login_passwordfile',

               'log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert',

                     'log_file_name_convert', 'standby_file_management');

------------------------------------------------------------------------------------------------------------------------

=========================================================================