0% found this document useful (0 votes)
13 views19 pages

DataGuard

This document outlines the steps for setting up a Physical Standby Active Data Guard using Data Broker in Oracle Database 19c, including VM creation, OS preparation, and Oracle installation. It details the configuration of network settings, database creation, and Data Guard management using SQL commands and RMAN. The guide concludes with instructions for managing the primary and standby databases through the Data Guard Broker.

Uploaded by

hicata2319
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views19 pages

DataGuard

This document outlines the steps for setting up a Physical Standby Active Data Guard using Data Broker in Oracle Database 19c, including VM creation, OS preparation, and Oracle installation. It details the configuration of network settings, database creation, and Data Guard management using SQL commands and RMAN. The guide concludes with instructions for managing the primary and standby databases through the Data Guard Broker.

Uploaded by

hicata2319
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Oracle Data Guard Setup

Physical Standby Active Data Guard Setup using Data Broker in Oracle Database 19c
I. Create 2 VMs(Primary Server & Standby Server)

RAM: 8/16GB
CPU: 2/4
Disk: 50G

II. Prepare Both VMs as per Oracle’s Documentation

1. Install Linux (CentOS 8) with Required Resources


/boot – 1G
/ - 15G
/u01 – 25G
/tmp – 1G
Swap – 8G

2. Disable SELinux
# vi /etc/selinux/config
SELINUX=disabled
# setenforce 0
# getenforce
# reboot

3. Disable Firewall
# systemctl stop firewalld
# systemctl disable firewalld
4. Update CentOS 8 and Install Required Packages
# ls /etc/yum.repos.d
# yum -y update
# cd /etc/yum.repos.d
# wget http://public-yum.oracle.com/public-yum-ol7.repo
# rpm --import http://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
# yum -y install oracle-database-preinstall-19c
# yum -y install gcc-c++
# yum -y install compat-libstdc* libnsl*

5. Set password for the oracle user


# passwd oracle

6. Create required directories for the Oracle software and database


# mkdir -p /u01/app/oracle/product/19.3.0/dbhome_1
# chown -R oracle:oinstall /u01
# chmod -R 775 /u01

7. Set environment variables (Primary Server)


# vi /home/oracle/.bashrc
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME= primarydb.pis.com
export ORACLE_UNQNAME= orclprmy
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome_1
export ORA_INVENTORY=/u01/app/oraInventory
export ORACLE_SID= orclprmy
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/lib64:/usr/lib:/usr/lib64
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

8. Set environment variables (Standby Server)


# vi /home/oracle/.bashrc
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME= stdbydb.pis.com
export ORACLE_UNQNAME= orclstdby
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome_1
export ORA_INVENTORY=/u01/app/oraInventory
export ORACLE_SID= orclstdby
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/lib64:/usr/lib:/usr/lib64
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

9. Configure Network & Hostname (Primary Server)


# cd /etc/sysconfig/network-scripts/
# vi ifcfg-ens33
DEVICE="ens33"
ONBOOT="yes"
BOOTPROTO=static
IPADDR=192.168.74.201
NETMASK=255.255.255.0
GATEWAY=192.168.74.2
DNS1=192.168.74.2

# systemctl restart network


# hostnamectl set-hostname primarydb.pis.com
# hostname
# hostname –I

10. Configure Network & Hostname (Standby Server)


# cd /etc/sysconfig/network-scripts/
# vi ifcfg-ens33
DEVICE="ens33"
ONBOOT="yes"
BOOTPROTO=static
IPADDR=192.168.74.202
NETMASK=255.255.255.0
GATEWAY=192.168.74.2
DNS1=192.168.74.2

# systemctl restart network


# hostnamectl set-hostname stdbydb.pis.com
# hostname
# hostname -I

11. Add Hostname & IP Address in the /etc/hosts file on Both Servers
# vi /etc/hosts
192.168.74.201 primarydb.pis.com
192.168.74.202 stdbydb.pis.com
III. Install Oracle Database Software Only on Both the Primary & Standby Servers
Copy the Oracle Database 19c Software into $ORACLE_HOME Dir and Install Oracle
Database 19c Software
1. Set the Required Variable Value
Login as oracle user

$ vi $ORACLE_HOME/cv/admin/cvu_config
uncomment Line 20 (CV_ASSUME_DISTID=OEL5)

$ source $ORACLE_HOME/cv/admin/cvu_config
$ cd $ORACLE_HOME
$ ls
$ unzip LINUX.X64_193000_db_home.zip
$ ls
$ ./runInstall [Note: Take about 15 minutes or more to initialize in 19c, wait]
Install Software only with default settings
Note: Pre-requisite check takes about 20 minutes, so wait

IV. Create Database using DBCA (On Primary Server Only)


$ dbca
Create database with Sample Schema
No need to select Listener
V. Configuring Data Guard

Check that the primary database is in archivelog mode (On Primary)

$ sqlplus / as sysdba
SQL> SELECT log_mode FROM v$database;
SQL> Archive Log List;

If it is noarchivelog mode, switch is to archivelog mode. (On Primary)


$ sqlplus / as sysdba
SQL>SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;

SQL> ALTER DATABASE OPEN;

Enable forced logging by issuing the following command. (On Primary)


SQL> SELECT force_logging FROM v$database;
SQL> ALTER DATABASE FORCE LOGGING;
SQL> SELECT force_logging FROM v$database;

Make sure at least one logfile is present. (On Primary)

SQL> ALTER SYSTEM SWITCH LOGFILE;

Create standby redo logs on the primary database (On Primary)

The standby redo logs should be at least as big as the largest online redo log and there
should be one extra group per thread compared the online redo logs
SQL> select group#,bytes/(1024*1024) "size in MB" from v$log;
SQL> ALTER DATABASE ADD STANDBY LOGFILE
('/u01/app/oracle/oradata/ORCLPRMY/std_redo01.log') SIZE 200M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE


('/u01/app/oracle/oradata/ORCLPRMY/std_redo02.log') SIZE 200M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE


('/u01/app/oracle/oradata/ORCLPRMY/std_redo03.log') SIZE 200M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE


('/u01/app/oracle/oradata/ORCLPRMY/std_redo04.log') SIZE 200M;

Enable Flashback Database (On Both Primary & Standby)

SQL> SELECT flashback_on FROM v$database;


SQL> ALTER DATABASE FLASHBACK ON;

View db_name & db_unique_name Initialization Parameters. Both should be set to


“orclprmy” (On Primary)

SQL> show parameter db_name


SQL> show parameter db_unique_name

Make sure the STANDBY_FILE_MANAGEMENT parameter is set to Auto (On Primary)

SQL> Show parameter STANDBY_FILE_MANAGEMENT;

SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO Scope=both;


Configure tnsnames.ora (On Both Primary & Standaby) – Send the same file to the
Standby Server using scp

$ vi $ORACLE_HOME/network/admin/tnsnames.ora
orclprmy =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = primarydb.pis.com)(PORT = 1521))
)

(CONNECT_DATA =
(SID = orclprmy) ##### NOTE: SERVICE_NAME should be replaced with SID
) ##### SID value should NOT be full name but just name
) #### like ‘orclprmy’ NOT ‘orclprmy.pis.com’

orclstby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = stdbydb.pis.com)(PORT = 1521))
)

(CONNECT_DATA =
(SID = orclprmy) ### Take care of SID name
)
)
OR

$ netmgr
netmgr --> service naming --> + -->
Net Service name: orclprmy
Protocol: TCP/IP
Hostname: primrydb.pis.com
Port: 1521
Service Name: orclprmy
Connection Type: database default
Select: Use Oracle release 8.0 compatible identification
SID: orclprmy

service naming --> + -->


Net Service name: orclstby
Protocol: TCP/IP
Hostname: stdbydb.pis.com
Port: 1521
Service Name: orclprmy # Take care, name should be ‘orclprmy’
Connection Type: database default
Select: Use Oracle release 8.0 compatible identification

SID: orclprmy # Take care, name should be ‘orclprmy’

Note: The ‘tnsnames.ora’ file can be transferred using scp to Standby server.
Configure Listener On Both Primary & Standby

$ netmgr (On Primary)

Listeners --
Listener Name: LISTENER
Listening Location (Select from Drop Down)
Add Address
Protocol: TCP/IP
Host: primarydb.pis.com
Port: 1521
Database Services (Select from Drop Down)
Add Database
Global Database Name: orclprmy_DGMGRL
Oracle Home Directory: default
SID: orclprmy

Add Address # ADD MANUALLY


Protocol: TCP/IP
Key: EXTPROC1521
--> File --> Save network configuration

$ cat $ORACLE_HOME/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primarydb.pis.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orclprmy_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1)
(SID_NAME = orclprmy)
)
)
ADR_BASE_LISTENER = /u01/app/oracle

$ netmgr (On Standby)

Listeners --
Listener Name: LISTENER
Listening Location (Select from Drop Down)
Add Address
Protocol: TCP/IP
Host: stdbydb.pis.com
Port: 1521
Database Services (Select from Drop Down)
Add Database
Global Database Name: orclstby_DGMGRL
Oracle Home Directory: default
SID: orclprmy (Note: SID should be orclprmy)

Add Address ## ADD MANUALLY


Protocol: TCP/IP
Key: EXTPROC1521
--> File --> Save network configuration

$ cat $ORACLE_HOME/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = stdbydb.pis.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orclstby_DGMGRL)

(ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1)
(SID_NAME = orclprmy) ### Take care of SID_NAME
)
)
ADR_BASE_LISTENER = /u01/app/oracle
$ lsnrctl stop (Both the Servers)

$ lsnrctl start (Both the Servers)

Create Initialization Parameter File (On Standby)

$ vi /tmp/initorclstby.ora (On Standby)


*.db_name='orclprmy'

Create the necessary directories (On the Standby Server)

# mkdir -p /u02/data/orclprmy/pdbseed (Only if container database has to be created)


# mkdir -p /u02/data/orclprmy/pdb1 (Only if container database has to be created)

# mkdir -p /u01/app/oracle/fast_recovery_area/ORCLPRMY/
# mkdir -p /u01/app/oracle/recovery_area/ORCLPRMY/
# mkdir -p /u01/app/oracle/oradata/ORCLPRMY/
# mkdir -p /u01/app/oracle/admin/orclprmy/adump/

Create a password file, with the SYS password matching that of the primary database
(On Standby) – OR send a copy of the password file from the primary server to the
standby server.

$ scp $ORACLE_HOME/dbs/orapworclprmy
oracle@stdbydb.pis.com:$ORACLE_HOME/dbs/orapworclprmy (On Server)
OR
$ orapwd file=/u01/app/oracle/product/19.3.0/dbhome_1/dbs/orapworclprmy
password=Nepal_123 entries=10

Create Standby Database Using RMAN’s DUPLICATE Command (On Standby)


$ export ORACLE_SID=orclprmy # NOTE: value of oracle_sid should be ‘orclprmy’

$ sqlplus / as sysdba
SQL> STARTUP NOMOUNT PFILE=’/tmp/initorclstby.ora’;
SQL> show parameter db_name;

$ rman TARGET sys/Nepal_123@orclprmy AUXILIARY sys/Nepal_123@orclstby


[Note: Run the above command as it is]

RMAN> DUPLICATE TARGET DATABASE


FOR STANDBY
FROM ACTIVE DATABASE
DORECOVER
SPFILE
SET db_unique_name='orclstby' COMMENT 'Is standby 19c'
NOFILENAMECHECK;

$ sqlplus / as sysdba (stdbydb)


SQL> select status from v$instance;
MOUNTED
SQL> select name, open_mode, log_mode from v$database;
ORCLPRMY ARCHIVELOG MOUNTED

$ sqlplus / as sysdba (primarydb)


SQL> select status from v$instance;
OPEN
SQL> select name, open_mode, log_mode from v$database;
ORCLPRMY ARCHIVELOG READ WRITE

VI. Managing Primary and Standby Databases Using Data Broker

Enable Broker (On Both Primary & Standby)

SQL> ALTER SYSTEM SET dg_broker_start=true scope=both;

Register the Database with Broker (On Primary)

$ dgmgrl sys/Nepal_123@orclprmy

DGMGRL> CREATE CONFIGURATION dg_config AS PRIMARY DATABASE IS


orclprmy CONNECT IDENTIFIER IS orclprmy;

Now add the standby database (On Primary)

DGMGRL> ADD DATABASE orclstby AS CONNECT IDENTIFIER IS orclstby


MAINTAINED AS PHYSICAL;

Now we enable the new configuration (On Primary)

DGMGRL> ENABLE CONFIGURATION;

(If does not succeed in first attempt, run it again till status is SUCESS)

Check the configuration and status of the databases from the broker (On Primary)

DGMGRL> SHOW CONFIGURATION;


DGMGRL> SHOW DATABASE orclprmy;

DGMGRL> SHOW DATABASE orclstby;

On Primary
$ ORACLE_SID=orclprmy
SQL> select name, log_mode, open_mode from v$database;

On Standby
$ ORACLE_SID=orclprmy
SQL> select name, log_mode, open_mode from v$database;
SQL> alter database open; (Standby database will be open in READ ONLY mode)
SQL> select name, log_mode, open_mode from v$database;

On Standby
SQL> Select salary from hr.employees where employee_id=120;

On Primary
SQL> Select salary from hr.employees where employee_id=120;
SQL> Update hr.employees set salary=2*salary where employee_id=120;
SQL> commit;
SQL> Select salary from hr.employees where employee_id=120;

On Standby
SQL> Select salary from hr.employees where employee_id=120;
(salary should have been changed in standby as well)
SQL> update hr.employees set salary=2*salary where employee_id=120;
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

After Restart of the Primary & Standby Databases, Start in the Following Sequence

$ lsnrctl start (Primary)


$ lsnrctl start (Standby)

SQL> startup open (Primary)


SQL> select name, log_mode, open_mode from v$database; (Primary)
OpenMode: Read-Write

$ORACLE_SID=orclprmy (Standby)
SQL> startup open (Standby)
SQL> select name, log_mode, open_mode from v$database; (Standby)
OpenMode: Read Only with Apply

$ dgmgrl sys/Nepal_123@orclprmy (Primary)


DGMGRL> show configuration;
DGMGRL> enable configuration (If any error is shown)
DGMGRL> show configuration; (run it until both the primary & standby are file)

VI. Database Switchover

A database can be in one of two mutually exclusive modes (primary or standby). These
roles can be altered at runtime without loss of data or resetting of redo logs. This
process is known as a Switchover and can be performed using the following
commands.
Connect to the primary database (orclprmy) and switchover to the standby database
(orclstby).

$ dgmgrl sys/Nepal_123@orclprmy (On Primary)

DGMGRL> SHOW CONFIGURATION;


DGMGRL> SWITCHOVER TO orclstby;
DGMGRL> SHOW CONFIGURATION;

Connect to the new primary (orclstby) and switchover to the new standby database
(orclprmy)

$ dgmgrl sys/Nepal_123@orclstby (On Standby)

DGMGRL> SWITCHOVER TO orclprmy;


DGMGRL> SHOW CONFIGURATION; #RUN FOR MULTIPLE TIMES UNTIL SUCCES

Open the Primary Server (Now Standyby) manually


SQL> startup open;

VII. Database Failover

If the primary database is not available, the standby database can be activated as a
primary database using the following statements.

Connect to the standby database (orclprmy ) and failover supposing the primary
(orclstby) has crashed
$ dgmgrl sys/oracle@orclprmy

DGMGRL> show configuration;


DGMGRL> FAILOVER TO orclprmy;
DGMGRL> show configuration;

Since the standby database is now the primary database it should be backed up
immediately. (On Standby)

$ rman target /
RMAN> backup database plus archivelog;

The original primary database can now be configured as a standby (On Primary)

If flashback database was enabled on the primary database, then this can be done
relatively easily with the following command.

$ dgmgrl sys/Nepal_123@orclprmy

DGMGRL> REINSTATE DATABASE orclstby;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy