Scaling API-first – The story of a global engineering organization
Oracle data guard configuration in 12c
1. Oracle Data Guard Configuration in 12c
This note examines how to create an Oracle 12.1.0.2.0 physical standby Active Data Guard database using
the RMAN DUPLICATE FROM ACTIVE command.
We will be creating the data guard configuration in a 12c Container Database.
IN 12c Data Guard is set up at the Container level and not the individual Pluggable database level as
the redo log files only belong to the Container database and the individual pluggable databases do not have
their own online redo log files.
The platform Solaris 10 and the primary database db_unique_name is DB12c and the db_unique_name of the
Active Standby database is STBY12c.
Primary Database Standby Database
DB Name DB12C DB12C
DB unique Name DB12C STBY12c
IP and Hostname 172.31.36.12 (Solaris12c) 172.31.36.13 (SolarisST)
Let us look at the steps involved.
Change the cat /etc/hosts for both Primary and Standby Database Machine, Thats why they can know
Each other both IP address and HostName.
hosts_standby hosts_primary
On Primary
Enable the Archive Log:
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
2. ** Please Increase The db_recovery_file_dest_size atleast 5G , by default it’s less than 1G which is fillup
in any time.
Enable the Force Logging
SQL> alter database force logging;
Database altered.
SQL> select FORCE_LOGGING from v$database;
FORCE_LOGGING
---------------------------------------
YES
On Standby
Create the required directory structure
It’s important cause when we restore RMAN backup , at that time if appropriate directory is not created then
you got error in restore.
Technique :
1. Find the location of ADUMP path of Primary database and create the same things in Standby
database.
SQL> show parameter audit_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest string /export/home/oracle/admin/DB12c/adump
So you must create below folder in Standby database
$ mkdir -p export/home/oracle/admin/DB12c/adump
2. Find the Location of db_recovery_file_dest in Primary Database and create same directory in Standby
database.
SQL> show parameter DB_Recove
3. NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /export/home/oracle/fast_recovery_area
db_recovery_file_dest_size big integer 3G
So must create below folder in Standby Database
$ mkdir -p /export/home/oracle/fast_recovery_area
3. Check The control file location in Primary Database and create same folder in Standby database.
SQL> show parameter control
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string
/export/home/oracle/oradata/DB12C/controlfile/o1_mf_bo5tnjkh_.ctl,
/export/home/oracle/fast_recovery_area/DB12C/controlfile/o1_mf_bo5tnl4q_.ctl
control_management_pack_access string DIAGNOSTIC+TUNING
So create the control file location in Standby Database
$ mkdir -p /export/home/oracle/oradata/DB12C/controlfile
$ mkdir -p /export/home/oracle/fast_recovery_area/DB12C/controlfile
4. Check the datafile location and logfile location on Primary Database and create same folder in
Standby Database.
SQL> select name from v$datafile;
/export/home/oracle/oradata/DB12C/datafile/o1_mf_system_bo5tgrz1_.dbf
....
....
SQL> select member from v$logfile;
/export/home/oracle/oradata/DB12C/onlinelog/o1_mf_3_bo5tohpf_.log
/export/home/oracle/fast_recovery_area/DB12C/onlinelog/o1_mf_3_bo5tonq9_.log
.....
.....
$ mkdir -p /export/home/oracle/oradata/DB12C/datafile
$ mkdir -p /export/home/oracle/oradata/DB12C/onlinelog
$ mkdir -p /export/home/oracle/fast_recovery_area/DB12C/onlinelog
4. Primary Database
Copy the password file from primary to standby
$ scp -rp orapwo12c
oracle@172.31.36.13:/export/home/oracle/product/12.2.0/db_1/dbs
oracle@orasql-001-test's password:
orapwo12c
100% 7680 7.5KB/s 00:00
StandBy Database
On Standby
Add a static entry in the listener.ora for STBY12c
# listener.ora Network Configuration File:
/export/home/oracle/product/12.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SolarisST)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = DB12c)
(ORACLE_HOME = /export/home/oracle/product/12.2.0/db_1)
(SID_NAME = DB12c)
)
)
listener_Standby.ora
Reload the listener
$ lsnrctl reload LISTENER
Create spfile for StandBY database input Single one line spfileDB12c.ora
6. (CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DB12c)
)
)
tnsnames_Primary.ora
On Standby
Start the Standby instance in NOMOUNT mode
Run the .profile where we mention ORACLE_SID=DB12c
.profile
bash-3.2$ . ./.profile
bash-3.2$ sqlplus
SQL*Plus: Release 12.1.0.2.0 Production on Sat May 16 13:47:30 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter user-name: sys as sysdba
Enter password:
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 229683200 bytes
Fixed Size 2286800 bytes
Variable Size 171969328 bytes
Database Buffers 50331648 bytes
Redo Buffers 5095424 bytes
Now Standby Databse in nomount stage with create spfile .
7. Primary Database:
Check the tnsping from Primary to StandBy database:
bash-3.2$ tnsping STBY12c
TNS Ping Utility for Solaris: Version 12.1.0.2.0 - Production on 16-MAY-2015 13:55:33
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
/export/home/oracle/product/12.2.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.31.36.13)(PORT =
1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DB12c)))
OK (40 msec)
Connect to Primary and auxiliary connection to Standby
bash-3.2$ rman target sys/sys auxiliary sys/sys123@STBY12c
Recovery Manager: Release 12.1.0.2.0 - Production on Sat May 16 13:54:46 2015
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: DB12C (DBID=1333620530)
connected to auxiliary database: DB12C (not mounted)
This is the command we will run to create the Standby Database.
Note – since the data file names are not being changed on the standby database we need to include the
NOFILENAMECHECK
Run
{
8. allocate channel c1 type disk;
allocate channel c2 type disk;
allocate auxiliary channel aux type disk;
duplicate target database for standby from active database nofilenamecheck spfile
set log_archive_max_processes='8'
set db_unique_name='STBY12c'
set standby_file_management='AUTO'
set log_archive_config='dg_config=(DB12c, STBY12c)'
set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles)
db_unique_name= STBY12c'
set log_Archive_dest_2='service=DB12c async noaffirm reopen=15 valid_for=(all_logfiles,primary_role)
db_unique_name=DB12c';
}
After the RMAN DUPLICATE command completes we now need to add the relevant parameters for the
redo log transport on the Primary database.
RMAN> alter system set standby_file_management='AUTO';
Statement processed
RMAN> alter system set log_archive_config='dg_config=( DB12c', STBY12c')';
Statement processed
RMAN> alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST
valid_for=(all_logfiles,all_roles) db_unique_name= DB12c'';
Statement processed
RMAN> alter system set log_Archive_dest_2='service=condb1_dr async noaffirm reopen=15
valid_for=(all_logfiles,primary_role) db_unique_name= STBY12c ';
Statement processed
In StandBY Database
Since we have 3 online redo log file groups, we need to create (3+1) 4 Standby redo log file groups
SQL> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo01.log' size 50m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo02.log' size 50m;
Database altered.
9. SQL> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo03.log' size 50m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo04.log' size 50m;
Database altered.
On Primary
RMAN> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo01.log' size 50m;
Statement processed
RMAN> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo02.log' size 50m;
Statement processed
RMAN> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo03.log' size 50m;
Statement processed
RMAN> ALTER DATABASE ADD STANDBY LOGFILE
'/export/home/oracle/oradata/DB12C/standby_redo04.log' size 50m;
Statement processed
On Primary change the protection mode
RMAN> alter database set standby database to maximize availability;
Statement processed
NOW Testing is it OK or NOT
On the Standby database, the RMAN script which we ran from the primary database has not opened the
database and started managed recovery.
10. Let us now manually do it.
On Standby
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
SQL> startup;
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2296576 bytes
Variable Size 2214593792 bytes
Database Buffers 2046820352 bytes
Redo Buffers 12070912 bytes
Database mounted.
Database opened.
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
2401331
To start the redo apply run this Standby database
recover managed standby database using current logfile disconnect;
SQL> recover managed standby database using current logfile disconnect;
Media recovery complete.
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
2442377
SQL> !ps -ef |grep mrp
oracle 1173 1 4 14:30:24 ? 0:20 ora_mrp0_DB12c
oracle 1180 1113 0 14:32:39 pts/2 0:00 /bin/sh -c ps -ef |grep mrp
oracle 1181 1180 0 14:32:39 pts/2 0:00 grep mrp
11. SQL> select process,status,thread#,sequence#,blocks from v$managed_standby where process like
'%MRP%';
PROCESS STATUS THREAD# SEQUENCE# BLOCKS
--------- ------------ ---------- ---------- ----------
MRP0 APPLYING_LOG 1 10 102400
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB12C MOUNTED
SQL> alter pluggable database all open read only;
Pluggable database altered.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB12C READ ONLY
For Pluggable Database need to Entry in TNSNAME.ORA for both primary and Standby Database.
Standby Database:
STPDB12C=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SolarisST)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PDB12C)
(UR = A)
)
)
12. Primary Database:
PDB12C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Solaris12c)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PDB12C)
)
)
On Primary Database
SQL> conn uzzal/basak@PDB12C
Connected.
SQL> select * from tab;
no rows selected
SQL> create table pp (no number(2));
Table created.
SQL> insert into pp values (1);
1 row created.
SQL> select * from pp;
NO
----------
1
SQL> commit;
Commit complete.
Check in Standby Database:
SQL> conn uzzal/basak@STPDB12C
Connected.
13. SQL> select * from pp;
NO
----------
1
Last Part Of the Data Guard is Maintaince of DataGuard :
To start the redo apply Run this
recover managed standby database using current logfile disconnect;
To Stop the redo apply Run below command
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> !ps -ef |grep mrp
oracle 1236 1224 0 15:05:25 pts/2 0:00 /bin/sh -c ps -ef |grep mrp
oracle 1237 1236 0 15:05:25 pts/2 0:00 grep mrp
SQL> select process,status,thread#,sequence#,blocks from v$managed_standby where process like
'%MRP%';
no rows selected
And Start the Redo Apply and Enjoy the Beauty of Data Guard in 12c
recover managed standby database using current logfile disconnect;
Reference Link
http://gavinsoorma.com/2013/11/creating-an-oracle-12c-data-guard-active-standby-database/