ORACLE模拟临时文件、日志成员、口令文件丢失情况与恢复【weber出品】
2014-09-29 21:08 yaoweber 阅读(1334) 评论(0) 编辑 收藏 举报一、临时表空间文件、日志文件和口令文件都属于非关键性文件,因为这些文件丢失后并不会影响到整个数据库的完整性。
但是,当这些文件丢失后我们需要快速的找回这些文件。接下来我将模拟临时表空间文件、日志文件和口令文件丢失的情况。
二、如果属于 TEMP 表空间的临时文件丢失或损坏,则 TEMP 表空间将不可用。例如:在执行需要 TEMP 空间进行排序的 SQL 语句过程中,此问题将声明其为错误。
一般会用到临时表空间的场景有:
索引create或rebuild
select NAME from v$tempfile; NAME -------------------------------------------------------------------------------- /u01/oracle/oradata/orcl/temp02.dbf SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 192M SQL> alter system set pga_aggregate_target=10M;
把pga_aggregate_target给调小些,这样order by的时候就一定会用到临时文件了。
rm -rf /u01/oracle/oradata/orcl/temp02.dbf
创建模拟表
SQL> conn scott/tiger SQL> create table temp_table as select * from all_objects; SQL> insert into temp_table select * from all_objects; SQL> commit; SQL> SQL> select * from temp_table order by 1,2,3,4,5,6,7,8,9,10,11,12,13; select * from temp_table order by 1,2,3,4,5,6,7,8,9,10,11,12,13 * ERROR at line 1: ORA-01116: error in opening database file 201 ORA-01110: data file 201: '/u01/oracle/oradata/orcl/temp01.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3
不需要重新启动数据库就可以恢复丢失的 TEMPFILE。
如果要恢复数据库,可以先在数据库中添加一个新的数据文件,然后删除那个已在 OS 层删除的数据文件。
SQL> conn / as sysdba Connected. SQL> ALTER TABLESPACE temp ADD TEMPFILE '/u01/oracle/oradata/orcl/temp02.dbf' SIZE 20M; Tablespace altered. SQL> ALTER TABLESPACE temp DROP TEMPFILE '/u01/oracle/oradata/orcl/temp01.dbf'; Tablespace altered. SQL> select name from v$tempfile; NAME -------------------------------------------------------------------------------- /u01/oracle/oradata/orcl/temp02.dbf
再次执行order by的语句就可以成功了。因为临时文件的内容不是非常的重要,属于可有可无的那种,没有了重建就是了。
select a.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile b where a.group#=b.group# order by 1; GROUP# SEQUENCE# ARC STATUS MEMBER ------ --------- --- -------- ------------------------------------------ 1 15 YES CURRENT /u01/oracle/oradata/orcl/redo01.log 1 15 YES CURRENT /u01/oracle/oradata/orcl/redo0101.log 2 17 NO INACTIVE /u01/oracle/oradata/orcl/redo0201.log 2 17 NO INACTIVE /u01/oracle/oradata/orcl/redo02.log 3 16 YES INACTIVE /u01/oracle/oradata/orcl/redo0301.log 3 16 YES INACTIVE /u01/oracle/oradata/orcl/redo03.log SQL> !rm -rf /u01/oracle/oradata/orcl/redo01.log SQL> !rm -rf /u01/oracle/oradata/orcl/redo0101.log
接下来将current转换成active状态:
SQL> alter system switch logfile;--先让其变成ACTIVE System altered. SQL> select a.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile b where a.group#=b.group# order by 1; 2 3 GROUP# SEQUENCE# ARC STATUS MEMBER ------ --------- --- -------- ------------------------------------------ 1 22 NO ACTIVE /u01/oracle/oradata/orcl/redo01.log 1 22 NO ACTIVE /u01/oracle/oradata/orcl/redo0101.log 2 23 NO CURRENT /u01/oracle/oradata/orcl/redo0201.log 2 23 NO CURRENT /u01/oracle/oradata/orcl/redo02.log 3 21 YES INACTIVE /u01/oracle/oradata/orcl/redo0301.log 3 21 YES INACTIVE /u01/oracle/oradata/orcl/redo03.log 6 rows selected. SQL> alter system checkpoint;--再让其变成INACTIVE System altered. SQL> select a.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile b where a.group#=b.group# order by 1; 2 3 GROUP# SEQUENCE# ARC STATUS MEMBER ------ --------- --- -------- ------------------------------------------ 1 22 NO INACTIVE /u01/oracle/oradata/orcl/redo01.log 1 22 NO INACTIVE /u01/oracle/oradata/orcl/redo0101.log 2 23 NO CURRENT /u01/oracle/oradata/orcl/redo0201.log 2 23 NO CURRENT /u01/oracle/oradata/orcl/redo02.log 3 21 YES INACTIVE /u01/oracle/oradata/orcl/redo0301.log 3 21 YES INACTIVE /u01/oracle/oradata/orcl/redo03.log 6 rows selected.
关闭数据库,启动到mounted状态下:
SQL> shutdown immediate
SQL>startup mount
SQL>alter database clear unarchived logfile group 1---清除
SQL> alter database open;
Database altered.
SQL> select a.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile b
where a.group#=b.group#
order by 1; 2 3
GROUP# SEQUENCE# ARC STATUS MEMBER
------ --------- --- -------- ------------------------------------------
1 24 NO CURRENT /u01/oracle/oradata/orcl/redo01.log
1 24 NO CURRENT /u01/oracle/oradata/orcl/redo0101.log
2 23 YES INACTIVE /u01/oracle/oradata/orcl/redo0201.log
2 23 YES INACTIVE /u01/oracle/oradata/orcl/redo02.log
3 21 YES INACTIVE /u01/oracle/oradata/orcl/redo0301.log
3 21 YES INACTIVE /u01/oracle/oradata/orcl/redo03.log
好了,这样重做日志组1就回来了。不过,current日志组的成员如果一旦两个都坏了,虽然整个数据还是完整的,但是如果想要恢复current这个业务之前的状态就有不可以了。
删除口令文件:
cd $ORACLE_HOME/dbs/
rm -rf orapworcl
使用操作系统验证登陆数据库:
[oracle@nylg dbs]$ sqlplus sys/a@orcl as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 18 08:40:01 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. ERROR: ORA-01031: insufficient privileges Enter user-name:
口令文件丢失,使用口令验证无法登陆,只能通过操作系统验证登陆
[oracle@nylg dbs]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 18 08:40:55 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL>
将 REMOTE_LOGIN_PASSWORDFILE 参数设置为 NONE 并重新启动数据库
REMOTE_LOGIN_PASSWORDFILE 参数有三个值:
NONE:禁止使用口令登陆
EXCLUSIVE:主要是针对于多实例来说的,如果数据库是多实例的,也就是RAC,只允许某个单实例使用口令文件
SHARE:主要是针对于多实例来说的,如果数据库是多实例的,也就是RAC,允许所有的实例共享使用一个口令文件
alter system set REMOTE_LOGIN_PASSWORDFILE=NONE scope=spfile startup force
使用口令实用程序orapwd创建口令文件
orapwd file=filename password=password entries=max_users
其中:
filename 是口令文件的名称
password 是 SYSOPER 和 SYSDBA 的口令
Entries 是允许以 SYSDBA 或 SYSOPER 身份连接的最大不同用户数
如果超出了此数值,必须创建新口令文件,使用较大的数值比较保险
等号 (=) 字符两边没有空格
orapwd file=$ORACLE_HOME/dbs/orapworcl password=a entries=5 alter system set REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE; startup force
使用在创建的口令文件连接到数据库
CONNECT sys/a@orcl AS SYSDBA