In today’s article, I will talk about Oracle Data Guard Installation.
I used Oracle Linux 7.6 and Oracle Database 19C while installing.
There are conditions that must be met in order to install Oracle Data Guard. These are as follows:
Oracle database must be Enterprise edition.
Both servers must have the same operating system.
Oracle Software must be the same version on both servers.
After these conditions are met, the necessary steps for installation can be started.
First, we install Oracle Software on the Standby server. Then we create and start the listener service using “netca”.
We write the information of the servers in the “/etc/hosts” file in the Primary and Standby databases.
1 |
vi /etc/hosts |
Settings to be made on the Primary Server:
1. The archive log mode of the database must be turned on. We check if it is open with the following command.
1 |
select log_mode from v$database; |
If the database is not in archive mode, we follow the steps below to put the database in archive mode.
We close the database consistently and open it in mount mode.
1 2 |
shutdown immediate; startup mount; |
We put the database in archive mode and open the database.
1 2 |
alter database arhivelog; alter database open; |
2. We log all transactions in the database with the following command.
1 |
alter database force logging; |
3. In the Primary, we learn the values of the “DB_NAME” and “DB_UNIQUE_NAME” parameters.
1 |
show parameter db_name |
1 |
show parameter db_unique_name |
4. We set the “LOG_ARCHIVE_CONFIG” parameter in the database.
First we write Primary database DB_UNIQUE_NAME and then we write standby database DB_UNIQUE_NAME.
1 |
alter system set log_archive_config= ‘dg_config=(ORCL,ORCLSTBY)’ |
5. We configure the “remote archive log” option in the database.
1 2 3 |
alter system set log_archive_dest_2=’SERVICE=orclstby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLSTBY’; |
1 |
alter system set log_archive_dest_state_2=enable; |
6.We set the parameters “LOG_ARCHIVE_FORMAT”, “LOG_ARCHIVE_MAX_PROCESSES”, “REMOTE_LOGIN_PASSWORDFILE” in the database as follows.
1 2 3 |
alter system set log_archive_format=’%t_%s_%r.arc’ scope=spfile; alter system set log_archive_max_processes=30; alter system set remote_login_passwordfile=exclusive scope=spfile; |
7. Considering the switchover situation, we set the following parameters so that the database is ready for migration, and then we restart the database.
1 2 3 4 |
alter system set fal_server=orcl_stby; alter system set standby_file_management=auto; shutdown immediate; startup; |
8. We edit the tnsnames.ora file on both the primary and standby server. We write standby information to the primary server and primary server information to the standby server.
1 |
vim $ORACLE_HOME/network/admin/tnsnames.ora |
9. For the switchover situation, we create a page for the standby database from the redologs in the primary database. (It is not mandatory.)
1 2 3 4 5 |
sqlplus / as sysdba alter database add standby logfile (‘/u01/app/oracle/oradata/ORCL/standby_redo01.log’) size 50m; alter database add standby logfile (‘/u01/app/oracle/oradata/ORCL/standby_redo01.log’) size 50m; alter database add standby logfile (‘/u01/app/oracle/oradata/ORCL/standby_redo02.log’) size 50m; alter database add standby logfile (‘/u01/app/oracle/oradata/ORCL/standby_redo03.log’) size 50m; |
10. We take a backup of the primary database, including archive logs.
1 2 |
rman target / backup database plus archivelog; |
11. We create control file and pfile for standby database.
1 2 |
alter database create standby controlfile as ‘/tmp/orcl_stby.ctl’; create pfile=’/tmp/initorcl_stby.ora’ from spfile; |
12. We make arrangements for the standby database in the created initorcl_stby.ora file.
1 |
vim /tmp/initorcl_stby.ora |
1 2 3 4 |
*.db_name=’orclstby’ *.db_unique_name=’ORCL_STBY’ *.fal_server=’ORCL’ *.log_archive_dest_1=’SERVICE=orcl ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL’ |
Settings to be made in Standby Server:
1.We create the necessary directories on the standby server.
1 2 3 4 5 6 7 |
mkdir -p /u01/app/oracle/oradata/ORCL_STBY cd /u01/app/oracle/oradata/ORCL_STBY mkdir controlfile datafile onlinelog mkdir -p /u01/app/oracle/fast_recovery_area/ORCL_STBY/ cd /u01/app/oracle/fast_recovery_area/ORCL_STBY/ mkdir archivelog backupset controlfile onlinelog mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump |
2.Rman backup, archive logs, created control file, pfile and password file taken on the primary server are copied to the standby server using scp.
1 |
scp /tmp/orcl_stby.ctl oracle@192.168.56.12:/u01/app/oracle/oradata/ORCL_STBY/controlfile/ |
1 |
scp /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2021_03_23/* oracle@192.168.56.12:/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2021_03_23/ |
1 |
scp -P22 /tmp/initorcl_stby.ora oracle@192.168.56.12:/u01/app/oracle/product/19.0.0/dbhome_1/dbs |
1 |
scp -P22 $ORACLE_HOME/dbs/orapworcl oracle@192.168.56.12:/u01/app/oracle/product/19.0.0/dbhome_1/dbs |
3. The Listener restarts.
1 |
lsnrctl reload |
4. We return from the backup copied from the primary database on the server.
1 2 3 4 |
export $ORACLE_SID=orcl_stby rman target / startup mount; restore database; |
5. After the necessary adjustments are made on both the primary and standby servers, we start the log apply process.
1 |
alter database recover managed standby database using current logfile disconnect |
6. We can learn whether the archive log files are applied to the standby database with the following command.
1 |
select sequence#, first_time, next_time, applied from v$archived_log order by sequence#; |