这里是:一看就会,一做就废系列
数据库演示版本为 19.3 (12.2.0.3)
该系列涉及恢复过程中使用的 5 个语句:
1. recover database
2. recover database until cancel
3. recover database using backup controlfile
4. recover database until cancel using backup controlfile
5. recover database using backup controlfile until cancel
继续之前,你得知道什么叫还原 ?什么叫恢复 ?以及备份与恢复的基础 点我查看己亥清爽系列
恢复级别一共三个:recover database > recover tablespace > recover datafile 本系列目的是为了演示上面 5 条命令的区别与联系,所以不探讨恢复级别以及数据库状态对应所使用的恢复级别问题。最高级别 database 已经包含了 tablespace 和 datafile 两个级别。
版权声明:博客园 AskScuti 版权所有,未经允许,禁止转载!
目录
1. 概念解释
2. 情况说明
3. 实验过程
3.1 备份 CDB
3.2 PDB1 创建测试数据
3.3 删除 CDB 控制文件
3.4 还原 CDB 控制文件
3.5 恢复 CDB 控制文件
3.6 开启 CDB
1. 概念解释
首先你得知道,recover database 这个命令是用作对所有数据文件进行恢复的,而且是完全恢复。
有个细节注意下,这个命令分为两种,一种用在 SQL 命令行,一种用在 RMAN:
SQL > recover database 仅对所有数据文件进行完全恢复,前提是控制文件为当前最新状态,不可以是还原过来的老版本或是手工重建,否则 SQL 命令行执行将返回错误。
RMAN > recover database 对所有数据文件和控制文件进行完全恢复
本例中演示对控制文件的恢复将(数据文件、归档日志、联机日志完好无损的情况下)
2. 情况说明
当前系统中,数据文件、归档日志、联机日志都完好无损,删除 CDB 级别所有控制文件,并采用 RMAN 对控制文件进行单独还原,使用 recover database 进行完全恢复。
3. 实验过程
3.1 备份 CDB
略,参考上篇
3.2 PDB1 创建测试数据
查看 PDB1 当前表空间及对应数据文件
RMAN> report schema; Report of database schema for database with db_unique_name CDB1 List of Permanent Datafiles =========================== File Size(MB) Tablespace RB segs Datafile Name ---- -------- ----------- ------- --------------------------------------------- 9 280 SYSTEM NO /u01/app/oracle/oradata/CDB1/pdb1/system01.dbf 10 350 SYSAUX NO /u01/app/oracle/oradata/CDB1/pdb1/sysaux01.dbf 11 100 UNDOTBS1 NO /u01/app/oracle/oradata/CDB1/pdb1/undotbs01.dbf 12 5 USERS NO /u01/app/oracle/oradata/CDB1/pdb1/users01.dbf 13 5 HENRY NO /u01/app/oracle/oradata/CDB1/pdb1/henry01.dbf List of Temporary Files ======================= File Size(MB) Tablespace Maxsize(MB) Tempfile Name ---- -------- ----------- ----------- ------------------------------------------- 3 36 TEMP 32767 /u01/app/oracle/oradata/CDB1/pdb1/temp01.dbf
创建新的表空间 recover_rman
SQL> create tablespace recover_rman datafile '/u01/app/oracle/oradata/CDB1/pdb1/recover_rman01.dbf' size 5m; Tablespace created.
注意:新的表空间结构,没有在备份的数据文件和控制文件里面。
3.3 删除 CDB 控制文件
SQL> conn / as sysdba Connected. SQL> select name from v$controlfile; NAME -------------------------------------------------- /u01/app/oracle/oradata/CDB1/control01.ctl /u01/app/oracle/oradata/CDB1/control02.ctl SQL> !rm -rf /u01/app/oracle/oradata/CDB1/control*
重启 CDB ,报错
SQL> startup force; ORACLE instance started. Total System Global Area 1241510120 bytes Fixed Size 9134312 bytes Variable Size 889192448 bytes Database Buffers 335544320 bytes Redo Buffers 7639040 bytes ORA-00205: error in identifying control file, check alert log for more info
3.4 还原 CDB 控制文件
[oracle@henry ~]$ rman target / Recovery Manager: Release 19.0.0.0.0 - Production on Sat Jun 8 18:14:49 2019 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved. connected to target database: CDB1 (not mounted) RMAN> restore controlfile from '/u02/backup/c-983951798-20190608-02.CTL'; Starting restore at 08-JUN-19 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=390 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:03 output file name=/u01/app/oracle/oradata/CDB1/control01.ctl output file name=/u01/app/oracle/oradata/CDB1/control02.ctl Finished restore at 08-JUN-19
将数据库启动到 MOUNT
RMAN> alter database mount; released channel: ORA_DISK_1 Statement processed
这时查控制文件中记录的数据文件(v$datafile 动态性能视图数据来自控制文件)
SQL> set pagesize 50 SQL> select name from v$datafile; NAME -------------------------------------------------- /u01/app/oracle/oradata/CDB1/system01.dbf /u01/app/oracle/oradata/CDB1/sysaux01.dbf /u01/app/oracle/oradata/CDB1/undotbs01.dbf /u01/app/oracle/oradata/CDB1/pdbseed/system01.dbf /u01/app/oracle/oradata/CDB1/pdbseed/sysaux01.dbf /u01/app/oracle/oradata/CDB1/users01.dbf /u01/app/oracle/oradata/CDB1/pdbseed/undotbs01.dbf /u01/app/oracle/oradata/CDB1/pdb1/system01.dbf /u01/app/oracle/oradata/CDB1/pdb1/sysaux01.dbf /u01/app/oracle/oradata/CDB1/pdb1/undotbs01.dbf /u01/app/oracle/oradata/CDB1/pdb1/users01.dbf /u01/app/oracle/oradata/CDB1/pdb1/henry01.dbf
恢复出来的控制文件中,是没有记录表空间 recover_rman
3.5 恢复 CDB 控制文件
使用 recover database 恢复数据库
RMAN> recover database; Starting recover at 08-JUN-19 Starting implicit crosscheck backup at 08-JUN-19 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=134 device type=DISK Crosschecked 3 objects Finished implicit crosscheck backup at 08-JUN-19 Starting implicit crosscheck copy at 08-JUN-19 using channel ORA_DISK_1 Finished implicit crosscheck copy at 08-JUN-19 searching for all files in the recovery area cataloging files... no files cataloged using channel ORA_DISK_1 starting media recovery archived log for thread 1 with sequence 9 is already on disk as file /u01/app/oracle/oradata/CDB1/redo03.log archived log file name=/u01/app/oracle/oradata/CDB1/redo03.log thread=1 sequence=9 creating datafile file number=14 name=/u01/app/oracle/oradata/CDB1/pdb1/recover_rman01.dbf archived log file name=/u01/app/oracle/oradata/CDB1/redo03.log thread=1 sequence=9 media recovery complete, elapsed time: 00:00:01 Finished recover at 08-JUN-19
请注意倒数第 4 行:creating datafile file number=14 name=/u01/app/oracle/oradata/CDB1/pdb1/recover_rman01.dbf
完全恢复命令自动在控制文件中创建添加了 recover_rman 数据文件
再次查控制文件中记录的数据文件
SQL> select name from v$datafile; NAME ---------------------------------------------------- /u01/app/oracle/oradata/CDB1/system01.dbf /u01/app/oracle/oradata/CDB1/sysaux01.dbf /u01/app/oracle/oradata/CDB1/undotbs01.dbf /u01/app/oracle/oradata/CDB1/pdbseed/system01.dbf /u01/app/oracle/oradata/CDB1/pdbseed/sysaux01.dbf /u01/app/oracle/oradata/CDB1/users01.dbf /u01/app/oracle/oradata/CDB1/pdbseed/undotbs01.dbf /u01/app/oracle/oradata/CDB1/pdb1/system01.dbf /u01/app/oracle/oradata/CDB1/pdb1/sysaux01.dbf /u01/app/oracle/oradata/CDB1/pdb1/undotbs01.dbf /u01/app/oracle/oradata/CDB1/pdb1/users01.dbf /u01/app/oracle/oradata/CDB1/pdb1/henry01.dbf /u01/app/oracle/oradata/CDB1/pdb1/recover_rman01.dbf
3.6 开启 CDB
因为动了“控制文件”,所以,必须得以 resetlogs 方式打开,为啥?勿问,爱过!抚摸我查看官方文档
你想直接打开?too young, too simple, sometimes naive.- 来自于莎士比亚的蔑视。
SQL> alter database open; alter database open * ERROR at line 1: ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs; Database altered.
你的疑问在于:recover database 语句明明是个完全恢复的动作,为何成功之后,依然需要 resetlogs ?因为 recover database 命令只能修复控制文件中数据文件的物理结构信息,无法修改控制文件中的日志序列号,无法像数据文件一样,应用归档和联机日志前滚,所以控制文件中的序列号依然是老旧的,因此,只能通过重置序列号来打开数据库。
以 resetlogs 打开之后,日志组序列号重置为 1,新的版本化身 incarnation 出现
RMAN> list incarnation; using target database control file instead of recovery catalog List of Database Incarnations DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time ------- ------- -------- ---------- ------- ---------- ---------- 1 1 CDB1 983951798 PARENT 1 17-APR-19 2 2 CDB1 983951798 PARENT 1920977 06-JUN-19 3 3 CDB1 983951798 CURRENT 2455443 08-JUN-19
INCARNATION 是个啥?请参考: