11g Release 2 enhanced Tablespace Point In Time Recovery

11g release 2中引入了针对被dropped掉的表空间的表空间时间点恢复,这是一种十分有用的新特性。TSPITR(TablesSpace Point In Time Recovery)在10g中就能做到自动创建辅助实例以恢复表空间到某个时间点,但在10g中是无法恢复一个已经被drop掉的表空间的。如同10g中一样11g仍旧可以利用全自动的TSPITR恢复被drop的表空间;Oracle会自动创建并启动辅助实例,且仅仅还原那些恢复所需的控制文件,system,sysaux,undo表空间及目标表空间,这些工作都将在用户指定的辅助目的地’Auxiliary Destination’中完成;之后Oracle将进一步使用辅助实例recover目标表空间到指定的时间点,并将其中的数据以Data Pump传输表空间的形式倒回到原数据库当中。
接下来我们要具体测试这一新特性,我们会创建一个示例表空间并在该表空间上产生少量数据,之后我们将对数据库进行备份,drop目标示例表空间,并在RMAN中使用TSPITR的方式将已经被drop掉的表空间恢复回来。在正式drop表空间前我们当然需要留意时间点或者当时的scn号,以保证正常恢复,同时在测试时使用recovery catalog恢复目录,虽然我们同样可以不用。

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /s01/arch
Oldest online log sequence     7
Next log sequence to archive   9
Current log sequence           9

SQL> create tablespace maclean datafile '/s01/maclean.dbf' size 50M;
Tablespace created.

SQL> drop table visa;

Table dropped.

SQL> create user maclean identified by maclean;

User created.

SQL> grant dba to maclean;

Grant succeeded.

SQL> conn maclean/maclean;
Connected.

SQL> create table visa tablespace maclean as select * from sh.costs;
Table created.

[maclean@rh3 s01]$ rman target / catalog rman/rman@OCM

[maclean@rh3 s01]$ rman target / catalog rman/rman@OCM

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 28 06:00:25 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: G11R2 (DBID=2679584393)
connected to recovery catalog database

RMAN> backup database;

Starting backup at 28-OCT-10
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=140 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=00001 name=/s01/oradata/G11R2/system01.dbf
input datafile file number=00002 name=/s01/oradata/G11R2/sysaux01.dbf
input datafile file number=00005 name=/s01/oradata/G11R2/example01.dbf
input datafile file number=00006 name=/s01/maclean.dbf
input datafile file number=00003 name=/s01/oradata/G11R2/undotbs01.dbf
input datafile file number=00004 name=/s01/oradata/G11R2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 28-OCT-10
channel ORA_DISK_1: finished piece 1 at 28-OCT-10
piece handle=/s01/flash_recovery_area/G11R2/backupset/2010_10_28/o1_mf_nnndf_TAG20101028T060034_6dk88434_.bkp tag=TAG20101028T060034 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 28-OCT-10

Starting Control File and SPFILE Autobackup at 28-OCT-10
piece handle=/s01/flash_recovery_area/G11R2/autobackup/2010_10_28/o1_mf_s_733557681_6dk89l5v_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 28-OCT-10

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     994231

SQL> drop tablespace maclean including contents and datafiles;

Tablespace dropped.

RMAN> recover tablespace maclean until scn 994231 auxiliary destination '/s01/backup';

Starting recover at 28-OCT-10
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=145 device type=DISK

Creating automatic instance, with SID='kwrt'

initialization parameters used for automatic instance:
db_name=G11R2
db_unique_name=kwrt_tspitr_G11R2
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/s01/backup
log_archive_dest_1='location=/s01/backup'
#No auxiliary parameter file used

starting up automatic instance G11R2

Oracle instance started

Total System Global Area     292278272 bytes

Fixed Size                     2212736 bytes
Variable Size                100666496 bytes
Database Buffers             184549376 bytes
Redo Buffers                   4849664 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  scn 994231;
# 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;';
# resync catalog
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 28-OCT-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=59 device type=DISK

channel 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 /s01/flash_recovery_area/G11R2/autobackup/2010_10_28/o1_mf_s_733557681_6dk89l5v_.bkp
channel ORA_AUX_DISK_1: piece handle=/s01/flash_recovery_area/G11R2/autobackup/2010_10_28/o1_mf_s_733557681_6dk89l5v_.bkp tag=TAG20101028T060121
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/s01/backup/G11R2/controlfile/o1_mf_6dk8g3o4_.ctl
Finished restore at 28-OCT-10

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# set requested point in time
set until  scn 994231;
# 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
 "/s01/maclean.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 Script

executing 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 /s01/backup/G11R2/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 28-OCT-10
using channel ORA_AUX_DISK_1

channel 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 00001 to /s01/backup/G11R2/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /s01/backup/G11R2/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /s01/backup/G11R2/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /s01/maclean.dbf
channel ORA_AUX_DISK_1: reading from backup piece /s01/flash_recovery_area/G11R2/backupset/2010_10_28/o1_mf_nnndf_TAG20101028T060034_6dk88434_.bkp
channel ORA_AUX_DISK_1: piece handle=/s01/flash_recovery_area/G11R2/backupset/2010_10_28/o1_mf_nnndf_TAG20101028T060034_6dk88434_.bkp tag=TAG20101028T060034
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 28-OCT-10

datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=733557882 file name=/s01/backup/G11R2/datafile/o1_mf_system_6dk8gf26_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=733557882 file name=/s01/backup/G11R2/datafile/o1_mf_undotbs1_6dk8gf4n_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=733557882 file name=/s01/backup/G11R2/datafile/o1_mf_sysaux_6dk8gf2w_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 994231;
# 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  "MACLEAN", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing 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 28-OCT-10
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 9 is already on disk as file /s01/arch/1_9_733554444.dbf
archived log file name=/s01/arch/1_9_733554444.dbf thread=1 sequence=9
media recovery complete, elapsed time: 00:00:01
Finished recover at 28-OCT-10

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace  MACLEAN read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/s01/backup''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/s01/backup''";
}
executing Memory Script

sql statement: alter tablespace  MACLEAN read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/s01/backup''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/s01/backup''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_kwrt":
   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_kwrt" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_kwrt is:
   EXPDP>   /s01/backup/tspitr_kwrt_79105.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace MACLEAN:
   EXPDP>   /s01/maclean.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_kwrt" successfully completed at 06:06:57
Export completed

contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_kwrt" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_kwrt":
   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_kwrt" successfully completed at 06:07:39
Import completed

contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace  MACLEAN read write';
sql 'alter tablespace  MACLEAN offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
# resync catalog
resync catalog;
}
executing Memory Script

sql statement: alter tablespace  MACLEAN read write

sql statement: alter tablespace  MACLEAN offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

starting full resync of recovery catalog
full resync complete

Removing automatic instance
Automatic instance removed
auxiliary instance file /s01/backup/G11R2/datafile/o1_mf_temp_6dk8j1ox_.tmp deleted
auxiliary instance file /s01/backup/G11R2/onlinelog/o1_mf_3_6dk8hzd7_.log deleted
auxiliary instance file /s01/backup/G11R2/onlinelog/o1_mf_2_6dk8hylj_.log deleted
auxiliary instance file /s01/backup/G11R2/onlinelog/o1_mf_1_6dk8hxpg_.log deleted
auxiliary instance file /s01/backup/G11R2/datafile/o1_mf_sysaux_6dk8gf2w_.dbf deleted
auxiliary instance file /s01/backup/G11R2/datafile/o1_mf_undotbs1_6dk8gf4n_.dbf deleted
auxiliary instance file /s01/backup/G11R2/datafile/o1_mf_system_6dk8gf26_.dbf deleted
auxiliary instance file /s01/backup/G11R2/controlfile/o1_mf_6dk8g3o4_.ctl deleted
Finished recover at 28-OCT-10

SQL> conn maclean/maclean;
Connected.

SQL> alter tablespace maclean online;

Tablespace altered.

SQL> select count(*) from visa;

  COUNT(*)
----------
     82112

/* 恢复完成,之前被drop掉的表空间maclean被恢复回来 */

需要注意的是不管是11g还是10g的TSPITR都需要遵循表空间自包含(self-contained)的原则,且表空间上不能存有sys用户的对象,否则将出现类似下列错误:

shutting down automatic instance
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/28/2010 05:35:34
RMAN-06136: ORACLE error from auxiliary database: ORA-01097: cannot shutdown while in a transaction - commit or rollback first
RMAN-06962: Error received during export of metadata
RMAN-06960:    EXPDP> ORA-39123: Data Pump transportable tablespace job aborted
ORA-39187: The transportable set is not self-contained, violation list is
ORA-39917: SYS owned object COSTS in tablespace MOS not allowed in pluggable setde

同时在恢复期间可能遇到”the filename for datafile %d is missing in the control file”的问题,一般是在drop表空间前没有对控制文件进行备份,导致RMAN选择还原出来的控制文件中没有该目标表空间相关数据文件的记录,恢复将被终止;当TSPITR中恢复一旦终止,Oracle将删除所有辅助实例使用的临时文件。


Posted

in

by

Tags:

Comments

2 responses to “11g Release 2 enhanced Tablespace Point In Time Recovery”

  1. an9 Avatar

    技术贴,纯路过。

  2. 有教无类 Avatar
    有教无类

    sga_target=280M 这些参数都是自动生成么?TSPITR前对系统空余资源有什么要求没。

Leave a Reply

Your email address will not be published. Required fields are marked *