这篇文章主要讲解了“ Oracle12 RMAN新特性Recover Table有什么作用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ Oracle12 RMAN新特性Recover Table有什么作用”吧!
在 Oracle 12c 之前,如果误删一张表,常规的方法是 Flashback 闪回或 TSPITR。而开启 flashback 会消耗磁盘空间,且如果被 purge 或者经过 DDL,将无法 flashback。如果需要恢复的表空间过大,TSPITR 会耗时非常久。12c 中提供了Table Recovery 的新特性,可以针对单表(或单个表分区)基于时间点进行恢复,该特性用以直接从 RMAN 备份中恢复表的方法,该特性有以下特点:
不影响数据库中的其他数据库对象
减少时间和磁盘空间的消耗,和早期的 TSPIRT 工作流程类似
从另一个磁盘路径恢复表空间
导出想要的表数据
导入到原数据库(可选)
recover table 可以将一个或多个表或表分区恢复到指定的时间点,而不会影响其余的数据库对象。可以使用以前创建的 RMAN 备份将表和表分区恢复到指定的时间点。
该表被恢复到一个辅助实例中,并且可以选择:
使用 REMAP 选项将恢复的表导入新表或分区
仅在恢复的表中创建 expdp dump 文件,以便在其他时间进行导入
先决条件
目标数据库必须处于 ARCHIVELOG 模式。
您必须拥有表或表分区的 RMAN 备份,因为它们存在于要恢复这些对象的时间点。
要恢复单个表分区,目标数据库的 COMPATIBLE 初始化参数必须设置为 11.1.0 或更高。
请确保 AUXILIARY DESTINATION 有足够的空间来恢复 system、sysaux、undo 以及恢复表所需的表空间。
请注意,表恢复后,辅助目标中的这些文件将自动删除
必须使用 AUXILIARY DESTINATION 子句和后面其中一个子句来指定恢复的时间点:UNTIL TIME、UNTIL SCN 或 UNTIL SEQUENCE。
使用限制
属于SYS模式的表和表分区无法恢复。
SYSTEM和SYSAUX表空间中的表和表分区无法恢复。
standby数据库上的表和表分区无法恢复。
命名为NOT NULL约束的表不能用REMAP选项恢复。
RMAN从备份中自动处理恢复表或者表分区时会执行如下步骤:
1.判断哪些备份包含需要恢复的表或表分区,然后根据指定的时间来进行恢复。
2.判断目标主机上是否有足够的空间来创建auxiliary instance,该实例用于处理表或分区的恢复。 如果需要的空间不足,那么RMAN 会报错并退出恢复操作。
3.创建auxiliary database,并根据指定的时间来恢复指定的表或表分区到auxiliary database中。 辅助数据库的数据文件位置可以在命令中指定。
4.创建包含恢复表或表分区的数据泵文件(expdp dump file)。 数据泵的名称和位置也可以在命令中指定。
5. (可选操作)将上一步生产的数据泵文件导入到目标实例中。当然也可以选择不导入,如果选择不导入就必须使用impdp 手工导入。
6. (可选操作)在目标数据库中rename 恢复表或表分区。
使用场景
RMAN 的表级和表分区级恢复在以下场景中非常适用:
(1) 需要将非常少量的表恢复至特定的时间点。在这种情况下,TSPITR 不是最有效的解决方案,因为它会将表空间中的所有对象恢复到指定的时间点。
(2) 需要恢复已被逻辑损坏或已被 drop 和 purge 的表。
(3) flashback 不可用,比如需要的 undo 数据被覆盖。
(4) DDL 操作修改表结构后丢失的数据。flashback table 不能跨越 DDL(例如truncate)来回滚表。
在这Recover table 过程演示
SQL> create table t_recover_test as select * from dba_objects;
Table created.
SQL> select count(*) from t_recover_test;
COUNT(*) ---------- 72652 |
备份
[oracle@localhost ~]$ rman target / Recovery Manager: Release 12.2.0.1.0 - Production on Thu Jun 28 21:06:17 2018 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. connected to target database: PCC (DBID=3164878903) RMAN> backup database format '/home/oracle/bak/db_%U';
Starting backup at 28-JUN-18 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=61 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=/home/oracle/oradata/pcc/system01.dbf input datafile file number=00003 name=/home/oracle/oradata/pcc/sysaux01.dbf input datafile file number=00004 name=/home/oracle/oradata/pcc/undotbs01.dbf input datafile file number=00005 name=/home/oracle/oradata/pcc/tbs_zyq01.dbf input datafile file number=00007 name=/home/oracle/oradata/pcc/users01.dbf channel ORA_DISK_1: starting piece 1 at 28-JUN-18 channel ORA_DISK_1: finished piece 1 at 28-JUN-18 piece handle=/home/oracle/bak/db_01t6k254_1_1 tag=TAG20180628T215236 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 28-JUN-18
Starting Control File and SPFILE Autobackup at 28-JUN-18 piece handle=/u01/app/oracle/product/12.2.0.1/dbs/c-3164878903-20180628-00 comment=NONE Finished Control File and SPFILE Autobackup at 28-JUN-18 |
恢复表
[oracle@localhost ~]$ rman target / Recovery Manager: Release 12.2.0.1.0 - Production on Fri Jun 29 00:52:29 2018 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. connected to target database: PCC (DBID=3164878903) RMAN> RECOVER TABLE zyq.t_recover_test until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh34:mi:ss')" AUXILIARY DESTINATION '/data01' REMAP TABLE zyq.t_recover_test:t_recover_test_map;
Starting recover at 29-JUN-18 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=66 device type=DISK RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments Tablespace SYSTEM Tablespace UNDOTBS1
Creating automatic instance, with SID='hCed' initialization parameters used for automatic instance: db_name=PCC db_unique_name=hCed_pitr_PCC compatible=12.2.0 db_block_size=8192 db_files=200 diagnostic_dest=/u01/app/oracle _system_trig_enabled=FALSE sga_target=732M processes=200 db_create_file_dest=/data01 log_archive_dest_1='location=/data01' #No auxiliary parameter file used starting up automatic instance PCC
Oracle instance started
Total System Global Area 767557632 bytes
Fixed Size 8625416 bytes Variable Size 213910264 bytes Database Buffers 541065216 bytes Redo Buffers 3956736 bytes Automatic instance created
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh34:mi:ss')"; # 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'; } executing Memory Script
executing command: SET until clause
Starting restore at 29-JUN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=35 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 /u01/app/oracle/product/12.2.0.1/dbs/c-3164878903-20180628-01 channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/12.2.0.1/dbs/c-3164878903-20180628-01 tag=TAG20180628T234914 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02 output file name=/data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl Finished restore at 29-JUN-18
sql statement: alter database mount clone database
sql statement: alter system archive log current
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh34:mi:ss')"; # set destinations for recovery set and auxiliary set datafiles set newname for clone datafile 1 to new; set newname for clone datafile 4 to new; set newname for clone datafile 3 to new; set newname for clone tempfile 1 to new; # switch all tempfiles switch clone tempfile all; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 1, 4, 3;
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
renamed tempfile 1 to /data01/PCC/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 29-JUN-18 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 /data01/PCC/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00004 to /data01/PCC/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /data01/PCC/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/bak/db_01t6k254_1_1 channel ORA_AUX_DISK_1: piece handle=/home/oracle/bak/db_01t6k254_1_1 tag=TAG20180628T215236 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15 Finished restore at 29-JUN-18
datafile 1 switched to datafile copy input datafile copy RECID=4 STAMP=980038406 file name=/data01/PCC/datafile/o1_mf_system_fmcsc755_.dbf datafile 4 switched to datafile copy input datafile copy RECID=5 STAMP=980038406 file name=/data01/PCC/datafile/o1_mf_undotbs1_fmcsc75h_.dbf datafile 3 switched to datafile copy input datafile copy RECID=6 STAMP=980038406 file name=/data01/PCC/datafile/o1_mf_sysaux_fmcsc75c_.dbf
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh34:mi:ss')"; # online the datafiles restored or switched sql clone "alter database datafile 1 online"; sql clone "alter database datafile 4 online"; sql clone "alter database datafile 3 online"; # recover and open database read only recover clone database tablespace "SYSTEM", "UNDOTBS1", "SYSAUX"; sql clone 'alter database open read only'; } executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 4 online
sql statement: alter database datafile 3 online
Starting recover at 29-JUN-18 using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch2_3_979872889.dbf archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch2_4_979872889.dbf archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch2_3_979872889.dbf thread=1 sequence=3 archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch2_4_979872889.dbf thread=1 sequence=4 media recovery complete, elapsed time: 00:00:11 Finished recover at 29-JUN-18
sql statement: alter database open read only
contents of Memory Script: { sql clone "create spfile from memory"; shutdown clone immediate; startup clone nomount; sql clone "alter system set control_files = ''/data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl'' comment= ''RMAN set'' scope=spfile"; shutdown clone immediate; startup clone nomount; # mount database sql clone 'alter database mount clone database'; } executing Memory Script
sql statement: create spfile from memory
database closed database dismounted Oracle instance shut down
connected to auxiliary database (not started) Oracle instance started
Total System Global Area 767557632 bytes
Fixed Size 8625416 bytes Variable Size 213910264 bytes Database Buffers 541065216 bytes Redo Buffers 3956736 bytes
sql statement: alter system set control_files = ''/data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started) Oracle instance started
Total System Global Area 767557632 bytes
Fixed Size 8625416 bytes Variable Size 213910264 bytes Database Buffers 541065216 bytes Redo Buffers 3956736 bytes
sql statement: alter database mount clone database
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh34:mi:ss')"; # set destinations for recovery set and auxiliary set datafiles set newname for datafile 5 to new; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 5;
switch clone datafile all; } executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 29-JUN-18 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=34 device type=DISK
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 00005 to /data01/HCED_PITR_PCC/datafile/o1_mf_tbs_zyq_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/bak/db_01t6k254_1_1 channel ORA_AUX_DISK_1: piece handle=/home/oracle/bak/db_01t6k254_1_1 tag=TAG20180628T215236 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03 Finished restore at 29-JUN-18
datafile 5 switched to datafile copy input datafile copy RECID=8 STAMP=980038478 file name=/data01/HCED_PITR_PCC/datafile/o1_mf_tbs_zyq_fmcsfttn_.dbf
contents of Memory Script: { # set requested point in time set until time "to_date('2018-06-28 23:56:06','yyyy-mm-dd hh34:mi:ss')"; # online the datafiles restored or switched sql clone "alter database datafile 5 online"; # recover and open resetlogs recover clone database tablespace "TBS_ZYQ", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog; alter clone database open resetlogs; } executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 5 online
Starting recover at 29-JUN-18 using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch2_3_979872889.dbf archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/product/12.2.0.1/dbs/arch2_4_979872889.dbf archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch2_3_979872889.dbf thread=1 sequence=3 archived log file name=/u01/app/oracle/product/12.2.0.1/dbs/arch2_4_979872889.dbf thread=1 sequence=4 media recovery complete, elapsed time: 00:00:01 Finished recover at 29-JUN-18
database opened
contents of Memory Script: { # create directory for datapump import sql "create or replace directory TSPITR_DIROBJ_DPDIR as '' /data01''"; # create directory for datapump export sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as '' /data01''"; } executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/data01''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/data01''
Performing export of tables... EXPDP> Starting "SYS"."TSPITR_EXP_hCed_Dhxe": EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE EXPDP> . . exported "ZYQ"."T_RECOVER_TEST" 9.324 MB 72652 rows EXPDP> Master table "SYS"."TSPITR_EXP_hCed_Dhxe" successfully loaded/unloaded EXPDP> ****************************************************************************** EXPDP> Dump file set for SYS.TSPITR_EXP_hCed_Dhxe is: EXPDP> /data01/tspitr_hCed_71393.dmp EXPDP> Job "SYS"."TSPITR_EXP_hCed_Dhxe" successfully completed at Fri Jun 29 00:55:41 2018 elapsed 0 00:00:35 Export completed
contents of Memory Script: { # shutdown clone before import shutdown clone abort } executing Memory Script
Oracle instance shut down
Performing import of tables... IMPDP> Master table "SYS"."TSPITR_IMP_hCed_Arhm" successfully loaded/unloaded IMPDP> Starting "SYS"."TSPITR_IMP_hCed_Arhm": IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA IMPDP> . . imported "ZYQ"."T_RECOVER_TEST_MAP" 9.324 MB 72652 rows IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER IMPDP> Job "SYS"."TSPITR_IMP_hCed_Arhm" successfully completed at Fri Jun 29 00:56:43 2018 elapsed 0 00:00:45 Import completed
Removing automatic instance Automatic instance removed auxiliary instance file /data01/PCC/datafile/o1_mf_temp_fmcsd5ny_.tmp deleted auxiliary instance file /data01/HCED_PITR_PCC/onlinelog/o1_mf_3_fmcsg3y6_.log deleted auxiliary instance file /data01/HCED_PITR_PCC/onlinelog/o1_mf_2_fmcsg07o_.log deleted auxiliary instance file /data01/HCED_PITR_PCC/onlinelog/o1_mf_1_fmcsfzr1_.log deleted auxiliary instance file /data01/HCED_PITR_PCC/datafile/o1_mf_tbs_zyq_fmcsfttn_.dbf deleted auxiliary instance file /data01/PCC/datafile/o1_mf_sysaux_fmcsc75c_.dbf deleted auxiliary instance file /data01/PCC/datafile/o1_mf_undotbs1_fmcsc75h_.dbf deleted auxiliary instance file /data01/PCC/datafile/o1_mf_system_fmcsc755_.dbf deleted auxiliary instance file /data01/PCC/controlfile/o1_mf_fmcsc00p_.ctl deleted auxiliary instance file tspitr_hCed_71393.dmp deleted Finished recover at 29-JUN-18
RMAN> |
验证
SQL> select count(*) from T_RECOVER_TEST_MAP;
COUNT(*) ---------- 72652 |
感谢各位的阅读,以上就是“ Oracle12 RMAN新特性Recover Table有什么作用”的内容了,经过本文的学习后,相信大家对 Oracle12 RMAN新特性Recover Table有什么作用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。