Wednesday, 4 November 2015

all concepts in dataguard /. Switchover of Databases (Primary to standby and standby to primary) in Dataguard oracle 11g.


Step by step guide to convert physical standby database into snapshot standby database (READ WRITE mode)


 What is Standby snapshot Database?
Oracle provides an unique feature where the physical standby database can be opened in READ WRITE mode to perform update able transactions.
A snapshot standby database is a fully updatable standby database that is created by converting a physical standby database into a snapshot standby database. A snapshot standby database
receives and archives, but does not apply redo data from a primary database. Redo data received from the primary database is applied when a snapshot standby database is converted back
into a physical standby database, after discarding all local updates to the snapshot standby database.

A snapshot standby database typically diverges from its primary database over time because redo data from the primary database is not applied as it is received. Local updates to the
snapshot standby database will cause additional divergence. The data in the primary database is fully protected however, because a snapshot standby can be converted back into a
physical standby database at any time, and the redo data received from the primary will then be applied.

A snapshot standby database will allow you to make use of the data available on the physical standby database (which is the same data of the primary database), which allows the users
to test the application on a standby database which has the primary database's data before implementing it into production environment. Whenever a physical standby database is converted
into a snapshot standby database, a guaranteed restore point is automatically created. Once when the updateable transactions are completed for testing purposes on the snapshot standby
database and when you are converting back the snapshot standby to physical standby, oracle flashbacks to the restore point that was created earlier which means the transactions
which were made in standby database while it was open in READ WRITE mode will be flushed out.

The only requirement to have the snapshot standby is that FRA (Flash Recovery Area) must be configured on physical standby database. It is not necessary to have flashback enabled.
Below are the steps on how to convert a physical standby database to a snapshot standby database and viceversa.

Oracle version :-  11.2.0.1.0
Primary Database : prim
Standby Database : stand

Lets find out few datails from both database.
On primary database:-

SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
OPEN         prim             PRIMARY          READ WRITE

Find out current Log sequence  number.
SQL> select thread#,max(sequence#) from v$archived_log group by thread#;
  THREAD# MAX(SEQUENCE#)
---------- --------------
         1             23


Now at Standby database :-

SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;
STATUS       INSTANCE_NAME     DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
OPEN         stand            PHYSICAL   STANDBY READ ONLY WITH APPLY
 
Current Log sequence number at standby :-

SQL> select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;
   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             23

Also lets find out if Flashback is enabled or not.
SQL>  select flashback_on from v$database;

FLASHBACK_ON
------------------
NO


So we can see that the standby database in sync with the primary database.
Also the output of below command shows that the Flash Recovery Area is configured on standby database.

SQL> show parameter DB_RECOVERY_FILE_DEST

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/flash_recovery
                                                 _area
db_recovery_file_dest_size           big integer 3882M


Now Cancel the MRP Process in Standby database and restart it into mount stage.
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             310380536 bytes
Database Buffers           96468992 bytes
Redo Buffers                4308992 bytes
Database mounted.



Now Once the standby database is mounted, convert the Physical standby database to snapshot standby database.

SQL> alter database convert to snapshot standby;

Database altered.

Now open the database and check its open mode.
SQL> alter database open;

Database altered.

SQL>  select status,instance_name,database_role,open_mode from v$database,v$Instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
OPEN         stand            SNAPSHOT STANDBY READ WRITE

So we can see the database has been opened into read write mode.
Now lets test the scenario
Here on standby database we will do the following things.
1. Create a user called "snapshotstd"
2. Create a table called "test" whose owner is "snapshotstd" and insert some records in it.

SQL> create user snapshotstd identified by snapshotstd;

User created.

SQL> grant connect , resource to snapshotstd;                                                                

Grant succeeded.

SQL> conn snapshotstd/snapshotstd
Connected.
SQL> create table employees (name char(20) , Age number );

Table created.

SQL> insert into employees values ('SOUMYA' , '30' );

1 row created.
SQL> insert into employees values ('UDIT' , '24');

1 row created.

SQL> insert into employees values ('ABHISHEK' ,'25');

1 row created.

SQL> COMMIT;

Commit complete.

SQL> select * from employees;

NAME         AGE
------------ ----------
SOUMYA       30
UDIT         24
ABHISHEK     25

SQL> update employees set age=25 where name ='UDIT';

1 row updated.

SQL> Commit;

Commit complete.

SQL> select * from employees;

NAME         AGE
------------ ----------
SOUMYA       30
UDIT         25
ABHISHEK     25                                                    

Now at primary database:-
Lets update a table on primary database and see if its going to be replicated on physical standby when the database is converted.

SQL> conn  soumya/soumya
connected

SQL> create table xyz (id number);

Table created.

SQL> insert into xyz values (1);

1 row created.

SQL> /

1 row created.

SQL> commit;

On primary database:-
SQL> select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             26
 

On standby database:-

SQL>  select process,status,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CLOSING              25
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CLOSING              26
RFS       IDLE                  0
RFS       IDLE                 27

So we can see that the redo data from the primary database is received by the snapshot standby database but it was has been applied.


At standby database shut down the dbase and start it in mount stage:-
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             310380536 bytes
Database Buffers           96468992 bytes
Redo Buffers                4308992 bytes
Database mounted.

Now Lets convert back the snapshot standby database into physical standby database.
SQL> alter database convert to physical standby;

Database altered.

Once done, bounce the physical standby database and start the Managed Recovery Process (MRP) on it.

SQL> shut immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             310380536 bytes
Database Buffers           96468992 bytes
Redo Buffers                4308992 bytes
Database mounted.
Database opened.
SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
OPEN         stand            PHYSICAL STANDBY READ ONLY


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

Database altered.

SQL> select process,status,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CLOSING              28
RFS       IDLE                  0
RFS       IDLE                 29
MRP0      WAIT_FOR_LOG         29

7 rows selected.

SQL> select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             28
 
 
Crosscheck whether the physical standby database is in sync with the primary database.

On primary:-
SQL> select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             28

On standby:-
SQL> select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             28

Now we can see 

SQL> select * from snapshotstd.employees;
select * from snapshotstd.employees
                          *
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> Select username,account_status from dba_users where username='SNAPSHOTSTD';

no rows selected


We can see above that the transactions that were carried out when the standby database was opened in READ WRITE mode are flushed out after it was converted back to physical standby
database mode.

Also,
SQL> select * from soumya.xyz;

        ID
----------
         1
         1

So also we see when the standby database was converted into snapshot database, the datas updated in primary database has also replicated into physical standby database now.

Done..




Please share your ideas and opinions about this topic.

If you like this post, then please share with others.
Please subscribe on email for every updates on mail.

Perform Tablespace Point in time Recovery (TSPITR) in Dataguard Enviroment on oracle 11g

Scenario:- I had a requirement where i needed to recover a table at a specific time on primary database.
So i did TSPITR on primary database and then recreated the standby database.Flashback Database was  not enabled in my database hence i had to recreate the standby database. Here are the steps i followed.

Oracle version : 11.2.0.1.0 Enterprise Edition
OS : Rhel 6.4
Primary Database : prim
Standby Database : stand
Table Name          : TEST

Step 1:-First lets create a sample table to test the scenario.
[oracle@server2 ~]$sqlplus / as sysdba

SQL>create tablespace testtbs datafile '/u01/app/oracle/oradata/prim/testtbs.dbf' size 50M maxsize unlimited autoextend on;
Tablespace created.

SQL> create user soumya identified by soumya default tablespace testtbs quota unlimited on testtbs;
User created.

SQL> grant connect , resource to soumya;
Grant succeeded.

sql> conn soumya/soumya

SQL> create table test (id number);
SQL> insert into test values (1);
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created
SQL> commit;

SQL> select table_name ,tablespace_name from user_tables where table_name ='TEST';
TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
TEST                           TESTTBS


SQL> select * from test;

        ID
----------
         1
         1
         1
         1
         1
       
SQL> select to_char(sysdate,'DD-MON-YYYY HH24:MI:SS') from dual;

TO_CHAR(SYSDATE,'DD-MON-YYYYH)
------------------------------
28-DEC-2014 00:47:03


**********Important*******
Make sure that you have a valid RMAN level 0 backup to proceed.
Now lets drop the table and purge recyclebin too.

SQL> drop table test;

Table dropped.

SQL> purge recyclebin;

Recyclebin purged.

SQL> select * from test;
select * from test
              *
ERROR at line 1:
ORA-00942: table or view does not exist

Now We will perform the tablespace point in time recovery until the time before the table was dropped.

For TSPITR, we need to specify the auxiliary destination where RMAN would create a temporary database
by restoring the controlfile, SYSTEM tablespace, UNDO tablespace, SYSAUX tablespace and finally the
tablespace that needs to be recovered.Once the temporary database is restored and recovered, RMAN
automatically exports the contents of tablespace to be recovered from the temproary tablespace to a dump
file and imports this dump into the Target(Main) database where the table was dropped.

[oracle@server2]$ RMAN> run
{
recover tablespace TESTTBS until time "to_date('2014-12-28:00:47:03','YYYY-MM:DD:HH24:MI:SS')" auxiliary destination '/u01';
};

Starting recover at 20-SEP-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=29 device type=DISK
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1

Creating automatic instance, with SID='DFCz'

initialization parameters used for automatic instance:
db_name=PRIM
db_unique_name=DFCz_tspitr_PRIM
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/u01
log_archive_dest_1='location=/u01'
#No auxiliary parameter file used


starting up automatic instance PRIM

Oracle instance started

Total System Global Area     292278272 bytes

Fixed Size                     2212736 bytes
Variable Size                100666496 bytes
Database Buffers             184549376 bytes
Redo Buffers                   4849664 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2014-12-28:00:47:03','YYYY-MM:DD:HH24:MI:SS')";
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 20-SEP-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/200914_071833/control_PRIM_c-1366623577-20140920-08
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/200914_071833/control_PRIM_c-1366623577-20140920-08 tag=TAG20140920T072109
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/PRIM/controlfile/o1_mf_b1sqnht0_.ctl
Finished restore at 20-SEP-14

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2014-12-28:00:47:03','YYYY-MM:DD:HH24:MI:SS')";
plsql <<<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'TESTTBS' ||' offline immediate';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
set newname for datafile  8 to
 "/u01/app/oracle/oradata/PRIM/testtbs.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2, 8;
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace TESTTBS offline immediate

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /u01/PRIM/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 20-SEP-14
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/PRIM/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/200914_065249/full_PRIM_20140920_858754372_17_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/200914_065249/full_PRIM_20140920_858754372_17_1 tag=TAG20140920T065252
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/PRIM/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/PRIM/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/PRIM/testtbs.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/200914_071833/full_PRIM_20140920_858755915_24_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/200914_071833/full_PRIM_20140920_858755915_24_1 tag=TAG20140920T071834
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 20-SEP-14

datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=858756425 file name=/u01/PRIM/datafile/o1_mf_system_b1sqot67_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=858756425 file name=/u01/PRIM/datafile/o1_mf_undotbs1_b1sqot9h_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=858756425 file name=/u01/PRIM/datafile/o1_mf_sysaux_b1sqnphr_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2014-09-20:07:22:29','YYYY-MM:DD:HH24:MI:SS')";
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
sql clone "alter database datafile  8 online";
# recover and open resetlogs
recover clone database tablespace  "TESTTBS", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  8 online

Starting recover at 20-SEP-14
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting incremental datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/PRIM/datafile/o1_mf_sysaux_b1sqnphr_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/inc_level_1/200914_071502/inc_level_1_PRIM_20140920_858755714_21_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/inc_level_1/200914_071502/inc_level_1_PRIM_20140920_858755714_21_1 tag=TAG20140920T071513
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery

archived log for thread 1 with sequence 18 is already on disk as file /u01/1_18_838842842.dbf
archived log for thread 1 with sequence 19 is already on disk as file /u01/1_19_838842842.dbf
archived log for thread 1 with sequence 20 is already on disk as file /u01/1_20_838842842.dbf
archived log file name=/u01/1_18_838842842.dbf thread=1 sequence=18
archived log file name=/u01/1_19_838842842.dbf thread=1 sequence=19
archived log file name=/u01/1_20_838842842.dbf thread=1 sequence=20
media recovery complete, elapsed time: 00:00:00
Finished recover at 20-SEP-14

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace  TESTTBS read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01''";
}
executing Memory Script

sql statement: alter tablespace  TESTTBS read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_DFCz": 
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_DFCz" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_DFCz is:
   EXPDP>   /u01/tspitr_DFCz_62260.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace TESTTBS:
   EXPDP>   /u01/app/oracle/oradata/PRIM/testtbs.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_DFCz" successfully completed at 07:28:42
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace  TESTTBS including contents keep datafiles';
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

sql statement: drop tablespace  TESTTBS including contents keep datafiles

Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_DFCz" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_DFCz": 
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_DFCz" successfully completed at 07:29:27
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace  TESTTBS read write';
sql 'alter tablespace  TESTTBS offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace  TESTTBS read write

sql statement: alter tablespace  TESTTBS offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/PRIM/datafile/o1_mf_temp_b1sqqxbb_.tmp deleted
auxiliary instance file /u01/PRIM/onlinelog/o1_mf_3_b1sqqsvf_.log deleted
auxiliary instance file /u01/PRIM/onlinelog/o1_mf_2_b1sqqql5_.log deleted
auxiliary instance file /u01/PRIM/onlinelog/o1_mf_1_b1sqqo4d_.log deleted
auxiliary instance file /u01/PRIM/datafile/o1_mf_sysaux_b1sqnphr_.dbf deleted
auxiliary instance file /u01/PRIM/datafile/o1_mf_undotbs1_b1sqot9h_.dbf deleted
auxiliary instance file /u01/PRIM/datafile/o1_mf_system_b1sqot67_.dbf deleted
auxiliary instance file /u01/PRIM/controlfile/o1_mf_b1sqnht0_.ctl deleted
Finished recover at 28-DEC-14

Once the import is done successfully, RMAN automatically deletes the temporary database that it had
created earlier.Now, lets connect to the main database and check if we are able to access the dropped
table. But, before that, we need to bring the tablespace online.


SQL>  set linesize 100
SQL> col name for a60
SQL> select name,status from v$datafile;

NAME                                                         STATUS
------------------------------------------------------------ -------
/u01/app/oracle/oradata/orcl/system01.dbf                    SYSTEM
/u01/app/oracle/oradata/orcl/sysaux01.dbf                    ONLINE
/u01/app/oracle/oradata/orcl/undotbs01.dbf                   ONLINE
/u01/app/oracle/oradata/orcl/users01.dbf                     ONLINE
/u01/app/oracle/oradata/orcl/example01.dbf                   ONLINE
/u01/app/oracle/oradata/orcl/TS_HYBRIS_DATA.dbf              OFFLINE
/u01/app/oracle/oradata/orcl/TS_HYBRIS_INDEX.dbf             ONLINE
/u01/app/oracle/oradata/orcl/testtbs.dbf                     OFFLINE

8 rows selected.

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TS_HYBRIS_DATA                 OFFLINE
TS_HYBRIS_INDEX                ONLINE
TESTTBS                        OFFLINE


We can notice that the tablespace TESTTBS and TS_HYBRIS_DATA are offline. Before proceeding, this
tablespaces needs to be made online.

SQL> alter tablespace TS_HYBRIS_DATA online;

Tablespace altered.

SQL> alter tablespace testtbs online;

Tablespace altered.

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TS_HYBRIS_DATA                 ONLINE
TS_HYBRIS_INDEX                ONLINE
TESTTBS                        ONLINE

SQL> conn soumya/soumya;
Connected.

SQL> SELECT * FROM test;

        ID
----------
         1
         1
         1
         1
         1
       
Finally we can see the dropped table is back with its data inside it.       


Now we have to recreate the standby database afresh.
At standby database shut down the database:-
SQL>shut immediate;

Now delete all the datafiles,redolog files, controlfiles.
[oracle@server3]$cd /u01/app/oracle/oradata/stand/
[oracle@server3]$ rm -rf *.ctl *.log *.dbf

Now start the instance in nomount mode with minimal options

[oracle@server3] cd /u01/app/oracle/product/11.2.0/db_1/
[oracle@server3] vi initstand.ora
DB_NAME=prim
DB_UNIQUE_NAME=stand
DB_BLOCK_SIZE=8192

:wq

[oracle@server3]sqlplus / as sysdba
startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/initstand.ora';
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             339740664 bytes
Database Buffers           67108864 bytes
Redo Buffers                4308992 bytes
Database mounted.
Database opened.

SQL>exit

Now we will create the following RMAN run commands and  the changes to the standby’s spfile in this RMAN block.
[oracle@server2 ]rman target sys/redhat@prim auxiliary sys/redhat@stand   
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Sep 7 14:43:25 2015

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

connected to target database: PRIM (DBID=4130009889)
connected to auxiliary database: PRIM (not mounted)

RMAN>run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
parameter_value_convert 'prim','stand'
set db_unique_name='stand'
set db_file_name_convert='/u01/app/oracle/oradata/prim/','/u01/app/oracle/oradata/stand/'
set log_file_name_convert='/u01/app/oracle/oradata/prim/','/u01/app/oracle/oradata/stand/'
set control_files='/u01/app/oracle/oradata/stand/control01.ctl','/u01/app/oracle/oradata/stand/control02.ctl'
set log_archive_max_processes='10'
set fal_client='stand'
set fal_server='prim'
set standby_file_management='AUTO'
set log_archive_config='dg_config=(prim,stand)'
set log_archive_dest_2='service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim'
;
}
using target database control file instead of recovery catalog
allocated channel: prmy1
channel prmy1: SID=32 device type=DISK

allocated channel: prmy2
channel prmy2: SID=33 device type=DISK

allocated channel: prmy3
channel prmy3: SID=34 device type=DISK

allocated channel: prmy4
channel prmy4: SID=35 device type=DISK

allocated channel: stby
channel stby: SID=19 device type=DISK

Starting Duplicate Db at 16-MAY-13

contents of Memory Script:
{
 backup as copy reuse
 targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwprim' auxiliary format
 '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwstand' targetfile
 '/u01/app/oracle/product/11.2.0/db_1/dbs/spfileprim.ora' auxiliary format
 '/u01/app/oracle/product/11.2.0/db_1/dbs/spfilestand.ora' ;
 sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfilestand.ora''";
}
executing Memory Script

Starting backup at 16-MAY-13
Finished backup at 16-MAY-13

sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfilestand.ora''

contents of Memory Script:
{
 sql clone "alter system set audit_file_dest =
 ''/u01/app/oracle/oradata/dump/stand/adump'' comment=
 '''' scope=spfile";
 sql clone "alter system set diagnostic_dest =
 ''/u01/app/oracle/oradata/dump/stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_dest_1 =
 ''location=use_db_recovery_file_dest valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set db_unique_name =
 ''stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set db_file_name_convert =
 ''/u01/app/oracle/oradata/prim/prim/datafile/'', ''/u01/app/oracle/oradata/stand/stand/datafile/'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_file_name_convert =
 ''/u01/app/oracle/oradata/prim/prim/onlinelog/'', ''/u01/app/oracle/oradata/stand/stand/onlinelog/'' comment=
 '''' scope=spfile";
 sql clone "alter system set control_files =
 ''/u01/app/oracle/oradata/stand/control/control01.ctl'', ''/u01/app/oracle/oradata/stand/control/control02.ctl'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_max_processes =
 10 comment=
 '''' scope=spfile";
 sql clone "alter system set fal_client =
 ''stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set fal_server =
 ''prim'' comment=
 '''' scope=spfile";
 sql clone "alter system set standby_file_management =
 ''AUTO'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_config =
 ''dg_config=(prim,stand)'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_dest_2 =
 ''service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim'' comment=
 '''' scope=spfile";
 shutdown clone immediate;
 startup clone nomount;
}
executing Memory Script

sql statement: alter system set audit_file_dest = ''/u01/app/oracle/oradata/dump/stand/adump'' comment= '''' scope=spfile

sql statement: alter system set diagnostic_dest = ''/u01/app/oracle/oradata/dump/stand'' comment= '''' scope=spfile

sql statement: alter system set log_archive_dest_1 = ''location=use_db_recovery_file_dest valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=stand'' comment= '''' scope=spfile

sql statement: alter system set db_unique_name = ''stand'' comment= '''' scope=spfile

sql statement: alter system set db_file_name_convert = ''/u01/app/oracle/oradata/prim/prim/datafile/'', ''/u01/app/oracle/oradata/stand/stand/datafile/'' comment= '''' scope=spfile

sql statement: alter system set log_file_name_convert = ''/u01/app/oracle/oradata/prim/prim/onlinelog/'', ''/u01/app/oracle/oradata/stand/stand/onlinelog/'' comment= '''' scope=spfile

sql statement: alter system set control_files = ''/u01/app/oracle/oradata/stand/control/control01.ctl'', ''/u01/app/oracle/oradata/stand/control/control02.ctl'' comment= '''' scope=spfile

sql statement: alter system set log_archive_max_processes = 10 comment= '''' scope=spfile

sql statement: alter system set fal_client = ''stand'' comment= '''' scope=spfile

sql statement: alter system set fal_server = ''prim'' comment= '''' scope=spfile

sql statement: alter system set standby_file_management = ''AUTO'' comment= '''' scope=spfile

sql statement: alter system set log_archive_config = ''dg_config=(prim,stand)'' comment= '''' scope=spfile

sql statement: alter system set log_archive_dest_2 = ''service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim'' comment= '''' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 534462464 bytes

Fixed Size 2230072 bytes
Variable Size 163580104 bytes
Database Buffers 364904448 bytes
Redo Buffers 3747840 bytes
allocated channel: stby
channel stby: SID=18 device type=DISK

contents of Memory Script:
{
 backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/stand/control/control01.ctl';
 restore clone controlfile to '/u01/app/oracle/oradata/stand/control/control02.ctl' from
 '/u01/app/oracle/oradata/stand/control/control01.ctl';
}
executing Memory Script

Starting backup at 16-MAY-13
channel prmy1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_prim.f tag=TAG20130516T084319 RECID=7 STAMP=815561001
channel prmy1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 16-MAY-13

Starting restore at 16-MAY-13

channel stby: copied control file copy
Finished restore at 16-MAY-13

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/oradata/stand/stand/datafile/o1_mf_temp_8qbok7fk_.tmp";
 switch clone tempfile all;
 set newname for datafile 1 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf";
 set newname for datafile 2 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf";
 set newname for datafile 3 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf";
 set newname for datafile 4 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf";
 backup as copy reuse
 datafile 1 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf" datafile
 2 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf" datafile
 3 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf" datafile
 4 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf" ;
 sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/stand/stand/datafile/o1_mf_temp_8qbok7fk_.tmp in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 16-MAY-13
channel prmy1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_system_8ocl7bho_.dbf
channel prmy2: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_sysaux_8ocl7k6n_.dbf
channel prmy3: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf
channel prmy4: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_users_8qbolh3g_.dbf
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf tag=TAG20130516T084335
channel prmy3: datafile copy complete, elapsed time: 00:00:45
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf tag=TAG20130516T084335
channel prmy4: datafile copy complete, elapsed time: 00:00:55
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf tag=TAG20130516T084335
channel prmy1: datafile copy complete, elapsed time: 00:01:05
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf tag=TAG20130516T084335
channel prmy2: datafile copy complete, elapsed time: 00:01:05
Finished backup at 16-MAY-13

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=7 STAMP=815561103 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=815561104 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=815561104 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=815561104 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf
Finished Duplicate Db at 16-MAY-13
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4
released channel: stby

RMAN> exit

Now at standby database:-

SQL>shut immediate;
SQL>startup mount
SQL>alter database recover managed standby database disconnect from session;

Now for real time apply:-

SQL> alter database recover managed standby database cancel;

SQL> alter database open;

SQL> alter database recover managed standby database using current logfile disconnect from session;

SQL>select open_mode from v$database; (Output : read only with apply)

SQL> conn soumya/soumya
SQL> SELECT * FROM test;

        ID
----------
         1
         1
         1
         1
         1





Please share your ideas and opinions about this topic.

If you like this post, then please share with others.
Please subscribe on email for every updates on mail.
 

Creating a physical standby database on Oracle 11.2.0.1.0 using RMAN

Creating a physical standby database on Oracle 11.2.0.1.0 using RMAN :-

OS Version:-Red Hat Enterprise Linux Server release 6.4
Oracle version:- Oracle Database 12c Enterprise Edition Release 11.2.0.1.0 64bit
Primary database:- prim   
Standby database:- stand

System Configuration

primary server:-

edit the following files

vi /etc/hosts

192.168.2.102   server1.soumya.com      server1
192.168.2.104   server2.soumya.com      server2

:wq

vi /etc/sysconfig/network
HOSTNAME=server1.soumya.com

:wq

vi /etc/sysconfig/network-scripts/ifcfg-eth0

NETMASK=255.255.255.0
IPADDR=192.168.2.102
GATEWAY=192.168.2.1

:wq

Standby Server:-

edit the following files

vi /etc/hosts

192.168.2.102   server1.soumya.com      server1
192.168.2.104   server2.soumya.com      server2
:wq

vi /etc/sysconfig/network

HOSTNAME=server2.soumya.com

:wq

vi /etc/sysconfig/network-scripts/ifcfg-eth0

NETMASK=255.255.255.0
IPADDR=192.168.2.104
GATEWAY=192.168.2.1

:wq

In both server-- # service network restart
                 # service NetworkManager restart
                 # service iptables stop
                 # chkconfig iptables off
                 #vi /etc/selinux/config and disable selinux .
                  After changing inside the file please restart the server.       
               
We have a database called prim on primary server and  we will install only oracle binaries on
standby server(192.168.2.104).No database should be running in standby server.
                 



Oracle Net configuration:-

Listener.ora configuration for primary database (prim) in primary server (192.168.2.102)

vi $ORACLE_HOME/network/admin/listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = prim)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = prim)
    )
  )
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = server1.soumya.com)(PORT = 1521))
  )
ADR_BASE_LISTENER = /u01/app/oracle

:wq

Listener.ora configuration for standby database (stand) in standby server (192.168.2.104)
vi $ORACLE_HOME/network/admin/listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = stand)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = stand)
    )
  )
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = server2.soumya.com)(PORT = 1521))
  )
ADR_BASE_LISTENER = /u01/app/oracle

:wq

On both server(192.168.2.102 & 192.168.2.104), add Oracle Net aliases for both databases and aux alias for RMAN DUPLICATE in
tnsnames.ora:

vi $ORACLE_HOME/network/admin/tnsnames.ora

prim =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = server1.soumya.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = prim)
    )
  )

stand =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = server2.soumya.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = stand)
    )
  )

-save & exit(:wq )

Now we will have to start listener in primary and standby server:-

$ lsnrctl start

Check "tnsping prim" & "tnsping stand"  in both server. If output of both command is
coming as "ok" that means oracle net service has been added successfully.

In primary database:-
Put the database in archivelog mode.
SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     2
Current log sequence           4

SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> startup mount
ORACLE instance started.

Total System Global Area  629145600 bytes
Fixed Size                  2927528 bytes
Variable Size             511706200 bytes
Database Buffers          109051904 bytes
Redo Buffers                5459968 bytes
Database mounted.

SQL> alter database archivelog;
Database altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     2
Next log sequence to archive   4
Current log sequence           4

SQL> alter database open;

In Primary Database:-

Enable force logging The FORCE LOGGING option to ensure that all the changes made in the database
will be captured and available for recovery in the redo logs.

SQL> alter database force logging;
Database altered.

SQL> select force_logging from v$database;

FORCE_LOGGING
---------------------------------------
YES

Create a password file
$ orapwd file=$ORACLE_HOME/dbs/orapwprim password=redhat
$ cd $ORACLE_HOME/dbs/
$ chmod 775 orapwprim
$ cp orapwprim orapwstand

Now transfer the password file  into standby server using scp command
$ scp orapwstand oracle@192.168.2.104:/u01/app/oracle/product/11.2.0/db_1/dbs/


Add following parameter in pfile for primary database.

create pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora' from spfile;   

vi /u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora

*.db_name='prim'
*.db_unique_name='prim'
*.log_archive_config='DG_CONFIG=(prim, stand)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/flash_recovery_area VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prim'
*.log_archive_dest_2='SERVICE=stand LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=stand'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.FAL_SERVER=stand
*.FAL_CLIENT=prim
*.db_file_name_convert='/u01/app/oracle/oradata/stand/','/u01/app/oracle/oradata/prim/'
*.log_file_name_convert='/u01/app/oracle/oradata/stand/','/u01/app/oracle/oradata/prim/'
*.standby_file_management=auto   

-save & exit(:wq)

SQL> shut immediate;

SQL>  startup mount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora';
SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora';

SQL> startup open
Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             339740664 bytes
Database Buffers           67108864 bytes
Redo Buffers                4308992 bytes
Database mounted.
Database opened.

At Standby database:-
Create the necessary directory structure:-
$ mkdir -p /u01/app/oracle/oradata/stand/
$ mkdir -p /u01/app/oracle/admin/stand/adump
$ mkdir -p /u01/app/oracle/flash_recovery_area/stand/
$ chmod 775 -Rf /u01

Configure .bash_profile
[oracle@server2 ~]$ vi .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=server2.soumya.com
export ORACLE_UNQNAME=stand
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=stand
export PATH=/usr/sbin:$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/lib64
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

Now start the instance in nomount mode with minimal options

vi initstand.ora
DB_NAME=prim
DB_UNIQUE_NAME=stand
DB_BLOCK_SIZE=8192

:wq


SQL> startup nomount pfile='/home/oracle/initstand.ora';
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             339740664 bytes
Database Buffers           67108864 bytes
Redo Buffers                4308992 bytes

At primary database:-
Add the standby redologs.
SQL>  select group#, members , bytes /1024 /1024 from v$log;

    GROUP#    MEMBERS BYTES/1024/1024
---------- ---------- ---------------
         1          1              50
         2          1              50
         3          1              50
       
SQL> select group# , member from v$logfile;
    GROUP# MEMBER
---------- --------------------------------------------------
         3 /u01/app/oracle/oradata/prim/redo03.log
         2 /u01/app/oracle/oradata/prim/redo02.log
         1 /u01/app/oracle/oradata/prim/redo01.log       
       
       
SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/prim/redos4A.log' size 50M;
SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/prim/redos5A.log' size 50M;
SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/prim/redos6A.log' size 50M;
SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/prim/redos7A.log' size 50M;

SQL> select group# , member from v$logfile;
    GROUP# MEMBER
---------- --------------------------------------------------------------------------------
         3 /u01/app/oracle/oradata/prim/redo03.log
         2 /u01/app/oracle/oradata/prim/redo02.log
         1 /u01/app/oracle/oradata/prim/redo01.log
         4 /u01/app/oracle/oradata/prim/redos4A.log
         5 /u01/app/oracle/oradata/prim/redos5A.log
         6 /u01/app/oracle/oradata/prim/redos6A.log
         7 /u01/app/oracle/oradata/prim/redos7A.log


At standby database:-
Now once the redoglogs have been created in primary database,we will create the following RMAN run commands and  the changes to the standby’s spfile in this RMAN block.

[oracle@server2 ]rman target sys/redhat@prim auxiliary sys/redhat@stand   
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Sep 7 14:43:25 2015

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

connected to target database: PRIM (DBID=4130009889)
connected to auxiliary database: PRIM (not mounted)

RMAN>run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
parameter_value_convert 'prim','stand'
set db_unique_name='stand'
set db_file_name_convert='/u01/app/oracle/oradata/prim/','/u01/app/oracle/oradata/stand/'
set log_file_name_convert='/u01/app/oracle/oradata/prim/','/u01/app/oracle/oradata/stand/'
set control_files='/u01/app/oracle/oradata/stand/control01.ctl','/u01/app/oracle/oradata/stand/control02.ctl'
set log_archive_max_processes='10'
set fal_client='stand'
set fal_server='prim'
set standby_file_management='AUTO'
set log_archive_config='dg_config=(prim,stand)'
set log_archive_dest_2='service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim'
;
}

using target database control file instead of recovery catalog
allocated channel: prmy1
channel prmy1: SID=32 device type=DISK

allocated channel: prmy2
channel prmy2: SID=33 device type=DISK

allocated channel: prmy3
channel prmy3: SID=34 device type=DISK

allocated channel: prmy4
channel prmy4: SID=35 device type=DISK

allocated channel: stby
channel stby: SID=19 device type=DISK

Starting Duplicate Db at 16-MAY-13

contents of Memory Script:
{
 backup as copy reuse
 targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwprim' auxiliary format
 '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwstand' targetfile
 '/u01/app/oracle/product/11.2.0/db_1/dbs/spfileprim.ora' auxiliary format
 '/u01/app/oracle/product/11.2.0/db_1/dbs/spfilestand.ora' ;
 sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfilestand.ora''";
}
executing Memory Script

Starting backup at 16-MAY-13
Finished backup at 16-MAY-13

sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfilestand.ora''

contents of Memory Script:
{
 sql clone "alter system set audit_file_dest =
 ''/u01/app/oracle/oradata/dump/stand/adump'' comment=
 '''' scope=spfile";
 sql clone "alter system set diagnostic_dest =
 ''/u01/app/oracle/oradata/dump/stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_dest_1 =
 ''location=use_db_recovery_file_dest valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set db_unique_name =
 ''stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set db_file_name_convert =
 ''/u01/app/oracle/oradata/prim/prim/datafile/'', ''/u01/app/oracle/oradata/stand/stand/datafile/'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_file_name_convert =
 ''/u01/app/oracle/oradata/prim/prim/onlinelog/'', ''/u01/app/oracle/oradata/stand/stand/onlinelog/'' comment=
 '''' scope=spfile";
 sql clone "alter system set control_files =
 ''/u01/app/oracle/oradata/stand/control/control01.ctl'', ''/u01/app/oracle/oradata/stand/control/control02.ctl'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_max_processes =
 10 comment=
 '''' scope=spfile";
 sql clone "alter system set fal_client =
 ''stand'' comment=
 '''' scope=spfile";
 sql clone "alter system set fal_server =
 ''prim'' comment=
 '''' scope=spfile";
 sql clone "alter system set standby_file_management =
 ''AUTO'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_config =
 ''dg_config=(prim,stand)'' comment=
 '''' scope=spfile";
 sql clone "alter system set log_archive_dest_2 =
 ''service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim'' comment=
 '''' scope=spfile";
 shutdown clone immediate;
 startup clone nomount;
}
executing Memory Script

sql statement: alter system set audit_file_dest = ''/u01/app/oracle/oradata/dump/stand/adump'' comment= '''' scope=spfile

sql statement: alter system set diagnostic_dest = ''/u01/app/oracle/oradata/dump/stand'' comment= '''' scope=spfile

sql statement: alter system set log_archive_dest_1 = ''location=use_db_recovery_file_dest valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=stand'' comment= '''' scope=spfile

sql statement: alter system set db_unique_name = ''stand'' comment= '''' scope=spfile

sql statement: alter system set db_file_name_convert = ''/u01/app/oracle/oradata/prim/prim/datafile/'', ''/u01/app/oracle/oradata/stand/stand/datafile/'' comment= '''' scope=spfile

sql statement: alter system set log_file_name_convert = ''/u01/app/oracle/oradata/prim/prim/onlinelog/'', ''/u01/app/oracle/oradata/stand/stand/onlinelog/'' comment= '''' scope=spfile

sql statement: alter system set control_files = ''/u01/app/oracle/oradata/stand/control/control01.ctl'', ''/u01/app/oracle/oradata/stand/control/control02.ctl'' comment= '''' scope=spfile

sql statement: alter system set log_archive_max_processes = 10 comment= '''' scope=spfile

sql statement: alter system set fal_client = ''stand'' comment= '''' scope=spfile

sql statement: alter system set fal_server = ''prim'' comment= '''' scope=spfile

sql statement: alter system set standby_file_management = ''AUTO'' comment= '''' scope=spfile

sql statement: alter system set log_archive_config = ''dg_config=(prim,stand)'' comment= '''' scope=spfile

sql statement: alter system set log_archive_dest_2 = ''service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim'' comment= '''' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 534462464 bytes

Fixed Size 2230072 bytes
Variable Size 163580104 bytes
Database Buffers 364904448 bytes
Redo Buffers 3747840 bytes
allocated channel: stby
channel stby: SID=18 device type=DISK

contents of Memory Script:
{
 backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/stand/control/control01.ctl';
 restore clone controlfile to '/u01/app/oracle/oradata/stand/control/control02.ctl' from
 '/u01/app/oracle/oradata/stand/control/control01.ctl';
}
executing Memory Script

Starting backup at 16-MAY-13
channel prmy1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_prim.f tag=TAG20130516T084319 RECID=7 STAMP=815561001
channel prmy1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 16-MAY-13

Starting restore at 16-MAY-13

channel stby: copied control file copy
Finished restore at 16-MAY-13

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/oradata/stand/stand/datafile/o1_mf_temp_8qbok7fk_.tmp";
 switch clone tempfile all;
 set newname for datafile 1 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf";
 set newname for datafile 2 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf";
 set newname for datafile 3 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf";
 set newname for datafile 4 to
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf";
 backup as copy reuse
 datafile 1 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf" datafile
 2 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf" datafile
 3 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf" datafile
 4 auxiliary format
 "/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf" ;
 sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/stand/stand/datafile/o1_mf_temp_8qbok7fk_.tmp in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 16-MAY-13
channel prmy1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_system_8ocl7bho_.dbf
channel prmy2: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_sysaux_8ocl7k6n_.dbf
channel prmy3: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf
channel prmy4: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/prim/prim/datafile/o1_mf_users_8qbolh3g_.dbf
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf tag=TAG20130516T084335
channel prmy3: datafile copy complete, elapsed time: 00:00:45
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf tag=TAG20130516T084335
channel prmy4: datafile copy complete, elapsed time: 00:00:55
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf tag=TAG20130516T084335
channel prmy1: datafile copy complete, elapsed time: 00:01:05
output file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf tag=TAG20130516T084335
channel prmy2: datafile copy complete, elapsed time: 00:01:05
Finished backup at 16-MAY-13

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=7 STAMP=815561103 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_system_8ocl7bho_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=815561104 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sysaux_8ocl7k6n_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=815561104 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_sys_undo_8ocl7q6c_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=815561104 file name=/u01/app/oracle/oradata/stand/stand/datafile/o1_mf_users_8qbolh3g_.dbf
Finished Duplicate Db at 16-MAY-13
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4
released channel: stby

RMAN> exit

Now at standby database:-

SQL>shut immediate;
SQL>startup mount
SQL>alter database recover managed standby database disconnect from session;

Now for real time apply:-

SQL> alter database recover managed standby database cancel;

SQL> alter database open;

SQL> alter database recover managed standby database using current logfile disconnect from session;

SQL>select open_mode from v$database; (Output : read only with apply)


There are various ways to see if this is working or not. You can use it in the following query to see what was the last archive received/applied in the Standby Database.

On standby database

SQL> SELECT 'Last Applied : ' Logs,
TO_CHAR(next_time,'DD-MON-YY:HH24:MI:SS') TIME,thread#,sequence#
FROM v$archived_log
WHERE sequence# =
(SELECT MAX(sequence#) FROM v$archived_log WHERE applied='YES'
)
UNION
SELECT 'Last Received : ' Logs,
TO_CHAR(next_time,'DD-MON-YY:HH24:MI:SS') TIME,thread#,sequence#
FROM v$archived_log
WHERE sequence# =
(SELECT MAX(sequence#) FROM v$archived_log );

LOGS             TIME                  THREAD#  SEQUENCE#
---------------- ------------------ ---------- ----------
Last Applied :   07-SEP-15:11:53:22          1         17
Last Received :  07-SEP-15:11:53:22          1         17
While in the Primary Database, you can check what is the current sequence and what is the pending sequence to be applied.

On primary database

SQL> SELECT
 (SELECT name FROM V$DATABASE
 ) name,
 (SELECT MAX (sequence#) FROM v$archived_log WHERE dest_id = 1
 ) Current_primary_seq,
 (SELECT MAX (sequence#)
 FROM v$archived_log
 WHERE TRUNC(next_time) > SYSDATE - 1
 AND dest_id = 2
 ) max_stby,
 (SELECT NVL (
 (SELECT MAX (sequence#) - MIN (sequence#)
 FROM v$archived_log
 WHERE TRUNC(next_time) > SYSDATE - 1
 AND dest_id = 2
 AND applied = 'NO'
 ), 0)
 FROM DUAL
 ) "To be applied",
 (
 (SELECT MAX (sequence#) FROM v$archived_log WHERE dest_id = 1
 ) -
 (SELECT MAX (sequence#) FROM v$archived_log WHERE dest_id = 2
 )) "To be Shipped"
FROM DUAL;

NAME      CURRENT_PRIMARY_SEQ   MAX_STBY To be applied To be Shipped
--------- ------------------- ---------- ------------- -------------
PRIM                       17         17             0             0


Finally Test on primary database to check if the datas are being replicated to standby or not
SQL> create user soumya identified by soumya;
SQL>grant connect , resource to soumya;
SQL> conn soumya/soumya
SQL>create table test (id number);
SQL>insert into test values(1);
SQL> /
SQL> /
SQL> commit;

Now on standby database:-
sqlplus soumya/soumya

SQL> select * from test;

        ID
----------
         1
         1
       
So we can see the datas are applying on standby real time.



Please share your ideas and opinions about this topic.

If you like this post, then please share with others.
Please subscribe on email for every updates on mail.      

Switchover of Databases (Primary to standby and standby to primary) in Dataguard oracle 11g.

Switchover of Databases (Primary to standby and standby to primary) in  Dataguard  oracle 11g.

Oracle Version:- Enterprise Edition Release 11.2.0.1
OS:- Rhel 6.4
Primary database:- Prim
Standby database:- Stand


Switchover is a planned event, it is ideal when we might want to upgrade the primary database or change
the storage/hardware configuration (add memory, cpu networking), we may even want to upgrade the
configuration to Oracle RAC .

What happens during a switchover is the following :

1.) Notifies the primary database that a switchover is about to occur
2.) Disconnect all users from the primary database
3.) Generate a special redo record that signals the End of Redo (EOR)
4.) Converts the primary database into a standby database
5.) Once the standby database applies the final EOR record, guaranteeing that no data loss has been lost,
converts the standby database into the primary database.



Before doing the switchover lets run few select queries to find out some info:-
In primary:-

SQL> select status,INSTANCE_NAME ,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE
------------ ---------------- ----------------
OPEN         prim             PRIMARY

In standby:-

SQL> select status,INSTANCE_NAME ,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE
------------ ---------------- ----------------
MOUNTED      stand            PHYSICAL STANDBY


In primary:-
Archive log destination of Prim:-

SQL> show parameter log_archive_dest_1;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1                   string      LOCATION=/u01/app/oracle/flash
                                                 _recovery_area VALID_FOR=(ALL_
                                                 LOGFILES,ALL_ROLES) DB_UNIQUE_
                                                 NAME=prim
           
           
SQL> show parameter log_archive_dest_2;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2                   string      SERVICE=stand LGWR ASYNC VALID
                                                 _FOR=(ALL_LOGFILES,PRIMARY_ROL
                                                 E) DB_UNIQUE_NAME=stand
           
*Archivelog Destination 1 of Primary Database is "/u01/app/oracle/flash_recovery_area" and Archivelog
destination 2 of Primary database is pointing to the service-name of the standby database.


In standby:-
Archive log destination of Stand:-
SQL> show parameter log_archive_dest_1;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1                   string      LOCATION=/u01/app/oracle/flash
                                                 _recovery_area VALID_FOR=(ALL_
                                                 LOGFILES,ALL_ROLES) DB_UNIQUE_
                                                 NAME=stand
           

SQL> show parameter log_archive_dest_2;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2                   string      SERVICE=prim LGWR ASYNC VALID_
                                                 FOR=(ALL_LOGFILES,PRIMARY_ROLE
                                                 ) DB_UNIQUE_NAME=prim

*Archivelog Destination 1 of Standby database is "/u01/app/oracle/flash_recovery_area" and archivelog
destination 2 of standby database is pointing to the service-name of the primary database.
(Note: destination 2 in standby database is not mandatory. It is required only if the standby database
would be running in as primary database during switchover or failover. Hence it would be a good practice
to set this parameter to avoid problems during the switchover or failover.) 

Pre-Switchover Checks:-

In standby database:-

Verify whether Managed Recovery process is running on the standby database

Use the following query to check if the managed recovery process is running on the standby database.

SQL> select process,status,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CLOSING              27
RFS       IDLE                  0
RFS       IDLE                 28
MRP0      WAIT_FOR_LOG         28

The above result shows that the Managed Recovery Process (MRP0) is running on the standby database.
If MRP is not running, then start the process with real time enabled using the below query in the
standby database.

SQL>alter database recover managed standby disconnect from session;

Once when the MRP has started on the standby database, make sure that the archive logs generated at the
primary database end are shipped and getting applied to the standby database.

At primary database:-
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            27
  
At standby database:-
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            27

In the above case, sequence# 27 is the maximum sequence generated at the primary database and the
same has been applied to the standby database.So both database's log files are in sync.

*Verify primary and standby tempfiles match :-

For each temporary tablespace on the standby, verify that temporary files associated with that
tablespace on the primary database also exist on the standby database. Tempfiles added after initial
standby creation are not propagated to the standby. Run this query on both the primary and target
physical standby databases and verify that they match.

In primary database:-
SQL> select ts#, name ,status from v$tempfile;
      TS# NAME                                     STATUS
---------- ---------------------------------------- -------
         3 /u01/app/oracle/oradata/prim/temp01.dbf  ONLINE

SQL> select ts#,name from v$tablespace;

       TS# NAME
---------- ----------------------------------------
         0 SYSTEM
         1 SYSAUX
         2 UNDOTBS1
         4 USERS
         3 TEMP
         6 EXAMPLE


In Standby database:-
SQL> select ts#, name ,status from v$tempfile;
       TS# NAME                                     STATUS
---------- ---------------------------------------- -------
         3 /u01/app/oracle/oradata/stand/temp01.dbf ONLINE 


SQL> select ts#,name from v$tablespace;

       TS# NAME
---------- ----------------------------------------
         0 SYSTEM
         1 SYSAUX
         2 UNDOTBS1
         4 USERS
         3 TEMP
         6 EXAMPLE
         
*Verify that all datafiles are online on both primary and standby databases:-

On both primary and standby database:-

SQL> select name from v$datafile where status='OFFLINE';

no rows selected

If there are any offline datafiles, then bring them online using the below query
SQL>alter database datafile<datafile name> online;


Switchover Steps:

These steps are performed during the switchover process at the primary database side.

Check if there are any jobs running on the primary database using the below query.

SQL>select * from dba_jobs_running;
no rows selected

If there are any jobs running on the primary database and if it’s execution is not very important,
then terminate the job to continue further.

Block further job submission by setting the job_queue_processes parameter to 0 so that there would be no
jobs running during switchover.

SQL> show parameter job_queue_process;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes                  integer     1000

Set this parameter to the value 0.
SQL> alter system set job_queue_processes=0 scope=spfile;                  

System altered.


*Verify that the primary database can be switched over to the standby

In primary database:-

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO STANDBY

A value of TO STANDBY or SESSIONS ACTIVE (which requires the WITH SESSION SHUTDOWN clause on the switchover command)
indicates that the primary database can be switched to the standby role. If neither of these values is
returned, a switchover is not possible because redo transport is either mis-configured or is not functioning
properly.


*Switchover the primary database to standby

Once when value of switchover_status returns “TO STANDBY” or “SESSIONS ACTIVE” on the primary database,
then perform the switchover using the below query

In primary:-
SQL> alter database commit to switchover to physical standby with session shutdown;

Database altered.

Now the primary database is switched over to the standby database. The execution of the above command
may take some time and the archive logs generated during its execution would be automatically applied to
the standby database. Once when the command is executed with the output as “Database altered”, it means
that the primary database has been switched over to the standby.

Note: Always perform the switchover of the primary database to standby database first and then
switchover the standby database to primary. If not, then you would end up landing with two primary
databases.


*Switchover the standby database to primary
Query the switchover_status column from the v$database view at the standby side to determine whether
the standby database can be switched over to the primary database.

In standby database:-
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

A value of TO PRIMARY or SESSIONS ACTIVE indicates that the standby database is ready to be switched to
the primary role. If neither of these values is returned, verify that redo apply is active and that redo
transport is configured and working properly. Continue to query this column until the value returned is
either TO PRIMARY or SESSIONS ACTIVE.

Once when the value of switchover_status returns “TO PRIMARY” or “SESSIONS ACTIVE” on the standby
database, then perform the switchover using the below query

SQL>alter database commit to switchover to primary with session shutdown;

Now the standby database has been switched over to the primary database.

*Open the new primary database (stand)

The new primary database will be in mount state. Open this new primary database using the below query.

SQL>alter database open;

SQL> select status,INSTANCE_NAME ,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE
------------ ---------------- ----------------
OPEN         stand            PRIMARY


*Restart the new standby database
Restart the new standby database (old primary database prim), bring it to the mount stage and
start the managed recovery process.

Shutdown the new standby database (prim)
SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.

Startup the new standby database (prim) in mount stage
SQL>startup mount;
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             335546360 bytes
Database Buffers           71303168 bytes
Redo Buffers                4308992 bytes
Database mounted.

Start the managed recovery process on the the new standby database (prim)
SQL>alter database recover managed standby database disconnect from session;
Database altered.

QL> select status,INSTANCE_NAME ,database_role from v$database,v$instance;

STATUS       INSTANCE_NAME    DATABASE_ROLE
------------ ---------------- ----------------
MOUNTED      prim             PHYSICAL STANDBY

*Post-Switchover tasks

Reset the job_queue_processes parameter to its previous value
Set the job queue processes to its original value on the new standby (prim).

SQL> show parameter job_queue

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes                  integer     0

SQL> alter system set job_queue_processes=1000 scope=spfile;

System altered.


Now the roles of the databases have been changed. The primary database (prim) has been changed to
standby database and the standby database (stnd) has been changed to primary database.
The archive logs that get generated in the new primary database (stnd) get shipped automatically to the
new standby database (prim) and they are applied on it automatically.

Maximum archivelog generated at the new primary database (stnd)

SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            34
  
Maximum archivelog that has been shipped and applied to the new standby database (prim)
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            34


*Now if we want the real time apply enabled on new standby database(prim)
Perform the following queries on new standby database(prim)
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open;

Database altered.

SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY WITH APPLY

   

Please share your ideas and opinions about this topic.

If you like this post, then please share with others.
Please subscribe on email for every updates on mail.
Thanks
Srini

No comments:

Post a Comment


No one has ever become poor by giving