How to recover Oracle data when losting system tablespace?

Links: http://www.dbatools.net/mydul/aul-nosystem.html

    All the table structure informations are stored in system tablespace, in the user data tablespace, there are only a data object id and the rows you wanted. So we could scan all the data files and recover all the rows, but we actually do not know which table the rows belong, the relation ship between data object id and tables are stored in system tablespace. Following is a step by step example of using AUL/MyDUL to do recovery.

    I create a very small tablespace contains only one datafile (Download it for demo), and create several tables in this tablespace, insert few rows, then do a checkpoint or shutdown normal to force Oracle write everything to disk, as following:

SQL> CREATE TABLE TEST1 (COL1 VARCHAR2(10));
SQL> CREATE TABLE TEST2 (COL1 VARCHAR2(10));
SQL> CREATE TABLE TEST3 (COL1 VARCHAR2(10));

    Then we open the config file, use "SCAN TABLE TO filename" to get the object list by scanning all the data blocks. As following:

AUL> open db10g.cfg
*  ts#  fno  rfn ver bsize     blocks filename
- ---- ---- ---- --- ----- ---------- ----------------------
Y    5    5    5 a2   8192        256 AULTEST01.DBF
AUL> scan table to scan_table.log
2006-08-12 13:02:43
2006-08-12 13:02:43

    Then we open the scan_table.log file, you could see the following information, the line started with "CMD:" is the unload command AUL/MyDUL guessed for you, why I call it guess is because the column type maybe incorrect for unloading. For each distinct object, 5 sample rows will be printed in hex mode. By grep utilities in Unix/Linux, we could quickly get a script to unload all the tables (include dropped or truncated tables, even piece of dropped or truncated tables). Following is the result of the scan table:

RDBA=0x01400015(5/21),type=0x06,fmt=0xa2,seq=0x03,flag=0x06
seg/obj=0x000026fb=9979,csc=0x0000.000999cd,itc=2,typ=1 - DATA
tab#=  0     nrow=  11     offs=   0

545f50415254
545f4f424a454354
545f4c4f42
545f434c4f42
42494e24773455692b46
Column Count=1
CMD:UNLOAD OBJECT 9979 CLUSTER 0 COLUMN  VARCHAR

RDBA=0x0140001d(5/29),type=0x06,fmt=0xa2,seq=0x03,flag=0x06
seg/obj=0x000026fc=9980,csc=0x0000.000999cd,itc=2,typ=1 - DATA
tab#=  0     nrow=  11     offs=   0

545f50415254
545f4f424a454354
545f4c4f42
545f434c4f42
42494e24773455692b46
Column Count=1
CMD:UNLOAD OBJECT 9980 CLUSTER 0 COLUMN  VARCHAR

RDBA=0x01400025(5/37),type=0x06,fmt=0xa2,seq=0x03,flag=0x06
seg/obj=0x000026fd=9981,csc=0x0000.000999cd,itc=2,typ=1 - DATA
tab#=  0     nrow=  11     offs=   0

545f50415254
545f4f424a454354
545f4c4f42
545f434c4f42
42494e24773455692b46
Column Count=1
CMD:UNLOAD OBJECT 9981 CLUSTER 0 COLUMN  VARCHAR

    Then we test the unload commands generated, you will see rows are recovered, in this case the three tables contain same rows:

AUL> UNLOAD OBJECT 9979 CLUSTER 0 COLUMN  VARCHAR;
2006-08-12 13:17:52
T_PART
T_OBJECT
T_LOB
T_CLOB
BIN$w4Ui+F
BIN$JRhlBf
TEST
TEST2
BIN$IRebiY
TEST1
TEST3
2006-08-12 13:17:52
AUL> UNLOAD OBJECT 9980 CLUSTER 0 COLUMN  VARCHAR;
2006-08-12 13:18:01
T_PART
T_OBJECT
T_LOB
T_CLOB
BIN$w4Ui+F
BIN$JRhlBf
TEST
TEST2
BIN$IRebiY
TEST1
TEST3
2006-08-12 13:18:01
AUL> UNLOAD OBJECT 9981 CLUSTER 0 COLUMN  VARCHAR;
2006-08-12 13:18:09
T_PART
T_OBJECT
T_LOB
T_CLOB
BIN$w4Ui+F
BIN$JRhlBf
TEST
TEST2
BIN$IRebiY
TEST1
TEST3
2006-08-12 13:18:09

    Even with this command, the recovery of lost system tablespace is more complex. Enjoy it.

Post a comment

Remember Me?

« Previous | Main | Next »

Powered by
Movable Type 4.25