Friday, March 10, 2023

Dataguard Setup

 Decide the following unique names:

Primary unique name <pri_unq>
Standby unique name <stby_unq>

On Primary:

Create pfile:

create pfile='/oracle/init_db.ora' from spfile;

Backup controlfile:

backup current controlfile for standby format '/oracle/standby_controlfile_from_primary.f';


On standby:

Replace db_unq_name in pfile to standby unique name

startup nomount pfile='/oracle/init_db.ora';


SQL> create spfile='+DATA' from pfile='/oracle/init_db.ora';

File created.

shutdown immediate
startup nomount --> using spfile

RMAN> RESTORE STANDBY CONTROLFILE FROM '/oracle/standby_controlfile_from_primary.f';

Restore backup:

RMAN> catalog start with '/<backup_location>';


$ cat rman_restore.sh
#!/bin/ksh
#
dt=$(date +"%m-%d-%Y-%H")
export ORACLE_SID=<ora_sid>
export ORACLE_HOME=<oh>
export PATH=$PATH:$ORACLE_HOME/bin
rman << EOF
connect target /;
spool log to /oracle/restore_from_<db>_$dt.log;
run
{
sql "alter session set nls_date_format = ''DD-MON-RRRR HH24:MI:SS''";
set command id to '<db>_restore_cmd';
allocate channel t1 type DISK;
allocate channel t2 type DISK;
allocate channel t3 type DISK;
allocate channel t4 type DISK;
allocate channel t5 type DISK;
allocate channel t6 type DISK;
allocate channel t7 type DISK;
allocate channel t8 type DISK;
crosscheck copy;
crosscheck backup;
delete noprompt expired copy;
delete noprompt expired backup;
delete noprompt obsolete device type disk;
catalog start with '/<backup_location>' noprompt;
restore database;
recover database;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
release channel t5;
release channel t6;
release channel t7;
release channel t8;
}
spool log off;
EOF


On Primary:

Update tns entries on source and target.

alter system set log_archive_config='dg_config=(db_unq1,db_unq2)' scope=both sid='*';

alter system set log_archive_dest_2='service=<stby_unq> ASYNC NOAFFIRM delay=0 max_failure=0 max_connections=1 reopen=300 db_unique_name="<stby_unq>" register net_timeout=180 valid_for=(online_logfile,all_roles)' scope=both sid='*';

alter system set fal_server='<stby_uni=q>','<stby_unq1>' scope=both sid='*';   --> remote

alter system set fal_client=<pri_unq> scope=both sid='*';   --> local

On Standby:

alter system set log_archive_dest_5='service=<pri_unq> ASYNC NOAFFIRM delay=0 max_failure=0 max_connections=1 reopen=300 db_unique_name="<pri_unq>" register net_timeout=180 valid_for=(online_logfile,all_roles)' scope=both sid='*';

alter system set fal_server='<pri_unq>','<stby_unq1>' scope=both sid='*';   --> remote

alter system set fal_client=<stby_unq> scope=both sid='*';   --> local


SQL> alter database recover managed standby database cancel;

SQL> alter system set standby_file_management=manual scope=both sid='*';

select group#, thread#, status, bytes from v$standby_log;

alter database drop logfile group 11;
alter database drop logfile group 12;
alter database drop logfile group 13;

SQL> alter database clear logfile group 11; --> If they are active


alter database add standby logfile thread 1 group 11 ('+REDO01','+REDO02') size 1024M;
alter database add standby logfile thread 1 group 12 ('+REDO01','+REDO02') size 1024M;
alter database add standby logfile thread 1 group 13 ('+REDO01','+REDO02') size 1024M;

SQL> alter system set standby_file_management=auto scope=both sid='*';

SQL> alter database recover managed standby database disconnect from session;

 

Register Database:
 

srvctl add database -db <stby_unq> -oraclehome /<oh> -dbtype RAC -domain domain.com -spfile +DATA/<LOC>/spfile.576.1125922719 -pwfile +DATA/<LOC>/pwd<stby_unq> -dbname <stby_db> -role physical_standby -startoption "READ ONLY"


srvctl add instance -d <stby_unq> -i <inst1> -n <node1>
 
srvctl add instance -d <stby_unq> -i <inst2> -n <node2>


srvctl setenv database -d <stby_unq> -T "ORACLE_UNQNAME=<stby_unq>"

srvctl start database -d <stby_unq> -o mount

srvctl start database -d <stby_unq> -startoption "read only"