Monday, 16 July 2018

Standby database Configuration step by step

Primary Host: jcraju.prod.com
DB_NAME = proddb
DB_UNIQUE_NAME=proddb

Standby Host:jcraju.test.com
DB_NAME = proddb 
DB_UNIQUE_NAME = standby

On Primary Side:
SQL>alter system set log_archive_config='DG_CONFIG=(proddb,standby)';
SQL>alter system set log_archive_dest_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby';
SQL> alter system set fal_server=proddb;
SQL> alter system set fal_client=standby;

Add standby redo logs:
alter database add standby logfile '/u01/app/oracle/proddb/std_redo01.log' size 100M;
alter database add standby logfile '/u01/app/oracle/proddb/std_redo02.log' size 100M;
alter database add standby logfile '/u01/app/oracle/proddb/std_redo03.log' size 100M;


alter system set standby_file_management=auto;
alter system set remote_loging_passwordfile=exclusive;
 
On Standby Side: 
Copy parameetr file from  primary to standby and change db_unique_name=standby
startup db in nomount
alter system set fal_server=standby;
alter system set fal_client=proddb;

alter system set standby_file_management=auto;
alter system set remote_loging_passwordfile=exclusive;
 
Create password file in Primary:
orapwd file=/u01/app/oracle/product/12.2.0.1/db_1/dbs/orapwproddb password=manager123 entries=8 force=y

Copy password file  to Standby:
[oracle@jcraju dbs]$ scp orapwproddb oracle@jcraju.test.com:/u01/app/oracle/product/12.2.0.1/db_1/dbs
oracle@jcraju.test.com's password:
orapwproddb 


Add TNS details on both primary and standby:
proddbp =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = jcraju.prod.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = proddb)
    )
  )

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = jcraju.test.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = proddb)
    )
  )
 
Standby database using rman active duplicate :
[oracle@jcraju dbs]$ rman auxiliary sys/manager1#@standby

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Jul 17 01:27:12 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

connected to auxiliary database: PRODDB (not mounted)

RMAN> connect target sys/manager1#@proddbp
connected to target database: PRODDB (DBID=721284158)

RMAN> duplicate target database for standby from active database nofilenamecheck;

Starting Duplicate Db at 17-JUL-18
using channel ORA_AUX_DISK_1

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/12.2.0.1/db_1/dbs/orapwproddb' auxiliary format
 '/u01/app/oracle/product/12.2.0.1/db_1/dbs/orapwproddb'   ;
}
executing Memory Script

Starting backup at 17-JUL-18
using channel ORA_DISK_1
Finished backup at 17-JUL-18

contents of Memory Script:
{
   restore clone from service  'proddbp' standby controlfile;
}
executing Memory Script

Starting restore at 17-JUL-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service proddbp
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/proddb/control1.ctl
output file name=/u01/app/oracle/proddb/control2.ctl
Finished restore at 17-JUL-18

contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/proddb/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/u01/app/oracle/proddb/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/proddb/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/proddb/undotbs01.dbf";
   restore
   from  nonsparse   from service
 'proddbp'   clone database
   ;
   sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/proddb/temp01.dbf in control file

executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME

Starting restore at 17-JUL-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service proddbp
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/proddb/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service proddbp
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/proddb/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service proddbp
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/proddb/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 17-JUL-18

sql statement: alter system archive log current

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=981682445 file name=/u01/app/oracle/proddb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=981682445 file name=/u01/app/oracle/proddb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=981682445 file name=/u01/app/oracle/proddb/undotbs01.dbf
Finished Duplicate Db at 17-JUL-18

RMAN> exit

Check database status:
[oracle@jcraju dbs]$ sqlplus "/as sysdba"
SQL*Plus: Release 12.2.0.1.0 Production on Tue Jul 17 01:53:08 2018
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>select INSTANCE_NAME,host_name,status,logins, to_char(STARTUP_TIME,'DD/MM/YYYY HH24:MI:SS') "STARTUP_TIME" from gv$instance;
INSTANCE_NAME   HOST_NAME                   STATUS       LOGINS   STARTUP_TIME
---------------- ---------------------------------------- ------------ ---------- -------------------
proddb          jcraju.test.com                  MOUNTED      ALLOWED       17/07/2018 01:50:26

SQL>select database_role,open_mode,name from gv$database;
DATABASE_ROLE   OPEN_MODE       NAME
---------------- -------------------- ---------
PHYSICAL STANDBY MOUNTED         PRODDB


Start MRP Process:
SQL> alter database recover managed standby database disconnect from session;
Database altered.


Do some manual log switches on primary and check status in standby side:

SQL> SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence
Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference"
FROM
(SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX
(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,
(SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX
(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL
WHERE ARCH.THREAD# = APPL.THREAD#;  2    3    4    5    6    7    8 

    Thread Last Sequence Received Last Sequence  Applied Difference
---------- ---------------------- --------------------- ----------
      1                26            26     0

SQL> /

    Thread Last Sequence Received Last Sequence Applied Difference
---------- ---------------------- --------------------- ----------
      1                29            29     0


No comments:

Post a Comment