DataGuard
DataGuard
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
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*
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
$ sqlplus / as sysdba
SQL> SELECT log_mode FROM v$database;
SQL> Archive Log List;
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;
$ 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
Note: The ‘tnsnames.ora’ file can be transferred using scp to Standby server.
Configure Listener On Both Primary & Standby
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
$ 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
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)
$ 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)
# 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
$ sqlplus / as sysdba
SQL> STARTUP NOMOUNT PFILE=’/tmp/initorclstby.ora’;
SQL> show parameter db_name;
$ dgmgrl sys/Nepal_123@orclprmy
(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)
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
$ORACLE_SID=orclprmy (Standby)
SQL> startup open (Standby)
SQL> select name, log_mode, open_mode from v$database; (Standby)
OpenMode: Read Only with Apply
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).
Connect to the new primary (orclstby) and switchover to the new standby database
(orclprmy)
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
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