日期:2014-05-16  浏览次数:20357 次

如何最大程度的 把表空间里面的数据给抢救出来
今天一朋友问到一个比较有意识的问题:
如果一个表空间,其中一个数据文件丢失,在无备份和非归档的情况下,如何最大程度的
把表空间里面的数据给抢救出来?

我当时直接的回答是,使用exp进行逻辑导出,当时对方直接说exp是不行的,真是这样吗?

这篇文章就的目的就是为了解答这个问题,首先准备下测试环境:
SQL> select file_id,file_name,bytes/1024/1024,tablespace_name,AUTOEXTENSIBLE
2  from dba_data_files order by 1;

FILE_ID FILE_NAME                                  BYTES/1024/1024 TABLESPACE_NAME   AUT
------- ------------------------------------------ --------------- ----------------- ---
1 /home/ora10g/oradata/roger/system01.dbf                450 SYSTEM            YES
2 /home/ora10g/oradata/roger/undotbs01.dbf               925 UNDOTBS1          YES
3 /home/ora10g/oradata/roger/sysaux01.dbf                260 SYSAUX            YES
4 /home/ora10g/oradata/roger/users01.dbf                   5 USERS             YES
5 /home/ora10g/oradata/roger/roger01.dbf                  10 ROGER             NO
6 /home/ora10g/oradata/roger/roger02.dbf                  10 ROGER             NO
7 /home/ora10g/oradata/roger/roger03.dbf                  10 ROGER             NO

7 rows selected.

SQL> create user roger identified by roger default tablespace roger;

User created.

SQL> grant connect,resource,dba to roger;

Grant succeeded.

SQL>
SQL> conn roger/roger
Connected.
SQL> create table killdb1 as select * from sys.dba_objects;

Table created.

SQL> create table killdb2 as select * from killdb1;

Table created.

SQL> begin
2  for i in 1..100 loop
3  insert /*+ append */into killdb2 select * from killdb2;
4  commit;
5  end loop;
6  end;
7  /
begin
*
ERROR at line 1:
ORA-01653: unable to extend table ROGER.KILLDB2 by 128 in tablespace ROGER
ORA-06512: at line 3

SQL> analyze table killdb1 compute statistics;

Table analyzed.

SQL> analyze table killdb2 compute statistics;

Table analyzed.

SQL> conn /as sysdba
Connected.
SQL> select distinct dbms_rowid.rowid_relative_fno(rowid) file#
2    from roger.killdb1
3  union all
4  select distinct dbms_rowid.rowid_relative_fno(rowid) file#
5    from roger.killdb2;

FILE#
----------
6
5
7
6
5
7

6 rows selected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORA-00000: normal, successful completion
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup mount