四、还原受损的临时表空间
1. 在session 1中删除临时表空间的数据文件
SQL> show user;
USER is "SYS"
SQL> ho rm /u01/app/Oracle/oradata/orcl/temp01.dbf
SQL> alter system checkpoint; -->执行检查点进程
System altered.
2. 在session 2中执行排序查询,提示临时数据文件错误
SQL> show user;
USER is "SCOTT"
SQL> set autotrace traceonly;
SQL> select owner,object_name from big_table order by id,owner,object_name;
select owner,object_name from big_table order by id,owner,object_name
*
ERROR at line 1:
ORA-01565: error in identifying file '/u01/app/oracle/oradata/orcl/temp01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
3. 在session 1中为临时表空间增加数据文件
SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/orcl/temp02.dbf'
2 size 30m autoextend on next 1m maxsize 2g;
Tablespace altered.
4. 在session 2中继续执行排序操作,此次执行成功
SQL> select owner,object_name from big_table order by id,owner,object_name;
1000000 rows selected.
5. 查询临时数据文件状态及文件存在性
SQL> set linesize 160 --> session 1中查看临时数据文件状态,大小为0,但仍然为online状态
SQL> select s.name tbsname,t.name,(t.bytes/1024/1024) bytes,t.status
2 from v$tablespace s,v$tempfile t
3 where s.ts# = t.ts#;
TBSNAME NAME BYTES STATUS
-------------------- --------------------------------------------- ---------- -------
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf 0 ONLINE
TEMP /u01/app/oracle/oradata/orcl/temp02.dbf 30 ONLINE
SQL> ho ls /u01/app/oracle/oradata/orcl/temp01.dbf
ls: /u01/app/oracle/oradata/orcl/temp01.dbf: No such file or directory
6. 清除控制文件内记录的不存在的临时文件信息
SQL> alter tablespace temp drop tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf';
Tablespace altered.
7. 基于表空间级别的恢复操作(下面给出主要步骤,不在演示)
a. 创建一个新的临时表空间
b. 使用alter database 将用户切换到新的临时表空间,即设置新的默认的临时表空间
c. 删除受损的临时表空间
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
