情况2:只读-读写
注:是在情况1的环境下继续测试的。
1.将只读表空间修改为读写
SYS@ORA11GR2>alter tablespace ts_lob read write;
Tablespace altered.
2.删除状态为read write的表空间TS_LOB的物理文件
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
/u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
SYS@ORA11GR2>!rm /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
——验证:
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
ls: /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf: No such file or directory
3.利用之前的只读数据文件进行恢复
SYS@ORA11GR2>!cp /home/oracle/ts_lob01.dbf /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
SYS@ORA11GR2>
SYS@ORA11GR2>shutdown immediate;
ORA-03113: end-of-file on communication channel
Process ID: 19101
Session ID: 1 Serial number: 5
SYS@ORA11GR2>conn / as sysdba
Connected to an idle instance.
SYS@ORA11GR2>
SYS@ORA11GR2>startup
ORACLE instance started.
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 452984896 bytes
Database Buffers 272629760 bytes
Redo Buffers 2842624 bytes
Database mounted.
ORA-01113: file 3 needs media recovery
ORA-01110: data file 3: '/u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf'
SYS@ORA11GR2>select status from v$instance;
STATUS
------------
MOUNTED
SYS@ORA11GR2>recover datafile 3;
(应用日志从备份时read only 恢复到read write,即online)
Media recovery complete.
——开库:
SYS@ORA11GR2>alter database open;
Database altered.
——验证:(表空间已经恢复到ONLINE模式)
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_LOB';
TABLESPACE_NAME STATUS
---------------- ---------
TS_LOB ONLINE
SYS@ORA11GR2>delete tchar where x=1;
1 row deleted.
SYS@ORA11GR2>commit;
Commit complete.
6.在线恢复
--再次删除TS_LOB的数据文件(注意此时表孔间ts_lob状态为online)
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
/u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
SYS@ORA11GR2>
SYS@ORA11GR2>!rm /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
SYS@ORA11GR2>
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
ls: /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf: No such file or directory
--将表空间改为离线模式
SYS@ORA11GR2>alter tablespace ts_lob offline;
Tablespace altered.
——查看数表空间对应的数据文件路径及状态:
SYS@ORA11GR2>select file_id,file_name,status,online_status from dba_data_files where tablespace_name='TS_LOB';
FILE_ID FILE_NAME STATUS ONLINE
3 /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf AVAILABLE OFFLINE
——查看表空间的状态:
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_LOB';
TABLESPACE_NAME STATUS
---------------- ---------
TS_LOB OFFLINE
--从之前的只读备份中恢复丢失的数据文件
SYS@ORA11GR2>!cp /home/oracle/ts_lob01.dbf /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf
--此时将表空间改为在线模式,此处一定是报错的,因为我们是用只读的数据文件进行恢复在线的日志;
SYS@ORA11GR2>alter tablespace ts_lob online;
alter tablespace ts_lob online
*
ERROR at line 1:
ORA-01113: file 3 needs media recovery
ORA-01110: data file 3: '/u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf'
--恢复数据文件
SYS@ORA11GR2>recover datafile 3;
(应用日志从备份时read only 恢复到read write,即online)
Media recovery complete.
--此时可正常将表空间online
SYS@ORA11GR2>alter tablespace ts_lob online;
Tablespace altered.
验证:
SYS@ORA11GR2>select file_id,file_name,status,online_status from dba_data_files where tablespace_name='TS_LOB';
FILE_ID FILE_NAME STATUS ONLINE_
---------- --------------------------------------------- --------- -------
3 /u01/app/oracle/oradata/ORA11GR2/ts_lob01.dbf AVAILABLE ONLINE
SYS@ORA11GR2>select tablespace_name,status from dba_tablespaces where tablespace_name='TS_LOB';
TABLESPACE_NAME STATUS
---------------- ---------
TS_LOB ONLINE
——而且可以进行DML操作:
SYS@ORA11GR2>delete tchar where x=2;
1 row deleted.
SYS@ORA11GR2>commit;
Commit complete.
SYS@ORA11GR2>
SYS@ORA11GR2>insert into tchar values(2);
1 row created.
SYS@ORA11GR2>commit;
Commit complete.
完成!!!!!!!!!