Thursday, 20 March 2014

Recovering Tablespace was lost


How to recover a lost tablespace?

Till now we have seen recovering of physical files. Now we will be doing recovery of a logical object say tablespace.
Let us take an example case as follows:
Someone has dropped my tablespace at 4 pm today by mistake. After some time(6 PM same day) that guy came to me and asked for his tablespace back as it is required for business continuity saying the approximate time that he had dropped the tablespace. Now i have to get the tablespace and its contents.
I can do it in 2 ways.
(A)I can flash back it till before drop (if and only if flash back is enabled)
(B)Tablespace point in time recovery

Now before proceeding further try to understand the plan in the next 5 points mentioned below.

1. Yesterday i took the database HOT backup at 2 A.M. and i had archive logs available with me till now.
2. I will stop the database, restore it and recover the database till 3:59 PM today.so my database is at 3:59 today.
3. After finding my tablespace i will export it to a dump file and keep it in some path.
4. Now i will take trace of control file and start recovering database from 3:59 pm to till 6 pm.
5. Now the database came to as usual state without tablespace. Now i will import the tablespace.
So finally i will get my tablespace back.


We shall follow the steps by doing it practically as below:
1. Now the time is 6 pm. Best time to leave office. But we (DBA) are doers.so let’s do it. Take the HOT backup before proceeding.
SQL>alter database begin backup;
]~ cp   /u01/oracle/app/oradata/pavan/database_1/  /u01/oracle/app/oradata/pavan/database_1/HOT_BKP/*.dbf
SQL>alter database end backup;
SQL>alter database backup controlfile to trace as '/tmp/ttt.sql';
In the above step i am taking back up of controlfile in text format for future recovery purposes. I found my archive log files also in the path mentioned in init.ora.

2. Shut down the database in normal mode.
SQL>shut immediate/shutdown
SQL>select status from v$instance;
If you are not confident about the success of rest of activity you can take cold backup also along with it.
Now we are going restore the backup taken at 2AM yesterday night.
SQL>alter database begin backup;
}~cp /u01/oracle/app/oradata/pavan/database_1/lastnight_bkp/*.dbf /u01/oracle/app/oradata/pavan/database_1/
SQL>startup mount
Recover the database till 3:59 pm
SQL>alter database recover automatic using backup controlfile until time '2014:03:20:15:59:00';
SQL>alter database open RESETLOGS;

3. Now we took our database to 3:59 pm today. So this is the right time. Find your tablespace and export it to any path.
cd /tmp/
]~exp system/system file=ts2.dmp log=ts2.log tablespace_name=TS2;

4. Exporting of tablespace is done. Now i have to take my database to 6 pm today.
Tell me one thing: should i restore backup of yesterday night (2 A.M) and recover till 6 pm?
Or else
Should i recreate my control file using backup trace taken at step-1 and then start recovering till 6 pm (3:59 pm to 6 pm)?
The second one is preferable because it will reduce downtime.
So start recovering from 3:59 pm today. But for doing recovery some disaster should happen. What shall i do? I will take backup of my control file and will drop it.
So it needs recovery now.
]~ cp ontrol.ctl /tmp/
]~ rm control.ctl
SQL>shut abort
How shall i do now?
Now open your /tmp/ttt.sql and remove unnecessary rows
SQL>startup nomount
SQL>@/tmp/ttt.sql
SQL>select status from v$instance;
Now the database will be in mount state and control file will be created during above step.
Now start recovering database
SQL> recover database using backup controlfile until cancel;
SQL>alter database open resetlogs;
5. Now i had my database to normal stage and i have dump of tablespace. Import it and check in v$tablespace;
 imp system/system file =ts2.dmp tablespaces='TS2'



Errors i faced during above process:
1. ORA-00283: recovery session canceled due to errors
ORA-01111: name for data file 5 is unknown - rename to correct file
ORA-01110: data file 5:
'/u01/oracle/app/product/11.2.0.4/dbhome_1/dbs/UNNAMED00005'
This error occurred to me at step-2 while recovering
Solution: it is expecting a file in /u01/oracle/app/product/11.2.0.4/dbhome_1/dbs/UNNAMED00005 location.so to avoid that just create the file and remap it to our original data file as mentioned below.
SQL>alter database create datafile  '/u01/oracle/app/product/11.2.0.4/dbhome_1/dbs/UNNAMED00005' as '/u01/oracle/app/oradata/pavan/database_1/ts2.dbf';

2. ORA-10562: Error occurred while applying redo to data block (file# 2, block#414)
ORA-10564: tablespace SYSAUX
ORA-01110: data file 2: '/u01/oracle/app/oradata/pavan/database_1/sysaux01.dbf'
ORA-10561: block type 'TRANSACTION MANAGED INDEX BLOCK', data object# 15929
ORA-00607: Internal error occurred while making a change to a data block
ORA-00602: internal programming exception
ORA-07445: exception encountered: core dump [kdxlin()+4088] [SIGSEGV]
[ADDR:0xC] [PC:0x95FB47E] [Address not mapped to object] []
It occurred to me at step-4 while recovering database until cancel
This error means it applied all archive logs and unable to apply transactions from redo files. So while recovering gives the file name of redo which is active and current then it will recover easily.




Cheers.....!!!!!

No comments:

ORA-600 [kwqitnmphe:ltbagi], [1], [0] reported in the alert log file.

ORA-00600 [kwqitnmphe:ltbagi] Cause: This issue arises in 12.1.0.2. The error occurs because there are still Historical Messages without...