本文共 28740 字,大约阅读时间需要 95 分钟。
[20180222]11g删除表空间的恢复.txt
--//以前曾经做过利用传输表空间恢复数据库,连接如下:
--//在rman下执行如下:
RMAN> transport tablespace tea tablespace destination '/home/oracle/aux' auxiliary destination '/home/oracle/aux' until scn 13276962316;--//利用建立auxiliary实例,生成特定scn号的scn数据文件(这里只能恢复表空间文件).然后impdp导入回去.
--//为了规避同名问题,建立新的用户,使用参数REMAP_TABLESPACE,REMAP_SCHEMA.SCOTT@book> grant dba to ttt IDENTIFIED BY ttt;
Grant succeeded.$ cp /home/oracle/aux1/dmpfile.dmp /u01/app/oracle/admin/book/dpdump/
$ impdp system/oracle dumpfile=dmpfile.dmp transport_datafiles=/home/oracle/aux1/tea01.dbf REMAP_TABLESPACE=TEA:MILK
REMAP_SCHEMA=scott:ttt logfile=impdp.log--//今天补充测试删除表空间的情况:
1.环境:
SCOTT@book> @ &r/ver1 PORT_STRING VERSION BANNER ------------------------------ -------------- -------------------------------------------------------------------------------- x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionCREATE TABLESPACE TEA DATAFILE
'/mnt/ramdisk/book/tea01.dbf' SIZE 40M AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT MANUAL FLASHBACK ON;SCOTT@book> create table t tablespace tea as select * from all_objects;
Table created.SCOTT@book> alter system archive log current ;
System altered.--//使用rman做一个全备.
RMAN> backup database format '/home/oracle/backup/full_20180222_%U.bak'; Starting backup at 2018-02-22 14:50:00 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=171 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=184 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=197 device type=DISK channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00002 name=/mnt/ramdisk/book/sysaux01.dbf input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf channel ORA_DISK_1: starting piece 1 at 2018-02-22 14:50:02 channel ORA_DISK_2: starting full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set input datafile file number=00001 name=/mnt/ramdisk/book/system01.dbf input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf channel ORA_DISK_2: starting piece 1 at 2018-02-22 14:50:02 channel ORA_DISK_3: starting full datafile backup set channel ORA_DISK_3: specifying datafile(s) in backup set input datafile file number=00003 name=/mnt/ramdisk/book/undotbs01.dbf input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf channel ORA_DISK_3: starting piece 1 at 2018-02-22 14:50:02 channel ORA_DISK_3: finished piece 1 at 2018-02-22 14:50:03 piece handle=/home/oracle/backup/full_20180222_fjsrsgkq_1_1.bak tag=TAG20180222T145001 comment=NONE channel ORA_DISK_3: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: finished piece 1 at 2018-02-22 14:50:09 piece handle=/home/oracle/backup/full_20180222_fhsrsgkq_1_1.bak tag=TAG20180222T145001 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 channel ORA_DISK_2: finished piece 1 at 2018-02-22 14:50:09 piece handle=/home/oracle/backup/full_20180222_fisrsgkq_1_1.bak tag=TAG20180222T145001 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:07 Finished backup at 2018-02-22 14:50:09Starting Control File and SPFILE Autobackup at 2018-02-22 14:50:09
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2018_02_22/o1_mf_s_968770209_f8wt1196_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 2018-02-22 14:50:102.测试环境建立:
SCOTT@book> select count(*) from t ;
COUNT(*) ---------- 84772SCOTT@book> set numw 12
SCOTT@book> select current_scn,sysdate from v$database ; CURRENT_SCN SYSDATE ------------ ------------------- 13278546048 2018-02-22 14:51:13--//假设做了一次误操作.
SCOTT@book> set numw 12 SCOTT@book> select current_scn,sysdate from v$database ; CURRENT_SCN SYSDATE ------------ ------------------- 13278546048 2018-02-22 14:51:13SCOTT@book> delete from t where owner='SYSTEM';
569 rows deleted.SCOTT@book> commit ;
Commit complete.SCOTT@book> alter system archive log current ;
System altered.SCOTT@book> select count(*) from t ;
COUNT(*) ------------ 84203SCOTT@book> select current_scn,sysdate from v$database ;
CURRENT_SCN SYSDATE ------------ ------------------- 13278546093 2018-02-22 14:51:44SCOTT@book> drop tablespace tea including contents and datafiles;
Tablespace dropped. 2.恢复表空间看看: $ mkdir /homne/oracle/auxRMAN> recover datafile 6 until scn 13278546048 auxiliary destination '/home/oracle/aux';
Starting recover at 2018-02-22 14:55:30
allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=144 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=158 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=171 device type=DISK RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 02/22/2018 14:55:31 RMAN-05020: cannot specify AUXILIARY DESTINATION option for normal recovery --//不能这样恢复单个数据文件.--//recover tablespace tea until scn 13278546048 auxiliary destination '/home/oracle/aux';
RMAN> recover tablespace tea until scn 13278546048 auxiliary destination '/home/oracle/aux';
Starting recover at 2018-02-22 14:56:03
using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=144 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=158 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=171 device type=DISK RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-timeList of tablespaces expected to have UNDO segments
Tablespace SYSTEM Tablespace UNDOTBS1Creating automatic instance, with SID='uimx'
initialization parameters used for automatic instance:
db_name=BOOK db_unique_name=uimx_tspitr_BOOK compatible=11.2.0.4.0 db_block_size=8192 db_files=200 sga_target=1G processes=80 db_create_file_dest=/home/oracle/aux log_archive_dest_1='location=/home/oracle/aux' #No auxiliary parameter file usedstarting up automatic instance BOOK
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 285213576 bytes Database Buffers 771751936 bytes Redo Buffers 9711616 bytes Automatic instance createdList of tablespaces that have been dropped from the target database: Tablespace tea
contents of Memory Script:
{ # set requested point in time set until scn 13278546048; # restore the controlfile restore clone controlfile; # mount the controlfile sql clone 'alter database mount clone database'; # archive current online log sql 'alter system archive log current'; # avoid unnecessary autobackups for structural changes during TSPITR sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;'; } executing Memory Scriptexecuting command: SET until clause
Starting restore at 2018-02-22 14:56:08
allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=127 device type=DISK allocated channel: ORA_AUX_DISK_2 channel ORA_AUX_DISK_2: SID=133 device type=DISK allocated channel: ORA_AUX_DISK_3 channel ORA_AUX_DISK_3: SID=139 device type=DISKchannel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/BOOK/autobackup/2018_02_22/o1_mf_s_968770209_f8wt1196_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2018_02_22/o1_mf_s_968770209_f8wt1196_.bkp tag=TAG20180222T145009 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/home/oracle/aux/BOOK/controlfile/o1_mf_f8wtd9dp_.ctl Finished restore at 2018-02-22 14:56:10sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
contents of Memory Script:
{ # set requested point in time set until scn 13278546048; # set destinations for recovery set and auxiliary set datafiles set newname for clone datafile 1 to new; set newname for clone datafile 3 to new; set newname for clone datafile 2 to new; set newname for clone tempfile 1 to new; set newname for datafile 6 to "/mnt/ramdisk/book/tea01.dbf"; # switch all tempfiles switch clone tempfile all; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 1, 3, 2, 6; switch clone datafile all; } executing Memory Scriptexecuting command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /home/oracle/aux/BOOK/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 2018-02-22 14:56:14
using channel ORA_AUX_DISK_1 using channel ORA_AUX_DISK_2 using channel ORA_AUX_DISK_3channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00006 to /mnt/ramdisk/book/tea01.dbf channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/backup/full_20180222_fjsrsgkq_1_1.bak channel ORA_AUX_DISK_2: starting datafile backup set restore channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_2: restoring datafile 00001 to /home/oracle/aux/BOOK/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_2: reading from backup piece /home/oracle/backup/full_20180222_fisrsgkq_1_1.bak channel ORA_AUX_DISK_3: starting datafile backup set restore channel ORA_AUX_DISK_3: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_3: restoring datafile 00002 to /home/oracle/aux/BOOK/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_3: reading from backup piece /home/oracle/backup/full_20180222_fhsrsgkq_1_1.bak channel ORA_AUX_DISK_1: piece handle=/home/oracle/backup/full_20180222_fjsrsgkq_1_1.bak tag=TAG20180222T145001 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15 channel ORA_AUX_DISK_2: piece handle=/home/oracle/backup/full_20180222_fisrsgkq_1_1.bak tag=TAG20180222T145001 channel ORA_AUX_DISK_2: restored backup piece 1 channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:15 channel ORA_AUX_DISK_3: piece handle=/home/oracle/backup/full_20180222_fhsrsgkq_1_1.bak tag=TAG20180222T145001 channel ORA_AUX_DISK_3: restored backup piece 1 channel ORA_AUX_DISK_3: restore complete, elapsed time: 00:00:15 Finished restore at 2018-02-22 14:56:30datafile 1 switched to datafile copy
input datafile copy RECID=19 STAMP=968770590 file name=/home/oracle/aux/BOOK/datafile/o1_mf_system_f8wtdh8d_.dbf datafile 3 switched to datafile copy input datafile copy RECID=20 STAMP=968770590 file name=/home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_f8wtdh85_.dbf datafile 2 switched to datafile copy input datafile copy RECID=21 STAMP=968770590 file name=/home/oracle/aux/BOOK/datafile/o1_mf_sysaux_f8wtdh8n_.dbfcontents of Memory Script:
{ # set requested point in time set until scn 13278546048; # online the datafiles restored or switched sql clone "alter database datafile 1 online"; sql clone "alter database datafile 3 online"; sql clone "alter database datafile 2 online"; sql clone "alter database datafile 6 online"; # recover and open resetlogs recover clone database tablespace "TEA", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog; alter clone database open resetlogs; } executing Memory Scriptexecuting command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 2 online
sql statement: alter database datafile 6 online
Starting recover at 2018-02-22 14:56:30
using channel ORA_AUX_DISK_1 using channel ORA_AUX_DISK_2 using channel ORA_AUX_DISK_3starting media recovery
archived log for thread 1 with sequence 919 is already on disk as file /u01/app/oracle/archivelog/book/1_919_896605872.dbf
archived log file name=/u01/app/oracle/archivelog/book/1_919_896605872.dbf thread=1 sequence=919 media recovery complete, elapsed time: 00:00:01 Finished recover at 2018-02-22 14:56:32database opened
contents of Memory Script:
{ # make read only the tablespace that will be exported sql clone 'alter tablespace TEA read only'; # create directory for datapump import sql "create or replace directory TSPITR_DIROBJ_DPDIR as '' /home/oracle/aux''"; # create directory for datapump export sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as '' /home/oracle/aux''"; } executing Memory Scriptsql statement: alter tablespace TEA read only
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/aux''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/aux''
Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_uimx": EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK EXPDP> Master table "SYS"."TSPITR_EXP_uimx" successfully loaded/unloaded EXPDP> ****************************************************************************** EXPDP> Dump file set for SYS.TSPITR_EXP_uimx is: EXPDP> /home/oracle/aux/tspitr_uimx_97690.dmp EXPDP> ****************************************************************************** EXPDP> Datafiles required for transportable tablespace TEA: EXPDP> /mnt/ramdisk/book/tea01.dbf EXPDP> Job "SYS"."TSPITR_EXP_uimx" successfully completed at Thu Feb 22 14:57:09 2018 elapsed 0 00:00:31 Export completedcontents of Memory Script: { # shutdown clone before import shutdown clone immediate } executing Memory Script
database closed
database dismounted Oracle instance shut downPerforming import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_uimx" successfully loaded/unloaded IMPDP> Starting "SYS"."TSPITR_IMP_uimx": IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK IMPDP> Job "SYS"."TSPITR_IMP_uimx" successfully completed at Thu Feb 22 14:57:22 2018 elapsed 0 00:00:02 Import completedcontents of Memory Script: { # make read write and offline the imported tablespaces sql 'alter tablespace TEA read write'; sql 'alter tablespace TEA offline'; # enable autobackups after TSPITR is finished sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;'; } executing Memory Script
sql statement: alter tablespace TEA read write
sql statement: alter tablespace TEA offline
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;Removing automatic instance
Automatic instance removed auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_temp_f8wtf0q4_.tmp deleted auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_3_f8wtf0gq_.log deleted auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_2_f8wtf0bt_.log deleted auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_1_f8wtf03w_.log deleted auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_sysaux_f8wtdh8n_.dbf deleted auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_f8wtdh85_.dbf deleted auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_system_f8wtdh8d_.dbf deleted auxiliary instance file /home/oracle/aux/BOOK/controlfile/o1_mf_f8wtd9dp_.ctl deleted Finished recover at 2018-02-22 14:57:24--//恢复完成后,表空间状态是offline;
RMAN> report schema ;
Report of database schema for database with db_unique_name BOOK List of Permanent Datafiles =========================== File Size(MB) Tablespace RB segs Datafile Name ---- -------- -------------------- ------- ------------------------ 1 770 SYSTEM *** /mnt/ramdisk/book/system01.dbf 2 940 SYSAUX *** /mnt/ramdisk/book/sysaux01.dbf 3 865 UNDOTBS1 *** /mnt/ramdisk/book/undotbs01.dbf 4 300 USERS *** /mnt/ramdisk/book/users01.dbf 5 346 EXAMPLE *** /mnt/ramdisk/book/example01.dbf 6 0 TEA *** /mnt/ramdisk/book/tea01.dbf --//恢复到原来的位置.List of Temporary Files
======================= File Size(MB) Tablespace Maxsize(MB) Tempfile Name ---- -------- -------------------- ----------- -------------------- 1 35 TEMP 32767 /mnt/ramdisk/book/temp01.dbfSCOTT@book> SELECT file#, CHECKPOINT_CHANGE#,CHECKPOINT_TIME,UNRECOVERABLE_CHANGE#,UNRECOVERABLE_TIME,LAST_CHANGE#,LAST_TIME, OFFLINE_CHANGE#, ONLINE_CHANGE#,FIRST_NONLOGGED_SCN,FIRST_NONLOGGED_TIME,status,name FROM v$datafile; FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME UNRECOVERABLE_CHANGE# UNRECOVERABLE_TIME LAST_CHANGE# LAST_TIME OFFLINE_CHANGE# ONLINE_CHANGE# FIRST_NONLOGGED_SCN FIRST_NONLOGGED_TIM STATUS NAME ----- ------------------ ------------------- --------------------- ------------------- ------------ ------------------- --------------- -------------- ------------------- ------------------- ------- -------------------------------------------------- 1 13278546508 2018-02-22 14:56:14 0 925701 925702 0 SYSTEM /mnt/ramdisk/book/system01.dbf 2 13278546508 2018-02-22 14:56:14 0 925701 925702 0 ONLINE /mnt/ramdisk/book/sysaux01.dbf 3 13278546508 2018-02-22 14:56:14 0 925701 925702 0 ONLINE /mnt/ramdisk/book/undotbs01.dbf 4 13278546508 2018-02-22 14:56:14 0 925701 925702 0 ONLINE /mnt/ramdisk/book/users01.dbf 5 13278546508 2018-02-22 14:56:14 13274819965 2017-01-16 22:00:05 952916 952921 0 ONLINE /mnt/ramdisk/book/example01.dbf 6 13278547300 2018-02-22 14:57:24 0 13278547300 2018-02-22 14:57:24 13278547276 13278547281 0 OFFLINE /mnt/ramdisk/book/tea01.dbf 6 rows selected. --//注:恢复scn= 13278546048;
SCOTT@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE# , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME CREATION_CHANGE# RESETLOGS_CHANGE# STATUS CHECKPOINT_COUNT FUZ NAME TABLESPACE_NAME ----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------------------------- ------------------------------ 1 13278546508 2018-02-22 14:56:14 7 925702 ONLINE 1203 YES /mnt/ramdisk/book/system01.dbf SYSTEM 2 13278546508 2018-02-22 14:56:14 1834 925702 ONLINE 1192 YES /mnt/ramdisk/book/sysaux01.dbf SYSAUX 3 13278546508 2018-02-22 14:56:14 923328 925702 ONLINE 1113 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1 4 13278546508 2018-02-22 14:56:14 16143 925702 ONLINE 1207 YES /mnt/ramdisk/book/users01.dbf USERS 5 13278546508 2018-02-22 14:56:14 952916 925702 ONLINE 1109 YES /mnt/ramdisk/book/example01.dbf EXAMPLE 6 0 0 0 OFFLINE 0 6 rows selected.SCOTT@book> alter tablespace tea read only ; alter tablespace tea read only * ERROR at line 1: ORA-01539: tablespace 'TEA' is not online
$ cat e.txt alter tablespace tea online; alter tablespace tea read only ;
SCOTT@book> @ /home/oracle/hrp430/testb/e.txt
Tablespace altered. Tablespace altered.SCOTT@book> SELECT file#, CHECKPOINT_CHANGE#,CHECKPOINT_TIME,UNRECOVERABLE_CHANGE#,UNRECOVERABLE_TIME,LAST_CHANGE#,LAST_TIME, OFFLINE_CHANGE#, ONLINE_CHANGE#,FIRST_NONLOGGED_SCN,FIRST_NONLOGGED_TIME,status,name FROM v$datafile;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME UNRECOVERABLE_CHANGE# UNRECOVERABLE_TIME LAST_CHANGE# LAST_TIME OFFLINE_CHANGE# ONLINE_CHANGE# FIRST_NONLOGGED_SCN FIRST_NONLOGGED_TIM STATUS NAME ----- ------------------ ------------------- --------------------- ------------------- ------------ ------------------- --------------- -------------- ------------------- ------------------- ------- -------------------------------------------------- 1 13278546508 2018-02-22 14:56:14 0 925701 925702 0 SYSTEM /mnt/ramdisk/book/system01.dbf 2 13278546508 2018-02-22 14:56:14 0 925701 925702 0 ONLINE /mnt/ramdisk/book/sysaux01.dbf 3 13278546508 2018-02-22 14:56:14 0 925701 925702 0 ONLINE /mnt/ramdisk/book/undotbs01.dbf 4 13278546508 2018-02-22 14:56:14 0 925701 925702 0 ONLINE /mnt/ramdisk/book/users01.dbf 5 13278546508 2018-02-22 14:56:14 13274819965 2017-01-16 22:00:05 952916 952921 0 ONLINE /mnt/ramdisk/book/example01.dbf 6 13278547861 2018-02-22 15:03:55 0 13278547861 2018-02-22 15:03:55 13278547300 13278547838 0 ONLINE /mnt/ramdisk/book/tea01.dbf6 rows selected.
SCOTT@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE# , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME CREATION_CHANGE# RESETLOGS_CHANGE# STATUS CHECKPOINT_COUNT FUZ NAME TABLESPACE_NAME ----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------------------------- ------------------------------ 1 13278546508 2018-02-22 14:56:14 7 925702 ONLINE 1203 YES /mnt/ramdisk/book/system01.dbf SYSTEM 2 13278546508 2018-02-22 14:56:14 1834 925702 ONLINE 1192 YES /mnt/ramdisk/book/sysaux01.dbf SYSAUX 3 13278546508 2018-02-22 14:56:14 923328 925702 ONLINE 1113 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1 4 13278546508 2018-02-22 14:56:14 16143 925702 ONLINE 1207 YES /mnt/ramdisk/book/users01.dbf USERS 5 13278546508 2018-02-22 14:56:14 952916 925702 ONLINE 1109 YES /mnt/ramdisk/book/example01.dbf EXAMPLE 6 13278547861 2018-02-22 15:03:55 13278547276 925702 ONLINE 6 NO /mnt/ramdisk/book/tea01.dbf TEA 6 rows selected.--//注:恢复scn= 13278546048;
SCOTT@book> select count(*) from t ;
COUNT(*) ------------ 84772--//恢复到删除前的记录数,对比前面的结果.可以这样恢复的简单,完全把复杂的rman命令封装起来,是否实用不是很清楚.
--//假设不小心误操作,你会选择drop 表空间,然后在恢复吗? 不过对于误删除表空间倒是不错的选择.3.继续恢复:
SCOTT@book> drop tablespace tea including contents and datafiles; Tablespace dropped.RMAN> recover tablespace tea until scn 13278546093 auxiliary destination '/home/oracle/aux';
.... --//不再贴出SCOTT@book> @ /home/oracle/hrp430/testb/e.txt
Tablespace altered. Tablespace altered.SCOTT@book> select count(*) from t ;
COUNT(*) ------------ 84203--//恢复到delete之后的情况.另外注意一个问题就是这样恢复后,因为使用传输表空间dg不会自动建立数据文件6,必须手动传输过去.切记!!
4.恢复备库:
--//在备库执行报错. SYS@bookdg> select count(*) from scott.t; select count(*) from scott.t * ERROR at line 1: ORA-00942: table or view does not exist$ scp /mnt/ramdisk/book/tea01.dbf oracle@192.168.100.40:/mnt/ramdisk/book/
tea01.dbf 100% 40MB 40.0MB/s 00:01SYS@bookdg> alter database recover managed standby database using current logfile disconnect ;
Database altered.SYS@bookdg> select count(*) from scott.t;
select count(*) from scott.t * ERROR at line 1: ORA-01187: cannot read from file because it failed verification tests ORA-01110: data file 6: '/mnt/ramdisk/book/tea01.dbf'--//备库报错....重新启动看看.
ALTER DATABASE OPEN Read of datafile '/mnt/ramdisk/book/tea01.dbf' (fno 6) header failed with ORA-19735 Rereading datafile 6 header failed with ORA-19735 Beginning Standby Crash Recovery. Serial Media Recovery started Managed Standby Recovery starting Real Time Apply Media Recovery Log /u01/app/oracle/archivelog/book/1_921_896605872.dbf Standby Crash Recovery aborted due to error 1203. Errors in file /u01/app/oracle/diag/rdbms/bookdg/bookdg/trace/bookdg_ora_2664.trc: ORA-01203: wrong incarnation of this file - wrong creation SCN ORA-01110: data file 6: '/mnt/ramdisk/book/tea01.dbf' Recovery interrupted! Recovered data files to a consistent state at change 13278547278 Completed Standby Crash Recovery.$ oerr ora 19735
19735, 00000, "wrong creation SCN - control file expects initial plugged-in datafile" // *Cause: When a tablespace is plugged into a database, the tablespace is // initially read-only. Oracle converts the header of the // plugged-in datafiles (assign them a new creation SCN) when // the tablespace is first made read-write. This error occurs // when the creation SCN in the file header is different from the // creation SCN in the control file, possibly because this is the // converted datafile. // *Action: Either restore the initial version of the plugged-in datafile, or // continue database recovery, which will recover the control file.--//估计问题我做了2次recover的缘故.
--//在主库执行如下:SYS@book> alter database create standby controlfile as '/tmp/aa.ctl3';
Database altered.--//备库:
SYS@bookdg> shutdown immediate ; ORA-01109: database not open Database dismounted. ORACLE instance shut down.$ scp /tmp/aa.ctl3 oracle@192.168.100.40:/mnt/ramdisk/book/control01.ctl
aa.ctl3 100% 10MB 10.2MB/s 00:00 [oracle@gxqyydg4 IP=100.78 ~ 17]$ scp /tmp/aa.ctl3 oracle@192.168.100.40:/mnt/ramdisk/book/control02.ctl aa.ctl3 100% 10MB 10.2MB/s 00:00SYS@bookdg> alter database recover managed standby database using current logfile disconnect ;
Database altered.SYS@bookdg> select count(*) from scott.t;
COUNT(*) ------------ 84203--//OK..
5.继续:
SCOTT@book> set numw 12--//我前面执行删除后,执行如下,忘记记录删除表空间后的scn号:
SCOTT@book> select current_scn,sysdate from v$database ; CURRENT_SCN SYSDATE ------------ ------------------- 13278546093 2018-02-22 14:51:44SCOTT@book> select timestamp_to_scn('2018-02-22 14:53:00') from dual ;
TIMESTAMP_TO_SCN('2018-02-2214:53:00') -------------------------------------- 13278546213--//看看恢复scn=13278546213会如何,也就是选择drop 表空间后的情况:
SCOTT@book> drop tablespace tea including contents and datafiles;
Tablespace dropped.RMAN> recover tablespace tea until scn 13278546213 auxiliary destination '/home/oracle/aux';
.... sql statement: alter tablespace TEA online Removing automatic instance shutting down automatic instance database closed database dismounted Oracle instance shut down Automatic instance removed auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_temp_f8wwyjtf_.tmp deleted auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_3_f8wwyjlj_.log deleted auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_2_f8wwyjgk_.log deleted auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_1_f8wwyj70_.log deleted auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_sysaux_f8wwxz4x_.dbf deleted auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_f8wwxz4k_.dbf deleted auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_system_f8wwxz4r_.dbf deleted auxiliary instance file /home/oracle/aux/BOOK/controlfile/o1_mf_f8wwxs7o_.ctl deleted RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 02/22/2018 15:40:09 RMAN-03015: error occurred in stored script Memory Script RMAN-03009: failure of sql command on clone_default channel at 02/22/2018 15:40:02 RMAN-11003: failure during parse/execution of SQL statement: alter tablespace TEA online ORA-00959: tablespace 'TEA' does not exist--//报错.不过通过logminer还是可以确定准确的drop 表空间的scn号的.
6.logminer看看是否可以准确确定删除表空的scn号.
/* Formatted on 2018/2/22 15:43:11 (QP5 v5.252.13127.32867) */
BEGIN DBMS_LOGMNR.START_LOGMNR ( STARTTIME => '2018-02-22 14:51:13' ,ENDTIME => '2018-02-22 14:54:00' ,OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + DBMS_LOGMNR.CONTINUOUS_MINE + DBMS_LOGMNR.COMMITTED_DATA_ONLY ); END; /set linesize 200
set numw 12 column sql_redo format a100 select scn,start_scn,commit_scn ,timestamp,sql_redo from V$LOGMNR_CONTENTS where sql_redo like 'drop%'SCN START_SCN COMMIT_SCN TIMESTAMP SQL_REDO ------------ ------------ ------------ --------------------- ------------------------------------------------------- 13278546120 13278546119 13278546130 2018-02-22 14:52:06 drop table "SCOTT"."T" cascade constraints purge; 13278546149 2018-02-22 14:52:06 drop tablespace tea including contents and datafiles; 2 rows selected.
--//可以确定删除表示时间是2018-02-22 14:52:06.执行过程大概是先drop表,然后才是表空间.
SCOTT@book> select timestamp_to_scn('2018-02-22 14:52:06') from dual ;
TIMESTAMP_TO_SCN('2018-02-2214:52:06') -------------------------------------- 13278546116--//选择恢复到scn=13278546119,应该没有问题.
--//我测试恢复到scn=13278546120 ok!! --//我测试恢复到scn=13278546131 报错!!RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 02/22/2018 15:57:40 RMAN-05506: error during recursive execution--//另外恢复时控制文件备份一定要有删除表空间定义.
转载地址:http://eqeoa.baihongyu.com/