模拟删除操作
创建测试表和测试表空间
SQL>create tablespace test1190 datafile “/u01/app/oracle/oradata/10gdb/test01.dbf” size 30M;
SQL> create table t1 tablespace test1190 as select * from dba_objects where rownum < 1001;
Table created.
SQL> select count(*) from t1;
COUNT(*)
----------
1000
SQL> commit;
Commit complete.
备份数据库
rman target /
backup database format='/home/oracle/dbfull_U%.bak';
查看当前日志
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 5 52428800 1 NO CURRENT 1758394 07-MAR-23
2 1 3 52428800 1 YES INACTIVE 1758389 07-MAR-23
3 1 4 52428800 1 YES INACTIVE 1758392 07-MAR-23
模拟删除操作
SQL> delete from test.t1 where rownum < 101;
100 rows deleted.
查看当前日志
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 5 52428800 1 NO CURRENT 1758394 07-MAR-23
2 1 3 52428800 1 YES INACTIVE 1758389 07-MAR-23
3 1 4 52428800 1 YES INACTIVE 1758392 07-MAR-23
模拟删除表空间
SQL> drop tablespace test1190 including contents and datafiles;
Tablespace dropped.
切归档看下当前的日志
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 5 52428800 1 NO CURRENT 1758394 07-MAR-23
2 1 3 52428800 1 YES INACTIVE 1758389 07-MAR-23
3 1 4 52428800 1 YES INACTIVE 1758392 07-MAR-23
SQL> alter system switch logfile;
System altered.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 5 52428800 1 YES ACTIVE 1758394 07-MAR-23
2 1 6 52428800 1 NO CURRENT 1758477 07-MAR-23
3 1 4 52428800 1 YES INACTIVE 1758392 07-MAR-23
恢复操作
创建恢复数据库
原数据库生成pfile
SQL> create pfile='/home/oracle/1.ora' from spfile;
File created.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
修改pfile
将里面所有关于原数据库的信息修改为新数据库实例名称
[oracle@10gdb ~]$ cat 1.ora
oradb.__db_cache_size=478150656
oradb.__java_pool_size=4194304
oradb.__large_pool_size=4194304
oradb.__shared_pool_size=268435456
oradb.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/oradb/adump'
*.background_dump_dest='/u01/app/oracle/admin/oradb/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/oradata/oradb/control01.ctl','/u01/app/oracle/oradata/oradb/control02.ctl','/u01/app/oracle/oradata/oradb/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/oradb/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='10gdb'
*.db_unique_name='oradb'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=10gdbXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/u01/app/oracle/arch1'
*.open_cursors=300
*.pga_aggregate_target=252706816
*.processes=1500
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=758120448
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/oradb/udump'
创建数据库所需目录
[oracle@10gdb ~]$ mkdir -p /u01/app/oracle/admin/oradb/adump
[oracle@10gdb ~]$ mkdir -p /u01/app/oracle/admin/oradb/bdump
[oracle@10gdb ~]$ mkdir -p /u01/app/oracle/admin/oradb/cdump
[oracle@10gdb ~]$ mkdir -p /u01/app/oracle/admin/oradb/udump
[oracle@10gdb ~]$ mkdir -p /u01/app/oracle/oradata/oradb
[oracle@10gdb ~]$ mkdir -p /u01/app/oracle/arch1
用原数据库备份进行数据恢复
1. 使用新pfile启动数据库
[oracle@10gdb ~]$ export ORACLE_SID=oradb
[oracle@10gdb ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Mar 7 09:38:37 2023
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount pfile='/home/oracle/1.ora';
Oracle instance started
Total System Global Area 759169024 bytes
Fixed Size 2023848 bytes
Variable Size 276827736 bytes
Database Buffers 478150656 bytes
Redo Buffers 2166784 bytes
2.恢复控制文件
RMAN> restore controlfile from '/home/oracle/dbfull_0a1mer3c_1_1.bak';
Starting restore at 07-MAR-23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1641 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u01/app/oracle/oradata/oradb/control01.ctl
output filename=/u01/app/oracle/oradata/oradb/control02.ctl
output filename=/u01/app/oracle/oradata/oradb/control03.ctl
Finished restore at 07-MAR-23
RMAN> startup mount
database is already started
database mounted
released channel: ORA_DISK_1
3.查看表空间备份集
RMAN> list backup of tablespace test1190
2> ;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 626.73M DISK 00:00:25 07-MAR-23
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20230307T092218
Piece Name: /home/oracle/dbfull_051mecua_1_1.bak
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 1758237 07-MAR-23 /u01/app/oracle/oradata/10gdb/test1190.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4 Full 626.85M DISK 00:00:25 07-MAR-23
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20230307T092440
Piece Name: /home/oracle/dbfull_071med2o_1_1.bak
List of Datafiles in backup set 4
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 1758308 07-MAR-23 /u01/app/oracle/oradata/10gdb/test1190.dbf
4.只对必须的表空间文件执行rename操作
RMAN> run {
allocate channel c1 type disk;
set newname for datafile '/u01/app/oracle/oradata/10gdb/system01.dbf' to '/u01/app/oracle/oradata/oradb/system01.dbf';
set newname for datafile '/u01/app/oracle/oradata/10gdb/undotbs01.dbf' to '/u01/app/oracle/oradata/oradb/undotbs01.dbf';
set newname for datafile '/u01/app/oracle/oradata/10gdb/test1190.dbf' to '/u01/app/oracle/oradata/oradb/test1190.dbf';
restore datafile 1,2,6;
switch datafile all;
release channel c1;
}2> 3> 4> 5> 6> 7> 8> 9>
released channel: ORA_DISK_1
allocated channel: c1
channel c1: sid=1641 devtype=DISK
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 07-MAR-23
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/oradb/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/oradb/undotbs01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/oradb/test1190.dbf
channel c1: reading from backup piece /home/oracle/dbfull_071med2o_1_1.bak
channel c1: restored backup piece 1
piece handle=/home/oracle/dbfull_071med2o_1_1.bak tag=TAG20230307T092440
channel c1: restore complete, elapsed time: 00:00:26
Finished restore at 07-MAR-23
datafile 1 switched to datafile copy
input datafile copy recid=4 stamp=1130839198 filename=/u01/app/oracle/oradata/oradb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=5 stamp=1130839198 filename=/u01/app/oracle/oradata/oradb/undotbs01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=6 stamp=1130839198 filename=/u01/app/oracle/oradata/oradb/test1190.dbf
released channel: c1
5.注册归档
RMAN> catalog start with '/u01/app/oracle/arch1';
searching for all files that match the pattern /u01/app/oracle/arch1
List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/arch1/1_1_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_3_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_4_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_5_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_2_1130749717.dbf
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/arch1/1_1_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_3_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_4_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_5_1130749717.dbf
File Name: /u01/app/oracle/arch1/1_2_1130749717.dbf
RMAN> exit
Recovery Manager complete.
6.查看注册日志记录
[oracle@10gdb ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 7 10:09:29 2023
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from v$instance;
INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
HOST_NAME
----------------------------------------------------------------
VERSION STARTUP_T STATUS PAR THREAD# ARCHIVE LOG_SWITCH_WAIT
----------------- --------- ------------ --- ---------- ------- ---------------
LOGINS SHU DATABASE_STATUS INSTANCE_ROLE ACTIVE_ST BLO
---------- --- ----------------- ------------------ --------- ---
1 oradb
10gdb
10.2.0.1.0 07-MAR-23 MOUNTED NO 1 STARTED
ALLOWED NO ACTIVE PRIMARY_INSTANCE NORMAL NO
set lines 200
col name for a67
select SEQUENCE#, FIRST_CHANGE#, NEXT_CHANGE#,name from v$archived_log where name like '/u01/app/oracle/arch1/%';
SEQUENCE# FIRST_CHANGE# NEXT_CHANGE# NAME
---------- ------------- ------------ -------------------------------------------------------------------
1 1719758 1758387 /u01/app/oracle/arch1/1_1_1130749717.dbf
3 1758389 1758392 /u01/app/oracle/arch1/1_3_1130749717.dbf
4 1758392 1758394 /u01/app/oracle/arch1/1_4_1130749717.dbf
5 1758394 1758477 /u01/app/oracle/arch1/1_5_1130749717.dbf
2 1758387 1758389 /u01/app/oracle/arch1/1_2_1130749717.dbf
7. 查看注册归档里面的记录
SQL> show user
USER is "SYS"
SQL> oradebug setmypid
Statement processed.
SQL> alter session set tracefile_identifier='1212';
Session altered.
SQL> oradebug tracefile_name
/u01/app/oracle/admin/oradb/udump/oradb_ora_2650_1212.trc
SQL> alter system dump logfile '/u01/app/oracle/arch1/1_5_1130749717.dbf' scn min 175800 scn max 1758477;
System altered.
SQL> oradebug close_trace
Statement processed.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
[oracle@10gdb ~]$ more /u01/app/oracle/admin/oradb/udump/oradb_ora_2650_1212.trc
/u01/app/oracle/admin/oradb/udump/oradb_ora_2650_1212.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1
System name: Linux
Node name: 10gdb
Release: 2.6.18-371.el5
Version: #1 SMP Tue Oct 1 08:35:08 EDT 2013
Machine: x86_64
Instance name: oradb
Redo thread mounted by this instance: 1
Oracle process number: 15
Unix process pid: 2650, image: oracle@10gdb (TNS V1-V3)
*** 2023-03-07 10:16:48.722
*** SERVICE NAME:() 2023-03-07 10:16:48.722
*** SESSION ID:(1641.12) 2023-03-07 10:16:48.722
DUMP OF REDO FROM FILE '/u01/app/oracle/arch1/1_5_1130749717.dbf'
Opcodes *.*
RBAs: 0x000000.00000000.0000 thru 0xffffffff.ffffffff.ffff
SCNs: scn: 0x0000.0002aeb8 (175800) thru scn: 0x0000.001ad50d (1758477)
Times: creation thru eternity
FILE HEADER:
Compatibility Vsn = 169869568=0xa200100
Db ID=2763628572=0xa4b9a01c, Db Name='10GDB'
Activation ID=2782780412=0xa5dddbfc
Control Seq=1369=0x559, File size=102400=0x19000
File Number=1, Blksiz=512, File Type=2 LOG
descrip:"Thread 0001, Seq# 0000000005, SCN 0x0000001ad4ba-0x0000001ad50d"
thread: 1 nab: 0x92 seq: 0x00000005 hws: 0x2 eot: 0 dis: 0
resetlogs count: 0x4365df15 scn: 0x0000.001a3dce (1719758)
resetlogs terminal rcv count: 0x0 scn: 0x0000.00000000
prev resetlogs count: 0x43624547 scn: 0x0000.0018c907 (1624327)
prev resetlogs terminal rcv count: 0x0 scn: 0x0000.00000000
Low scn: 0x0000.001ad4ba (1758394) 03/07/2023 09:28:35
Next scn: 0x0000.001ad50d (1758477) 03/07/2023 09:30:47
Enabled scn: 0x0000.001a3dce (1719758) 03/06/2023 09:08:37
Thread closed scn: 0x0000.001ad4ba (1758394) 03/07/2023 09:28:35
Disk cksum: 0x749e Calc cksum: 0x749e
Terminal recovery stop scn: 0x0000.00000000
Terminal recovery 01/01/1988 00:00:00
Most recent redo scn: 0x0000.00000000
Largest LWN: 60 blocks
End-of-redo stream : No
Unprotected mode
Miscellaneous flags: 0x11
Thread internal enable indicator: thr: 0, seq: 0 scn: 0x0000.00000000
REDO RECORD - Thread:1 RBA: 0x000005.00000002.0010 LEN: 0x1540 VLD: 0x0d
SCN: 0x0000.001ad4c4 SUBSCN: 1 03/07/2023 09:29:05
CHANGE #1 TYP:0 CLS: 1 AFN:6 DBA:0x01800014 OBJ:53626 SCN:0x0000.001ad44f SEQ: 1 OP:11.3
KTB Redo
op: 0x01 ver: 0x01
op: F xid: 0x0004.02a.00000242 uba: 0x008006ae.0233.30
KDO Op code: DRP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01800014 hdba: 0x01800013
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 0(0x0)
CHANGE #2 TYP:0 CLS:23 AFN:2 DBA:0x00800039 OBJ:4294967295 SCN:0x0000.001ad3e6 SEQ: 1 OP:5.2
ktudh redo: slt: 0x002a sqn: 0x00000242 flg: 0x0012 siz: 252 fbi: 0
uba: 0x008006ae.0233.30 pxid: 0x0000.000.00000000
CHANGE #3 TYP:0 CLS: 1 AFN:6 DBA:0x01800014 OBJ:53626 SCN:0x0000.001ad4c4 SEQ: 1 OP:11.3
KTB Redo
op: 0x02 ver: 0x01
op: C uba: 0x008006ae.0233.31
KDO Op code: DRP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x01800014 hdba: 0x01800013
itli: 2 ispac: 0 maxfr: 4858
tabn: 0 slot: 1(0x1)
CHANGE #4 TYP:0 CLS: 1 AFN:6 DBA:0x01800014 OBJ:53626 SCN:0x0000.001ad4c4 SEQ: 2 OP:11.3
KTB Redo
op: 0x02 ver: 0x01
op: C uba: 0x008006ae.0233.32
8. 查看opt11.3操作代码的记录数量
[oracle@10gdb ~]$ cat /u01/app/oracle/admin/oradb/udump/oradb_ora_2650_1212.trc|grep 'OP:11.3'|grep 'OBJ:53626'|wc -l
100
[oracle@10gdb ~]$
9.找到最开始的操作位置
CHANGE #2 TYP:2 CLS: 1 AFN:1 DBA:0x0040ec47 OBJ:8 SCN:0x0000.001af31d SEQ: 1 OP:11.3
KTB Redo
op: 0x11 ver: 0x01
op: F xid: 0x0002.01e.0000024a uba: 0x00800325.021d.09
Block cleanout record, scn: 0x0000.001af326 ver: 0x01 opt: 0x02, entries follow...
itli: 2 flg: 2 scn: 0x0000.001af31d
KDO Op code: DRP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x0040ec47 hdba: 0x00400049
itli: 2 ispac: 0 maxfr: 4863
tabn: 2 slot: 26(0x1a)
REDO RECORD - Thread:1 RBA: 0x000009.00000074.0168 LEN: 0x0088 VLD: 0x01
SCN: 0x0000.001af328 SUBSCN: 1 03/07/2023 13:26:17
CHANGE #1 TYP:0 CLS:19 AFN:2 DBA:0x00800019 OBJ:4294967295 SCN:0x0000.001af31f SEQ: 1 OP:5.4
ktucm redo: slt: 0x001e sqn: 0x0000024a srt: 0 sta: 9 flg: 0x2
ktucf redo: uba: 0x00800325.021d.09 ext: 3 spc: 6640 fbi: 0
CHANGE #2 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ: 0 OP:17.10
Tablespace 7. dropped
including datafiles: 1
10.rename logfile
alter database rename file '/u01/app/oracle/oradata/10gdb/redo01.log' to '/u01/app/oracle/oradata/oradb/redo01.log';
alter database rename file '/u01/app/oracle/oradata/10gdb/redo02.log' to '/u01/app/oracle/oradata/oradb/redo02.log';
alter database rename file '/u01/app/oracle/oradata/10gdb/redo03.log' to '/u01/app/oracle/oradata/oradb/redo03.log';
alter database rename file '/u01/app/oracle/oradata/10gdb/temp01.dbf' to '/u01/app/oracle/oradata/oradb/temp01.dbf';
11.scn值计算
从归档中dump的信息中找到你之前的drop tablespace操作,找到上一个scn值
CHANGE #2 TYP:2 CLS: 1 AFN:1 DBA:0x0040ec47 OBJ:8 SCN:0x0000.001af31d SEQ: 1 OP:11.3
KTB Redo
op: 0x11 ver: 0x01
op: F xid: 0x0002.01e.0000024a uba: 0x00800325.021d.09
Block cleanout record, scn: 0x0000.001af326 ver: 0x01 opt: 0x02, entries follow...
itli: 2 flg: 2 scn: 0x0000.001af31d
KDO Op code: DRP row dependencies Disabled
xtype: XA flags: 0x00000000 bdba: 0x0040ec47 hdba: 0x00400049
itli: 2 ispac: 0 maxfr: 4863
tabn: 2 slot: 26(0x1a)
REDO RECORD - Thread:1 RBA: 0x000009.00000074.0168 LEN: 0x0088 VLD: 0x01
SCN: 0x0000.001af328 SUBSCN: 1 03/07/2023 13:26:17
CHANGE #1 TYP:0 CLS:19 AFN:2 DBA:0x00800019 OBJ:4294967295 SCN:0x0000.001af31f SEQ: 1 OP:5.4
ktucm redo: slt: 0x001e sqn: 0x0000024a srt: 0 sta: 9 flg: 0x2
ktucf redo: uba: 0x00800325.021d.09 ext: 3 spc: 6640 fbi: 0
CHANGE #2 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ: 0 OP:17.10
Tablespace 7. dropped
including datafiles: 1
SQL> select to_number('001af31d','XXXXXXXXXX') from dual;
TO_NUMBER('001AF31D','XXXXXXXXXX')
----------------------------------
1766173
12.恢复目标表空间并跳过其他
RMAN> run {
set until scn 1766173;
sql 'alter database datafile 1,2,6 online';
recover database skip forever tablespace sysoradb,users,zentbs;
}2> 3> 4> 5>
executing command: SET until clause
sql statement: alter database datafile 1,2,6 online
Starting recover at 07-MAR-23
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1641 devtype=DISK
starting media recovery
archive log thread 1 sequence 6 is already on disk as file /u01/app/oracle/arch1/1_6_1130749717.dbf
archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/arch1/1_7_1130749717.dbf
archive log thread 1 sequence 8 is already on disk as file /u01/app/oracle/oradata/10gdb/redo01.log
archive log thread 1 sequence 9 is already on disk as file /u01/app/oracle/oradata/10gdb/redo02.log
archive log filename=/u01/app/oracle/arch1/1_6_1130749717.dbf thread=1 sequence=6
archive log filename=/u01/app/oracle/arch1/1_7_1130749717.dbf thread=1 sequence=7
archive log filename=/u01/app/oracle/oradata/10gdb/redo01.log thread=1 sequence=8
archive log filename=/u01/app/oracle/oradata/10gdb/redo02.log thread=1 sequence=9
media recovery complete, elapsed time: 00:00:02
Finished recover at 07-MAR-23
13.开启新的数据库并查看数据
RMAN> alter database open resetlogs;
database opened
[oracle@10gdb oradb]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 7 13:49:00 2023
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> select open_mode from v$database;
OPEN_MODE
----------
READ WRITE
SQL> select count(*) from test.t1;
COUNT(*)
----------
900
本文由 mdnice 多平台发布