Table Point In Time Recovery (PITR) in Oracle Database 12c Release

Oracle version : 12.1.0.2.0  Enterprise Edition
OS : Rhel 6.4
Database Name : ORA12C


sqlplus soumya/soumya

SQL> create table xyz (id number);
SQL> insert into xyz 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 * FROM xyz;

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

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

TO_CHAR(SYSDATE,'DD-MON-YYYYH)
-----------------------------
2015-05-22:23:16:36

*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 xyz;

Table dropped.

SQL> purge recyclebin;

Recyclebin purged.

SQL> select * from xyz;
select * from xyz
              *
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.

RMAN> RECOVER TABLE 'SOUMYA'.'XYZ' until time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')" AUXILIARY DESTINATION '/u01'
REMAP TABLE 'SOUMYA'.'XYZ':'XYZ1_PREV';

Starting recover at 22-MAY-15
using channel ORA_DISK_1
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='vkqb'

initialization parameters used for automatic instance:
db_name=ORA12C
db_unique_name=vkqb_pitr_ORA12C
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=600M
processes=200
db_create_file_dest=/u01
log_archive_dest_1='location=/u01'
#No auxiliary parameter file used


starting up automatic instance ORA12C

Oracle instance started

Total System Global Area     629145600 bytes

Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','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';
}
executing Memory Script

executing command: SET until clause

Starting restore at 22-MAY-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=22 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/inc_level_1_cum/220515_224615/control_ORA12C_c-254883632-20150522-01
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/inc_level_1_cum/220515_224615/control_ORA12C_c-254883632-20150522-01 tag=TAG20150522T224704
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/ORA12C/controlfile/o1_mf_boyv53cn_.ctl
Finished restore at 22-MAY-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  4 to new;
set newname for clone datafile  3 to new;
set newname for clone tempfile  1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 4, 3;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

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

Starting restore at 22-MAY-15
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 00001 to /u01/ORA12C/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/ORA12C/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/ORA12C/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/220515_223941/full_ORA12C_20150522_880411183_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/220515_223941/full_ORA12C_20150522_880411183_1_1 tag=TAG20150522T223943
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:07
Finished restore at 22-MAY-15

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=880413765 file name=/u01/ORA12C/datafile/o1_mf_system_boyv5bb4_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=880413765 file name=/u01/ORA12C/datafile/o1_mf_undotbs1_boyv5bcz_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=880413765 file name=/u01/ORA12C/datafile/o1_mf_sysaux_boyv5bcp_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  4 online";
sql clone "alter database datafile  3 online";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  4 online

sql statement: alter database datafile  3 online

Starting recover at 22-MAY-15
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 00001: /u01/ORA12C/datafile/o1_mf_system_boyv5bb4_.dbf
destination for restore of datafile 00004: /u01/ORA12C/datafile/o1_mf_undotbs1_boyv5bcz_.dbf
destination for restore of datafile 00003: /u01/ORA12C/datafile/o1_mf_sysaux_boyv5bcp_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/inc_level_1_cum/220515_224615/inc_level_1_cum_ORA12C_20150522_880411578_4_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/inc_level_1_cum/220515_224615/inc_level_1_cum_ORA12C_20150522_880411578_4_1 tag=TAG20150522T224618
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 46 is already on disk as file /u01/app/oracle/fast_recovery_area/1_46_877084402.dbf
archived log file name=/u01/app/oracle/fast_recovery_area/1_46_877084402.dbf thread=1 sequence=46
Executing: alter database datafile 5 offline
archived log file name=/u01/app/oracle/fast_recovery_area/1_46_877084402.dbf thread=1 sequence=46
media recovery complete, elapsed time: 00:00:01
Finished recover at 22-MAY-15

sql statement: alter database open read only

contents of Memory Script:
{
   sql clone "create spfile from memory";
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  control_files =
  ''/u01/ORA12C/controlfile/o1_mf_boyv53cn_.ctl'' comment=
 ''RMAN set'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script

sql statement: create spfile from memory

database closed
database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     629145600 bytes

Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes

sql statement: alter system set  control_files =   ''/u01/ORA12C/controlfile/o1_mf_boyv53cn_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     629145600 bytes

Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  5 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  5;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 22-MAY-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=21 device type=DISK

creating datafile file number=5 name=/u01/VKQB_PITR_ORA12C/datafile/o1_mf_testtbs_%u_.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 22-MAY-15

datafile 5 switched to datafile copy
input datafile copy RECID=12 STAMP=880413824 file name=/u01/VKQB_PITR_ORA12C/datafile/o1_mf_testtbs_boyv95p7_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2015-05-22:23:16:36','YYYY-MM:DD:HH24:MI:SS')";
# online the datafiles restored or switched
sql clone "alter database datafile  5 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  5 online

Starting recover at 22-MAY-15
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 46 is already on disk as file /u01/app/oracle/fast_recovery_area/1_46_877084402.dbf
archived log file name=/u01/app/oracle/fast_recovery_area/1_46_877084402.dbf thread=1 sequence=46
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-15

database opened

contents of Memory Script:
{
# 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: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01''

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

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_vkqb_Dzlo":
   EXPDP> Estimate in progress using BLOCKS method...
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Total estimation using BLOCKS method: 64 KB
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   EXPDP> . . exported "SOUMYA"."XYZ"                              5.062 KB       2 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_vkqb_Dzlo" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_vkqb_Dzlo is:
   EXPDP>   /u01/tspitr_vkqb_17217.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_vkqb_Dzlo" successfully completed at Fri May 22 23:25:04 2015 elapsed 0 00:00:30
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script

Oracle instance shut down

Performing import of tables...
   IMPDP> Master table "SYS"."TSPITR_IMP_vkqb_dagD" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_vkqb_dagD":
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "SOUMYA"."XYZ1_PREV"                        5.062 KB       2 rows
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
   IMPDP> Job "SYS"."TSPITR_IMP_vkqb_dagD" successfully completed at Fri May 22 23:25:28 2015 elapsed 0 00:00:07
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/ORA12C/datafile/o1_mf_temp_boyv7n1j_.tmp deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/onlinelog/o1_mf_3_boyv9h6g_.log deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/onlinelog/o1_mf_2_boyv9fc9_.log deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/onlinelog/o1_mf_1_boyv9bwh_.log deleted
auxiliary instance file /u01/VKQB_PITR_ORA12C/datafile/o1_mf_testtbs_boyv95p7_.dbf deleted
auxiliary instance file /u01/ORA12C/datafile/o1_mf_sysaux_boyv5bcp_.dbf deleted
auxiliary instance file /u01/ORA12C/datafile/o1_mf_undotbs1_boyv5bcz_.dbf deleted
auxiliary instance file /u01/ORA12C/datafile/o1_mf_system_boyv5bb4_.dbf deleted
auxiliary instance file /u01/ORA12C/controlfile/o1_mf_boyv53cn_.ctl deleted
auxiliary instance file tspitr_vkqb_17217.dmp deleted
Finished recover at 22-MAY-15

[oracle@server3 bin]$ sqlplus soumya/soumya
OUMYA@ORA12C> SQL> SELECT * FROM xyz;

        ID
----------
         1
         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.

Recovering A Dropped Table Using Tablespace Point In Time Recovery (TSPITR) in Oracle 11g

Oracle version : 11.2.0.1.0 Enterprise Edition
OS : Rhel 6.4
Database Name : orcl
Tablespace Name : TESTTBS

A user reported a table named "TSPITR" was accidentally dropped . There was no flashback enabled on this
database and the recyclebin too was purged out. As a result, the table could not be recovered using
flashback method. The other methods to recover the dropped table would be:

Using Tablespace Point In Time Recovery. Here, the tablespace associate with the table that is dropped
would be recovered until the time. The main disadvantage of this method is that any other successful
transactions that were carried out on this tablespace after the time the
table was dropped, would be lost when you do a point in time recovery.

Here we are trying to create the same scenario by creating and dropping the table TSPITR.

sqlplus soumya/soumya

SQL> create table xyz (id number);
SQL> insert into xyz 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;


First lets find out the tablespace where the table resides:-
SQL> select table_name ,tablespace_name from user_tables where table_name ='XYZ';

TABLE_NAME               TABLESPACE_NAME
------------------------------ ------------------------------
XYZ                                 TESTTBS

SQL> SELECT * FROM xyz;

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

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

TO_CHAR(SYSDATE,'DD-MON-YYYYH
-----------------------------
20-SEP-2014 07:22:29

*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 xyz;

Table dropped.

SQL> purge recyclebin;

Recyclebin purged.

SQL> select * from xyz;
select * from xyz
              *
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 ORCL]$ RMAN> run
2> {
3> recover tablespace TESTTBS until time "to_date('2014-09-20:07:22:29','YYYY-MM:DD:HH24:MI:SS')" auxiliary destination '/u01';
4> };

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=ORCL
db_unique_name=DFCz_tspitr_ORCL
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 ORCL

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-09-20:07:22:29','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_ORCL_c-1366623577-20140920-08
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/200914_071833/control_ORCL_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/ORCL/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-09-20:07:22:29','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/orcl/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/ORCL/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/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/200914_065249/full_ORCL_20140920_858754372_17_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/200914_065249/full_ORCL_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/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/orcl/testtbs.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backups/rman_backup/full_backup/200914_071833/full_ORCL_20140920_858755915_24_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/full_backup/200914_071833/full_ORCL_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/ORCL/datafile/o1_mf_system_b1sqot67_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=858756425 file name=/u01/ORCL/datafile/o1_mf_undotbs1_b1sqot9h_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=858756425 file name=/u01/ORCL/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/ORCL/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_ORCL_20140920_858755714_21_1
channel ORA_AUX_DISK_1: piece handle=/u01/backups/rman_backup/inc_level_1/200914_071502/inc_level_1_ORCL_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/orcl/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/ORCL/datafile/o1_mf_temp_b1sqqxbb_.tmp deleted
auxiliary instance file /u01/ORCL/onlinelog/o1_mf_3_b1sqqsvf_.log deleted
auxiliary instance file /u01/ORCL/onlinelog/o1_mf_2_b1sqqql5_.log deleted
auxiliary instance file /u01/ORCL/onlinelog/o1_mf_1_b1sqqo4d_.log deleted
auxiliary instance file /u01/ORCL/datafile/o1_mf_sysaux_b1sqnphr_.dbf deleted
auxiliary instance file /u01/ORCL/datafile/o1_mf_undotbs1_b1sqot9h_.dbf deleted
auxiliary instance file /u01/ORCL/datafile/o1_mf_system_b1sqot67_.dbf deleted
auxiliary instance file /u01/ORCL/controlfile/o1_mf_b1sqnht0_.ctl deleted
Finished recover at 20-SEP-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.

QL> 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 xyz;

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

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




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 12.1.0.2

Creating a physical standby database on Oracle 12.1.0.2 :-

OS Version:-Red Hat Enterprise Linux Server release 6.4
Oracle version:- Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 64bit

System Configuration

primary server:-

edit the following files

vi /etc/hosts

192.168.2.100   server3.soumya.com      server3
192.168.2.101   server4.soumya.com      server4

:wq

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

:wq

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

NETMASK=255.255.255.0
IPADDR=192.168.2.100
GATEWAY=192.168.2.1

:wq

Standby Server:-

edit the following files

vi /etc/hosts

192.168.2.100   server3.soumya.com      server3
192.168.2.101   server4.soumya.com      server4
:wq

vi /etc/sysconfig/network

HOSTNAME=server4.soumya.com

:wq

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

NETMASK=255.255.255.0
IPADDR=192.168.2.101
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 ora12c on primary server and  we will install only oracle binaries on
standby server(192.168.2.101).No database should be running in standby server.


Primary database:- ORA12C
Standby database:- ORASTD

Oracle Net configuration:-

Listener.ora configuration for primary database (ORA12C) in primary server (192.168.2.100)

vi $ORACLE_HOME/network/admin/listener.ora

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

:wq

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

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

:wq

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

vi $ORACLE_HOME/network/admin/tnsnames.ora

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

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


:wq

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

$ lsnrctl start

Check "tnsping ORA12C" & "tnsping ORASTD"  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 archive log;
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


We have to enable remote login by setting remote_login_passwordfile to exclusive in password file
SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

Create a password file
$ orapwd file=$ORACLE_HOME/dbs/orapwORA12C password=redhat
$ cd $ORACLE_HOME/dbs/
$ chmod 775 orapwORA12C
$ cp orapwORA12C orapwORASTD

Now transfer the password file  into standby server using scp command
$ scp orapwORASTD oracle@192.168.2.101:/u01/app/oracle/product/12.1.0.2/db_1/dbs/


Configure standby redo log file with the same size of redo log file in ORA12C database
SYS@ORA12C>  select group#, members , bytes /1024 /1024 from v$log;

    GROUP#    MEMBERS BYTES/1024/1024
---------- ---------- ---------------
         1          1              50
         2          1              50
         3          1              50

SYS@ORA12C> select group# , member from v$logfile;
    GROUP# MEMBER
---------- --------------------------------------------------
         3 /u01/app/oracle/oradata/ORA12C/redo03.log
         2 /u01/app/oracle/oradata/ORA12C/redo02.log
         1 /u01/app/oracle/oradata/ORA12C/redo01.log

Now adding redolog files :-
SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/ORA12C/redos4A.log' size 50M;
SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/ORA12C/redos5A.log' size 50M;
SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/ORA12C/redos6A.log' size 50M;
SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/ORA12C/redos7A.log' size 50M;

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


Add following parameter in pfile for primary database.

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

vi /u01/app/oracle/product/12.1.0.2/db_1/dbs/initORA12C.ora

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

:wq

SQL> shut immediate;

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

Create a standby controlfile.
sql>alter database create standby controlfile as '/u01/app/oracle/oradata/ORA12C/ORASTD.ctl';

Create parameter file for standby database :

$cp /u01/app/oracle/product/12.1.0.2/db_1/dbs/initORA12C.ora /u01/app/oracle/product/12.1.0.2/db_1/dbs/initORASTD.ora

$ vi /u01/app/oracle/product/12.1.0.2/db_1/dbs/initORASTD.ora

ORASTD.__data_transfer_cache_size=0
ORASTD.__db_cache_size=197132288
ORASTD.__java_pool_size=4194304
ORASTD.__large_pool_size=8388608
ORASTD.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
ORASTD.__pga_aggregate_target=251658240
ORASTD.__sga_target=377487360
ORASTD.__shared_io_pool_size=8388608
ORASTD.__shared_pool_size=150994944
ORASTD.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/ORASTD/adump'
*.audit_trail='db'
*.compatible='12.1.0.2.0'
*.control_files='/u01/app/oracle/oradata/ORASTD/ORASTD.ctl','/u01/app/oracle/fast_recovery_area/ORASTD/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4560m
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORASTDXDB)'
*.memory_target=600m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.db_name='ORA12C'
*.db_unique_name='ORASTD'
*.log_archive_config='DG_CONFIG=(ORA12C, ORASTD)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/fast_recovery_area VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORASTD'
*.log_archive_dest_2='SERVICE=ORASTD LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORA12C'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.FAL_SERVER=ORA12C
*.FAL_CLIENT=ORASTD
*.db_file_name_convert='/u01/app/oracle/oradata/ORA12C/','/u01/app/oracle/oradata/ORASTD/'
*.log_file_name_convert='/u01/app/oracle/oradata/ORA12C/','/u01/app/oracle/oradata/ORASTD/'
*.standby_file_management=auto

:wq

In standby server :-
Create the necessary directory structure:-
$ mkdir -p /u01/app/oracle/oradata/ORASTD/
$ mkdir -p /u01/app/oracle/admin/ORASTD/adump
$ mkdir -p /u01/app/oracle/oradata/ORASTD
$ mkdir -p /u01/app/oracle/fast_recovery_area/ORASTD/
$ chmod 775 -Rf /u01

Copy all data files, all redo log files and standby redo log file, standby controlfile, pfile from ORA12C to ORASTD database.

$ cd /u01/app/oracle/oradata/ORA12C
$ ll
-rw-r----- 1 oracle oinstall  10043392 Apr 16 09:57 control01.ctl
-rw-r----- 1 oracle oinstall  10043392 Apr 16 09:47 ORASTD.ctl
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:59 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:41 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:41 redo03.log
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:14 redos4A.log
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:14 redos5A.log
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:14 redos6A.log
-rw-r----- 1 oracle oinstall  52429312 Apr 15 12:14 redos7A.log
-rw-r----- 1 oracle oinstall 629153792 Apr 15 12:59 sysaux01.dbf
-rw-r----- 1 oracle oinstall 817897472 Apr 15 12:59 system01.dbf
-rw-r----- 1 oracle oinstall  62922752 Apr 15 12:42 temp01.dbf
-rw-r----- 1 oracle oinstall  62922752 Apr 15 12:59 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Apr 15 12:59 users01.dbf


$ scp *.log oracle@192.168.2.101:/u01/app/oracle/oradata/ORASTD/
oracle@192.168.2.101's password:
redo01.log                                                                                 100%   50MB  25.0MB/s   00:02  
redo02.log                                                                                 100%   50MB  50.0MB/s   00:00  
redo03.log                                                                                 100%   50MB  25.0MB/s   00:02  
redos4A.log                                                                                100%   50MB  50.0MB/s   00:01  
redos5A.log                                                                                100%   50MB  50.0MB/s   00:01  
redos6A.log                                                                                100%   50MB  50.0MB/s   00:01  
redos7A.log                                                                                100%   50MB  50.0MB/s   00:01  

$ scp *.dbf oracle@192.168.2.101:/u01/app/oracle/oradata/ORASTD/
oracle@192.168.2.101's password:
sysaux01.dbf                                                                               100%  600MB  35.3MB/s   00:17  
system01.dbf                                                                               100%  780MB  39.0MB/s   00:20  
temp01.dbf                                                                                 100%   60MB  60.0MB/s   00:01  
undotbs01.dbf                                                                              100%   60MB  30.0MB/s   00:02  
users01.dbf                                                                                100% 5128KB   5.0MB/s   00:00  

$ scp ORASTD.ctl oracle@192.168.2.101:/u01/app/oracle/oradata/ORASTD/
oracle@192.168.2.101's password:
ORASTD.ctl                                                                                 100% 9808KB   9.6MB/s   00:00  

Now copy the pfile
$ cd $ORACLE_HOME/dbs
$ scp initORASTD.ora oracle@192.168.2.101:/u01/app/oracle/product/12.1.0.2/db_1/dbs/

In standby server:-
copy the controlfile into 2nd location and rename it as control02.ctl

$ cd /u01/app/oracle/oradata/ORASTD
$ cp ORASTD.ctl /u01/app/oracle/fast_recovery_area/ORASTD/
$ cd  /u01/app/oracle/fast_recovery_area/ORASTD/
$ mv ORASTD.ctl control02.ctl

In standby server:-
Setup .bash_profile for standby database
$ 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 TMP=/u01/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=server4.soumya.com
export ORACLE_UNQNAME=ORASTD
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1
export ORACLE_SID=ORASTD
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


:wq

$ . .bash_profile


In primary database:-
Open the primary database

SQL> alter database open;

In standby database:-

Now start the standby database in mount stage

$ sqlplus / as sysdba

SQL> startup mount pfile='/u01/app/oracle/product/12.1.0.2/db_1/dbs/initORASTD.ora';
ORACLE instance started.
Total System Global Area  830930944 bytes
Fixed Size                  2293832 bytes
Variable Size             595595192 bytes
Database Buffers          230686720 bytes
Redo Buffers                2355200 bytes
Database mounted.

SQL> create spfile from pfile='/u01/app/oracle/product/12.1.0.2/db_1/dbs/initORASTD.ora';

Start Physical Standby Database :
SQL> alter database recover managed standby database disconnect from session;

In standby database :
SQL>select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;

Also check the above query in primary database also to confirm the archive log no:-
In Primary database:-
SQL> select sequence#, first_time, next_time,dest_id, thread# , standby_dest,  applied from v$archived_log order by sequence#;

In primary database :
sql>alter system switch logfile;

Note: if archive logfile is coming to prodcws database, that means configuration is correct till now.

Now for real time apply:-
Steps :

# In Standby Database

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;

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

After commit on primary, it will directly apply on standby database.

+++++ END +++++



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.



Shell script for redirecting output of rman command for oracle 11g

vi /backups/scripts/rmanoutput.sh

#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=prim
export PATH=$PATH:$ORACLE_HOME/bin
export NLS_DATE_FORMAT='DD-MON-YY HH24:MI:SS'
export DATE=$(date +%Y-%m-%d)

rman target sys/sys@prim msglog /u01/rman_full_backup_db_online_TEST1_${DATE}.log <<EOF

backup database plus archivelog;

exit;

EOF

:wq

P.S Output for currently executing RMAN jobs is also stored in the V$RMAN_OUTPUT view,
which reads only from memory (that is, the information is not stored in the control file).
The V$RMAN_STATUS view contains metadata about jobs in progress as well as completed jobs.
The metadata for completed jobs is stored in the control file.




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.

Few words on CPU, PSU, SPU - Oracle Critical Patch Update Terminology Update


It all started in January 2005 with Critical Patch Updates (CPU).Then Patch Set Updates (PSU) were added
as cumulative patches that included priority fixes as well as security fixes.  As of the October 2012
Critical Patch Update, Oracle has changed the terminology to better differentiate between patch types.
This terminology will be used for the Oracle Database, Enterprise Manager, Fusion Middleware, and
WebLogic.

Critical Patch Update (CPU) now refers to the overall release of security fixes each quarter rather
than the cumulative database security patch for the quarter.  Think of the CPU as the overarching
quarterly release and not as a single patch.

Patch Set Updates (PSU) are the same cumulative patches that include both the security fixes and
priority fixes.  The key with PSUs is they are minor version upgrades (e.g., 11.2.0.1.1 to 11.2.0.1.2).
Once a PSU is applied, only PSUs can be applied in future quarters until the database is upgraded to a
new base version.

Security Patch Update (SPU) terminology is introduced in the October 2012 Critical Patch Update as the
term for the quarterly security patch.  SPU patches are the same as previous CPU patches, just a new name.
For the database, SPUs can not be applied once PSUs have been applied until the database is upgraded to a
new base version.

Bundle Patches are the quarterly patches for Windows and Exadata which include both the quarterly security
patches as well as recommended fixes.



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.

Oracle 11.2.0.4 download link for x86_64

Oracle 11.2.0.4 download link for x86_64:-


p13390677_112040_Linux-x86-64_1of7.zip-https://1drv.ms/u/s!AojZQaghYsq5beB4JhCWGc8m-1E

p13390677_112040_Linux-x86-64_2of7.zip -https://1drv.ms/u/s!AojZQaghYsq5biIeThihzYoMyC0
p13390677_112040_Linux-x86-64_3of7.zip - https://1drv.ms/u/s!AojZQaghYsq5gQRQSKLSqpRG47uN

p13390677_112040_Linux-x86-64_4of7.zip -https://1drv.ms/u/s!Auolf32UbJXrexWWDLcIis1EQYw

p13390677_112040_Linux-x86-64_5of7.zip -https://1drv.ms/u/s!AojZQaghYsq5gQYfyLHITzpZK4R5


p13390677_112040_Linux-x86-64_6of7.zip -
https://1drv.ms/u/s!Auolf32UbJXreq7VmLvF-Iws6-U

p13390677_112040_Linux-x86-64_7of7.zip -https://1drv.ms/u/s!AojZQaghYsq5gQu-kZlsX_xshcDH




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.

How to move all types of datafiles from one location to another in oracle 11g


Oracle Version: 11g
OS Version: Rhel 6

Step 1. Check the datafiles location & tablespace name .
SQL> column file_name format a50
SQL> select file_name , tablespace_name from dba_data_files;
FILE_NAME                                          TABLESPACE_NAME
-------------------------------------------------- ------------------------------
/u01/app/oracle/oradata/prim/users01.dbf           USERS
/u01/app/oracle/oradata/prim/undotbs01.dbf         UNDOTBS1
/u01/app/oracle/oradata/prim/sysaux01.dbf          SYSAUX
/u01/app/oracle/oradata/prim/system01.dbf          SYSTEM
/u01/app/oracle/oradata/prim/example01.dbf         EXAMPLE
/u01/app/oracle/oradata/prim/GHHSTORE_DATA_TBS.dbf GHHSTORE_DATA_TBS

SQL> select file_name , tablespace_name from dba_temp_files;

FILE_NAME                                          TABLESPACE_NAME
-------------------------------------------------- ------------------------------
/u01/app/oracle/oradata/prim/temp01.dbf            TEMP

Step 2.Shutdown the database and  move the data files into new location.

SQL>shut immediate;
SQL>! mv /u01/app/oracle/oradata/prim/users01.dbf /u02/oradata/users01.dbf
SQL>! mv /u01/app/oracle/oradata/prim/undotbs01.dbf /u02/oradata/undotbs01.dbf
SQL>! mv /u01/app/oracle/oradata/prim/sysaux01.dbf  /u02/oradata/sysaux01.dbf
SQL>! mv /u01/app/oracle/oradata/prim/system01.dbf /u02/oradata/system01.dbf
SQL>! mv /u01/app/oracle/oradata/prim/GHHSTORE_DATA_TBS.dbf /u02/oradata/GHHSTORE_DATA_TBS.dbf
SQL>! mv /u01/app/oracle/oradata/prim/temp01.dbf /u02/oradata/temp01.dbf
Step 3. Start the database in mount point and rename the datafiles.

SQL> alter database rename file '/u01/app/oracle/oradata/prim/users01.dbf' to
'/u02/oradata/users01.dbf';

SQL> alter database rename file '/u01/app/oracle/oradata/prim/undotbs01.dbf' to
'/u02/oradata/undotbs01.dbf';

SQL> alter database rename file '/u01/app/oracle/oradata/prim/sysaux01.dbf' to
'/u02/oradata/sysaux01.dbf';

SQL> alter database rename file '/u01/app/oracle/oradata/prim/system01.dbf' to
'/u02/oradata/system01.dbf';

SQL> alter database rename file '/u01/app/oracle/oradata/prim/GHHSTORE_DATA_TBS.dbf' to
'/u02/oradata/GHHSTORE_DATA_TBS.dbf' ;

SQL> alter database rename file '/u01/app/oracle/oradata/prim/temp01.dbf' to
'/u02/oradata/temp01.dbf';

Step 4.Open the database and check datafile location.
SQL>alter database open;
SQL> column file_name format a50
SQL> select file_name , tablespace_name from dba_data_files;

FILE_NAME                                          TABLESPACE_NAME
-------------------------------------------------- ------------------------------
/u02/oradata/users01.dbf             USERS
/u02/oradata/undotbs01.dbf           UNDOTBS1
/u02/oradata/sysaux01.dbf           SYSAUX
/u02/oradata/system01.dbf             SYSTEM
/u02/oradata/example01.dbf           EXAMPLE
/u02/oradata/GHHSTORE_DATA_TBS.dbf   GHHSTORE_DATA_TBS

SQL> select file_name , tablespace_name from dba_temp_files;

FILE_NAME                          TABLESPACE_NAME
---------------------------------- ------------------------------
/u02/oradata/temp01.dbf            TEMP

Done..

Incase if we cant shutdown the database, we can still perform the activity except for system datafile
and undo datafile.However we can change the default undo tablespace by creating a new undo tablespace
and drop the old one.

For users or any non-default system datafile:-
SQL> alter tablespace users offline;
SQL> alter database rename file '/u01/app/oracle/oradata/prim/users01.dbf' to
'/u02/oradata/users01.dbf';
SQL>  alter tablespace users online;

SQL> select file_name , online_status , tablespace_name from dba_data_files where tablespace_name='USERS';

FILE_NAME                                          ONLINE_ TABLESPACE_NAME
-------------------------------------------------- ------- ------------------------------
/u02/oradata/users01.dbf                           ONLINE  USERS

For sysaux datafile:-
SQL> alter tablespace sysaux offline;

Tablespace altered.

SQL> ! mv /u01/app/oracle/oradata/prim/sysaux01.dbf /u02/oradata/sysaux01.dbf;
SQL> alter database rename file '/u01/app/oracle/oradata/prim/sysaux01.dbf' to '/u02/oradata/sysaux01.dbf';

Database altered.

SQL> alter tablespace sysaux online;

SQL> select file_name , online_status , tablespace_name from dba_data_files where tablespace_name='SYSAUX';

FILE_NAME                                          ONLINE_ TABLESPACE_NAME
-------------------------------------------------- ------- ------------------------------
/u02/oradata/sysaux01.dbf                          ONLINE  SYSAUX


For temporary datafile:-

SQL> SELECT FILE_NAME, TABLESPACE_NAME FROM DBA_TEMP_FILES;

FILE_NAME                                 TABLESPACE_NAME         STATUS
---------------------------------------- ----------------------  -------
/u01/app/oracle/oradata/prim/temp01.dbf      TEMP                   ONLINE

SQL> alter database tempfile '/u01/app/oracle/oradata/prim/temp01.dbf' offline;

Database altered.

SQL> ! mv /u01/app/oracle/oradata/prim/temp01.dbf /u02/oradata/temp01.dbf

SQL> alter database rename file '/u01/app/oracle/oradata/prim/temp01.dbf' to
'/u02/oradata/temp01.dbf';

Database altered.
SQL> SELECT FILE_NAME, TABLESPACE_NAME FROM DBA_TEMP_FILES;

FILE_NAME                                 TABLESPACE_NAME         STATUS
---------------------------------------- ----------------------  -------
/u02/oradata/temp01.dbf       TEMP                    OFFINE

SQL> alter database tempfile '/u02/oradata/temp01.dbf' online;

Database altered.
SQL> select file_name, tablespace_name , status from dba_temp_files;

FILE_NAME                                TABLESPACE_NAME                STATUS
---------------------------------------- ------------------------------ -------
/u02/oradata/temp01.dbf                  TEMP                           ONLINE


For system Datafile:-
We cant offline a system tablespace. so for the we need to shutdown the database and then
move it to the new location as describe before.


For undo datafile:-
We cant drop or move default undo tablespace.
First create a new undo tablespace and then drop the old one.
SQL> create undo tablespace undotbs2 datafile '/u02/oradata/undotbs01.dbf' size 100M;

Tablespace created.
SQL>  alter system set undo_tablespace= undotbs2 ;
SQL> drop tablespace undotbs1 including contents and datafiles;

Tablespace dropped.

SQL>select file_name , online_status , tablespace_name from dba_data_files where tablespace_name like 'UNDO%';

FILE_NAME                                ONLINE_ TABLESPACE_NAME
---------------------------------------- ------- ------------------------------
/u02/oradata/undotbs01.dbf               ONLINE  UNDOTBS2





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.

Related Posts Plugin for WordPress, Blogger...