Oracle 备份恢复实例讲解
Oracle 备份恢复实例:三思笔记
1 shutdown abort
系统归档模式,有备份
create table xx as
select * from emp;
update xx set ename ='xxxxxx';
select * from xx
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 19 14:13:27 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup;---启动需要实例恢复
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 79693392 bytes
Database Buffers 201326592 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
--更新了未提交的数据,重新open后,被回滚
2 shutdown immediate,undo丢失
update xx set ename ='xxxxxx';
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@localhost grs]$ mv undotbs01.dbf /u01/oracle/backup/
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 79693392 bytes
Database Buffers 201326592 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'
[oracle@localhost grs]$ rman target/
Recovery Manager: Release 10.2.0.1.0 - Production on Wed Mar 19 14:38:53 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GRS (DBID=325518186, not open)
RMAN> restore datafile 2;
Starting restore at 19-MAR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1 tag=TAG20140318T154813
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
Finished restore at 19-MAR-14
RMAN> recover datafile 2;
Starting recover at 19-MAR-14
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 61 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_61_830623455.dbf
archive log thread 1 sequence 62 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_62_830623455.dbf
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=60
channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman1104_backup_1up3gc8s_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/oracle/backup/rman1104_backup_1up3gc8s_1_1 tag=TAG20140318T154948
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/archivelog/archivelog/1_60_830623455.dbf thread=1 sequence=60
media recovery complete, elapsed time: 00:00:21
Finished recover at 19-MAR-14
RMAN> alter database open;
database opened
RMAN>
3 undo丢失,有备份
[oracle@localhost grs]$ rm undotbs01.dbf
SQL> shutdown immediate;
ORA-01116: error in opening database file 2
ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
RMAN> restore datafile 2;
Starting restore at 19-MAR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/oracle/backup/rman1104_backup_1tp3gc5t_1_1 tag=TAG20140318T154813
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
Finished restore at 19-MAR-14
RMAN> recover datafile 2;
Starting recover at 19-MAR-14
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 60 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_60_830623455.dbf
archive log thread 1 sequence 61 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_61_830623455.dbf
archive log thread 1 sequence 62 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_62_830623455.dbf
archive log filename=/u01/app/oracle/archivelog/archivelog/1_60_830623455.dbf thread=1 sequence=60
media recovery complete, elapsed time: 00:00:13
Finished recover at 19-MAR-14
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 71304784 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database datafile 2 offline drop;
Database altered.
SQL> alter database open;
Database altered.
SQL> alter database datafile 2 online;
Database altered.
4 shutdown abort,无备份,undo丢失
update xx set ename ='xxxxxx';
select s.sid,s.serial#,t.used_ublk,r.status,s.username,r.segment_name
from gv$transaction t, gv$session s, dba_rollback_segs r
where t.ses_addr = s.saddr and t.xidusn = r.segment_id and r.tablespace_name='UNDOTBS1';
144 5 1 ONLINE SCOTT _SYSSMU11$
SQL> shutdown abort;
ORACLE instance shut down.
[oracle@localhost grs]$ mv undotbs01.dbf /u01/oracle/backup/
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 71304784 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'
SQL> col error format a15
SQL> set linesize 1000
SQL> set pagesize 1000
SQL> select * from v$recover_file;--查看那个文件需要恢复
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- --------------- ---------- ------------------
2 ONLINE ONLINE FILE NOT FOUND 0
SQL> alter database datafile 2 offline drop;
---设置为offline并删除(逻辑上)
Database altered.
SQL> alter database open;
--db可以打开
Database altered.
SQL> conn
Enter user-name: scott
Enter password:
Connected.
SQL> select * from xx;
select * from xx
*
ERROR at line 1:
ORA-00376: file 2 cannot be read at this time
ORA-01110: data file 2: '/u01/app/oracle/oradata/grs/undotbs01.dbf'
SQL> select * from v$datafile;--能看见删除的undo dbf
create pfile='/u01/app/oracle/pfile1' from spfile;
[oracle@localhost grs]$ vi /u01/app/oracle/pfile1
grs.__db_cache_size=209715200
grs.__java_pool_size=4194304
grs.__large_pool_size=4194304
grs.__shared_pool_size=58720256
grs.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/grs/adump'
*.background_dump_dest='/u01/app/oracle/admin/grs/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/oradata/grs/control01.ctl','/u01/app/oracle/oradata/grs/control02.ctl','/u01/app/oracle/oradata/grs/control03.ctl'#Restore Controlfile
*.core_dump_dest='/u01/app/oracle/admin/grs/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='grs'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=grsXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/u01/app/oracle/archivelog/archivelog/'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=285212672
*.undo_management='MANUAL'-----改为manual
*.undo_tablespace='UNDOTBS1'
*._corrupted_rollback_segments=(_SYSSMU1$,_SYSSMU2$,_SYSSMU3$,_SYSSMU4$,_SYSSMU5$,_SYSSMU6$,_SYSSMU7$,_SYSSMU8$,_SYSSMU9$,_SYSSMU10$,_SYSSMU11$)----添加
*._allow_resetlogs_corruption=true---隐藏参数
*.user_dump_dest='/u01/app/oracle/admin/grs/udump'
~
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup pfile='/u01/app/oracle/pfile1' mount;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 71304784 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> recover database until cancel;
Media recovery complete.
SQL> ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/grs/undotbs01.dbf' OFFLINE DROP;
Database altered.
SQL> alter database open resetlogs;
Database altered.
SQL> SELECT SEGMENT_NAME, OWNER, TABLESPACE_NAME, STATUS FROM DBA_ROLLBACK_SEGS;
SEGMENT_NAME OWNER TABLESPACE_NAME STATUS
------------------------------ ------ ------------------------------ ----------------
SYSTEM SYS SYSTEM ONLINE
_SYSSMU11$ PUBLIC UNDOTBS1 NEEDS RECOVERY
SQL> DROP ROLLBACK SEGMENT "_SYSSMU11$";---出现次错误,检查写法是否正确,关闭db,在pfile中的参数*._corrupted_rollback_segments中增加"_SYSSMU11$"
DROP ROLLBACK SEGMENT "_SYSSMU11$"
*
ERROR at line 1:
ORA-30025: DROP segment '_SYSSMU11$' (in undo tablespace) not allowed
SQL> DROP ROLLBACK SEGMENT "_SYSSMU11$";
Rollback segment dropped.
SQL> DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
Tablespace dropped.
SQL> create undo tablespace UNDOTBS1 datafile '/u01/app/oracle/oradata/grs/undotbs01.dbf' size 100m;
Tablespace created.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@localhost grs]$ vi /u01/app/oracle/pfile1----修改的另外一个pfile的副本
---去掉隐藏参数,
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=285212672
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/grs/udump'
SQL> startup;-----这里默认启用spfile,
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 71304784 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
5 归档,rman全备份,控制文件全部丢失
update xx set ename='20134978'
select * from xx
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@localhost grs]$ mv control01.ctl control02.ctl control03.ctl ./control_backup/
---移除控制文件
[oracle@localhost grs]$ ll
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 75499088 bytes
Database Buffers 205520896 bytes
Redo Buffers 2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info
--启动报错
查看alert 日志
[oracle@localhost grs]$ tail -f -n 20 /u01/app/oracle/admin/grs/bdump/alert_grs.log
LGWR started with pid=6, OS id=28040
CKPT started with pid=7, OS id=28042
SMON started with pid=8, OS id=28044
RECO started with pid=9, OS id=28046
CJQ0 started with pid=10, OS id=28048
MMON started with pid=11, OS id=28050
Thu Mar 20 16:25:14 2014
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
MMNL started with pid=12, OS id=28052
Thu Mar 20 16:25:14 2014
starting up 1 shared server(s) ...
Thu Mar 20 16:25:15 2014
ALTER DATABASE MOUNT
Thu Mar 20 16:25:15 2014
ORA-00202: control file: '/u01/app/oracle/oradata/grs/control01.ctl'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Thu Mar 20 16:25:18 2014
ORA-205 signalled during: ALTER DATABASE MOUNT...
[oracle@localhost grs]$ rman target/
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Mar 20 16:26:40 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: grs (not mounted)
RMAN> set DBID=325518186
executing command: SET DBID
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
RMAN> restore controlfile from '/u01/oracle/backup/rman_backup_c-325518186-20140320-01';
Starting restore at 20-MAR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
output filename=/u01/app/oracle/oradata/grs/control01.ctl
output filename=/u01/app/oracle/oradata/grs/control02.ctl
output filename=/u01/app/oracle/oradata/grs/control03.ctl
Finished restore at 20-MAR-14
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> recover database;
Starting recover at 20-MAR-14
Starting implicit crosscheck backup at 20-MAR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 20-MAR-14
Starting implicit crosscheck copy at 20-MAR-14
using channel ORA_DISK_1
Finished implicit crosscheck copy at 20-MAR-14
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/oradata/grs/redo02.log
archive log filename=/u01/app/oracle/oradata/grs/redo02.log thread=1 sequence=7
media recovery complete, elapsed time: 00:00:01
Finished recover at 20-MAR-14
RMAN> alter database open resetlogs;
以控制文件恢复,需要resetlogs方式打开db
database opened
RMAN>
select * from xx
查看数据正常
6 归档,无备份,控制文件全部丢失
--从新创建控制文件
在internal或sys 下运行如下创建控制文件的脚本,注意完整列出联机日志或数据文件的路径,或修改由 alter database backup control file to trace 备份控制文件时产生的脚本,去掉多余的注释即可。
SQL> alter database backup controlfile to trace as'/u01/oracle/backup/control_trace.sql';
Database altered.
user_dump_dest
alter database backup controlfile to trace as'/u01/oracle/backup/control_trace.sql';
idle> recover database using backup controlfile until cancel;
CREATE CONTROLFILE REUSE DATABASE grs2 NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u02/app/oracle/oradata/grs2/redo01.log' SIZE 50M,
GROUP 2 '/u02/app/oracle/oradata/grs2/redo02.log' SIZE 50M,
GROUP 3 '/u02/app/oracle/oradata/grs2/redo03.log' SIZE 50M
DATAFILE
'/u02/app/oracle/oradata/grs2/system01.dbf',
'/u02/app/oracle/oradata/grs2/undotbs01.dbf',
'/u02/app/oracle/oradata/grs2/sysaux01.dbf',
'/u02/app/oracle/oradata/grs2/users01.dbf',
'/u02/app/oracle/oradata/grs2/example01.dbf',
'/u02/app/oracle/oradata/grs2/yyhhqq.dbf',
'/u02/app/oracle/oradata/grs2/cmask01.dbf',
'/u02/app/oracle/oradata/grs2/rman_catalog.dbf',
'/u02/app/oracle/oradata/grs2/rman_test.dbf',
'/u02/app/oracle/oradata/grs2/data_test.dbf'
CHARACTER SET AL32UTF8
;
7 归档,有备份,非当前redo丢失
update xx set ename='erererl' 未commit
[oracle@localhost grs]$ rm redo03.log
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 75499088 bytes
Database Buffers 205520896 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/grs/redo03.log'
SQL> set linesize 1000
SQL> set pagesize 1000
SQL> select * from v$log;----日志3是未使用状态
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------
1 1 2 52428800 1 NO CURRENT 3252428 21-MAR-14
3 1 0 52428800 1 YES UNUSED 0
2 1 1 52428800 1 YES INACTIVE 3219698 20-MAR-14
SQL> alter database clear logfile group 3;---重建该组重做日志组
如果是该日志组还没有归档,则需要用
> alter database clear unarchived logfile group 3;
Database altered.
SQL> alter database open;
Database altered.
select * from xx;---未提交的,回滚
说明:
1、如果损坏的是非当前的联机日志文件,一般只需要 clear 就可以重建该日志文件,但是如果该数据库处于归档状态但该日志还没有归档,就需要强行 clear。
2、建议clear,特别是强行 clear后作一次数据库的全备份。
3、此方法适用于归档与非归档数据库。
http://www.itpub.net/thread-1824825-1-1.html
总结,对于不是当前使用的归档日志损坏,归档模式需要使用alter database clear unarchived 命令清空日志 组即可。对于非归档模式需要使用alter system clear 日志文件组即可。
8 丢失当前redo,归档,有备份
归档模式下当前日志的损坏有两种情况:
一、是数据库是正常关闭,日志文件中没有未解决的事务需要实例恢复,当前日志组的损坏就可以直接用alter database clear unarchived logfile group n 来重建。
二、是日志组中有活动的事务,数据库需要媒体恢复,日志组需要用来同步,有两种补救办
法:
A.最好的办法就是通过不完全恢复,可以保证数据库的一致性,但是这种办法要求在归档方式下,并且有可用的备份。
B.通过强制性恢复,但是可能导致数据库不一致。
下面分别用来说明这两种恢复方法
1 归档有备份,采用不完全恢复
select * from v$log;
1 1 2 52428800 1 YES INACTIVE 3252428 2014-3-21 5:31:00
2 1 1 52428800 1 YES INACTIVE 3219698 2014-3-20 16:29:31
3 1 3 52428800 1 NO CURRENT 3271167 2014-3-21 14:36:45
--删除文件3
[oracle@localhost grs]$ rm redo03.log
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 75499088 bytes
Database Buffers 205520896 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/grs/redo03.log'
SQL> alter database clear unarchived logfile group 3;
alter database clear unarchived logfile group 3
*
ERROR at line 1:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/grs/redo03.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 2 YES INACTIVE
3 0 NO CLEARING_CURRENT
2 0 YES UNUSED
RMAN> restore database;
Starting restore at 21-MAR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=151 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/grs/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/grs/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/grs/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/grs/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/grs/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/grs/yyhhqq.dbf
restoring datafile 00007 to /u01/app/oracle/oradata/grs/cmask01.dbf
restoring datafile 00008 to /u01/app/oracle/oradata/grs/rman_catalog.dbf
restoring datafile 00009 to /u01/app/oracle/oradata/grs/rman_test.dbf
channel ORA_DISK_1: reading from backup piece /u01/oracle/backup/rman_backup_2gp3lmi7
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/oracle/backup/rman_backup_2gp3lmi7 tag=TAG20140320T161606
channel ORA_DISK_1: restore complete, elapsed time: 00:04:28
Finished restore at 21-MAR-14
RMAN> run{
2> sql'alter session set nls_date_format="YYYY-MM-DD HH24:MI:SS"';
3> set until time '2014-03-21 15:45:04';
4> recover database;
5> };
sql statement: alter session set nls_date_format="YYYY-MM-DD HH24:MI:SS"
executing command: SET until clause
Starting recover at 21-MAR-14
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 6 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_6_842630868.dbf
archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_7_842630868.dbf
archive log thread 1 sequence 1 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_1_842718571.dbf
archive log thread 1 sequence 2 is already on disk as file /u01/app/oracle/archivelog/archivelog/1_2_842718571.dbf
archive log filename=/u01/app/oracle/archivelog/archivelog/1_6_842630868.dbf thread=1 sequence=6
archive log filename=/u01/app/oracle/archivelog/archivelog/1_7_842630868.dbf thread=1 sequence=7
archive log filename=/u01/app/oracle/archivelog/archivelog/1_1_842718571.dbf thread=1 sequence=1
unable to find archive log
archive log thread=1 sequence=3
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/21/2014 16:06:52
RMAN-06054: media recovery requesting unknown log: thread 1 seq 3 lowscn 3271167
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found ";": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"
RMAN-01007: at line 0 column 2 file: standard input
RMAN>
SQL> alter database open resetlogs;
Database altered.
2 采用隐藏的初始化参数来恢复
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 75499088 bytes
Database Buffers 205520896 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/grs/redo01.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 2 NO CURRENT
3 1 YES INACTIVE
2 0 YES UNUSED
SQL> alter database clear unarchived logfile group 1;
alter database clear unarchived logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance grs (thread 1)
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/grs/redo01.log'
SQL> alter system set "_allow_resetlogs_corruption"=TRUE scope=spfile;
System altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 75499088 bytes
Database Buffers 205520896 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> recover database until cancel;
ORA-00279: change 3273739 generated at 03/21/2014 16:07:22 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archivelog/archivelog/1_2_842803635.dbf
ORA-00280: change 3273739 for thread 1 is in sequence #2
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/grs/system01.dbf'
ORA-01112: media recovery not started
SQL> alter database open resetlogs;
Database altered.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------
1 1 1 52428800 1 NO CURRENT 3273740 21-MAR-14
2 1 0 52428800 1 YES UNUSED 0
3 1 0 52428800 1 YES UNUSED 0
[oracle@localhost grs]$ tail -f -n 20 /u01/app/oracle/admin/grs/bdump/alert_grs.log
select * from xx;----更新的丢失了
System parameters with non-default values:
processes = 150
__shared_pool_size = 62914560
__large_pool_size = 4194304
__java_pool_size = 4194304
__streams_pool_size = 4194304
sga_target = 285212672
control_files = /u01/app/oracle/oradata/grs/control01.ctl, /u01/app/oracle/oradata/grs/control02.ctl, /u01/app/oracle/oradata/grs/control03.ctl
db_block_size = 8192
__db_cache_size = 205520896
compatible = 10.2.0.1.0
log_archive_dest_1 = location=/u01/app/oracle/archivelog/archivelog/
db_file_multiblock_read_count= 16
db_recovery_file_dest = /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size= 2147483648
_allow_resetlogs_corruption= TRUE
undo_management = AUTO
undo_tablespace = UNDOTBS1
remote_login_passwordfile= EXCLUSIVE
db_domain =
dispatchers = (PROTOCOL=TCP) (SERVICE=grsXDB)
job_queue_processes = 10
background_dump_dest = /u01/app/oracle/admin/grs/bdump
user_dump_dest = /u01/app/oracle/admin/grs/udump
core_dump_dest = /u01/app/oracle/admin/grs/cdump
audit_file_dest = /u01/app/oracle/admin/grs/adump
db_name = grs
open_cursors = 300
pga_aggregate_target = 94371840
进行full expdp,然后重新创建db,在impdp(一些配置需要修改,比如归档,rman等)
SQL> alter database archivelog;
Database altered.
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog/archivelog/';
SQL> alter database open;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog/archivelog/
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6
SQL> show parameter user_dump_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string /u01/app/oracle/admin/grs/udum
p
SQL>
[oracle@localhost ~]$ export LC_ALL=en_US
[oracle@localhost ~]$ dbca
[oracle@localhost ~]$ netca
Oracle Net Services Configuration:
Oracle Net Services configuration terminated by user. The exit code is -1
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 24 15:46:01 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> create directory expdp_file_dir as '/u02/oracleexp';
Directory created.
SQL> alter user scott account unlock;
User altered.
SQL> alter user scott identified by "987064";
User altered.
SQL> grant dba to scott;
Grant succeeded.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@localhost ~]$ impdp scott/987064 directory=expdp_file_dir dumpfile=all_expdp_20140324.DMP nologfile=Y full=y parallel=4;
Import: Release 10.2.0.1.0 - Production on Monday, 24 March, 2014 15:57:38
Copyright (c) 2003, 2005, Oracle. All rights reserved.
UDI-00008: operation generated ORACLE error 1034
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
UDI-00003: all allowable logon attempts failed
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 24 15:58:05 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
http://192.168.2.185:1158/em/console/
</collection>[oracle@localhost test_xml]$ emctl status dbconsole
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://localhost.localdomain:1158/em/console/aboutApplication
Oracle Enterprise Manager 10g is running.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/10.2.0/db_1/localhost.localdomain_grs/sysman/log
9 归档模式,无备份,丢失一个数据文件
1 系统恢复
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 25 10:58:18 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 113247824 bytes
Database Buffers 167772160 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> CREATE TABLESPACE data_test DATAFILE
'/u01/app/oracle/oradata/grs/data_test.dbf'SIZE 10M AUTOEXTEND ON NEXT 10M MAXSIZE 20M 2 ;
Tablespace created.
SQL> create table data_test(a number) TABLESPACE data_test;
Table created.
SQL> insert into data_test
2 select rownum from dual connect by rownum<=10;
10 rows created.
SQL> select * from data_test;
A
----------
1
2
3
4
5
6
7
8
9
10
10 rows selected.
SQL> commit;
Commit complete.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !rm '/u01/app/oracle/oradata/grs/data_test.dbf';
[oracle@localhost grs]$ rm data_test.dbf----二者一样
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 104859216 bytes
Database Buffers 176160768 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 10 - see DBWR trace file
ORA-01110: data file 10: '/u01/app/oracle/oradata/grs/data_test.dbf'
SQL> alter database create datafile '/u01/app/oracle/oradata/grs/data_test.dbf'as '/u01/app/oracle/oradata/grs/data_test.dbf';
-----------重建该文件,
Database altered.
SQL> recover datafile 10;---该数据文件从创建起的所有的redo文件还在,就可以修复
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> select * from data_test;
A
----------
1
2
3
4
5
6
7
8
9
10
10 rows selected.
2 利用rman来恢复
重复上述步骤到start
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 113247824 bytes
Database Buffers 167772160 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 10 - see DBWR trace file
ORA-01110: data file 10: '/u01/app/oracle/oradata/grs/data_test.dbf'
[oracle@localhost grs]$ rman target/
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Mar 25 15:22:36 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GRS (DBID=341090406, not open)
RMAN> restore datafile 10;
Starting restore at 25-MAR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
creating datafile fno=10 name=/u01/app/oracle/oradata/grs/data_test.dbf
restore not done; all files readonly, offline, or already restored
Finished restore at 25-MAR-14
RMAN> recover datafile 10;
Starting recover at 25-MAR-14
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 25-MAR-14
RMAN> alter database open;
database opened
RMAN> sql'select * from data_test';
sql statement: select * from data_test
也可以是,恢复表空间
run{
allocate channel c1 type disk;
restore tablespace users;
recover tablespace users;
sql 'alter database datafile 6 online';
release channel c1;
}
在丢失多个数据文件时:
当启动检查数据文件丢失报错时可以查看该视图看需要恢复的数据文件有哪些
select * from v$recover_file;
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
10 归档模式,有备份,丢失一个数据文件
RMAN> backup tablespace data_test format '/u01/oracle/backup/rman_back20140325_%U';
Starting backup at 25-MAR-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00010 name=/u01/app/oracle/oradata/grs/data_test.dbf
channel ORA_DISK_1: starting piece 1 at 25-MAR-14
channel ORA_DISK_1: finished piece 1 at 25-MAR-14
piece handle=/u01/oracle/backup/rman_back20140325_06p42qal_1_1 tag=TAG20140325T154005 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-MAR-14
Starting Control File and SPFILE Autobackup at 25-MAR-14
piece handle=/u01/oracle/backup/rman_backup_c-341090406-20140325-01 comment=NONE
Finished Control File and SPFILE Autobackup at 25-MAR-14
RMAN> exit;
Recovery Manager complete.
[oracle@localhost grs]$ rm data_test.dbf
SQL> insert into data_test
2 select rownum from dual connect by rownum<=10;
10 rows created.
SQL> select * from data_test;
A
----------
1
2
3
4
5
6
7
8
9
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法