Oracle数据库恢复之resetlogs
实验环境:RHEL 5.4 + Oracle 11.2.0.3
如果是一名合格的Oracle DBA,对resetlogs这种关键字都应该是极其敏感的,当确认需要这种操作时一定要三思而后行,如果自己不是特别确认,哪怕多花些时间申请去让高级DBA人员协助你一起确认,也不要擅自去尝试执行,避免误操作造成既定损失后追悔莫及。
1.哪些场景可以resetlogs
首先要明确resetlogs操作非常危险的,也只有在进行不完全恢复开库时会使用到。
SQL> alter database open resetlogs;
-> open the database and reset the online logs
官方的描述如下:
Incomplete recovery, also called database point-in-time recovery, results in a noncurrent version of the database. In this case, you do not apply all of the redo generated after the restored backup. Typically, you perform point-in-time database recovery to undo a user error when Flashback Database is not possible.
To perform incomplete recovery, you must restore all data files from backups created before the time to which you want to recover and then open the database with the RESETLOGS option when recovery completes. Resetting the logs creates a new stream of log sequence numbers starting with log sequence 1.
官方的描述其实很清晰,但是实际很多初级DBA小伙伴们在实际工作中遇到这样的场景时却总是有些困惑,甚至误操作引发灾难。
我这里以一个实验来具体说明常见场景:
需求:A机数据库PROD1,现需在B机不同目录下用A机的备份集恢复出来;
A机:
--A机当前current redolog的sequence是57:
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
1 1 55 52428800 512 1 YES INACTIVE 2051572 19-MAY-19 2060361 19-MAY-19
2 1 56 52428800 512 1 YES INACTIVE 2060361 19-MAY-19 2060436 19-MAY-19
3 1 57 52428800 512 1 NO CURRENT 2060436 19-MAY-19 2.8147E+14
--A机做了一次数据库备份:
RMAN> backup database include current controlfile plus archivelog delete all input;
Starting backup at 19-MAY-19
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=23 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=189 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=21 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=57 RECID=3 STAMP=1008670991
channel ORA_DISK_1: starting piece 1 at 19-MAY-19
channel ORA_DISK_1: finished piece 1 at 19-MAY-19
piece handle=/home/oracle/backup/0cu1u68l_1_1.bak tag=TAG20190519T102315 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_57_860888149.dbf RECID=3 STAMP=1008670991
Finished backup at 19-MAY-19
Starting backup at 19-MAY-19
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
channel ORA_DISK_1: starting piece 1 at 19-MAY-19
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_2: starting piece 1 at 19-MAY-19
channel ORA_DISK_3: starting compressed full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
channel ORA_DISK_3: starting piece 1 at 19-MAY-19
channel ORA_DISK_3: finished piece 1 at 19-MAY-19
piece handle=/home/oracle/backup/0fu1u68p_1_1.bak tag=TAG20190519T102319 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_3: starting compressed full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_3: starting piece 1 at 19-MAY-19
channel ORA_DISK_3: finished piece 1 at 19-MAY-19
piece handle=/home/oracle/backup/0gu1u69j_1_1.bak tag=TAG20190519T102319 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: finished piece 1 at 19-MAY-19
piece handle=/home/oracle/backup/0du1u68p_1_1.bak tag=TAG20190519T102319 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:03
channel ORA_DISK_2: finished piece 1 at 19-MAY-19
piece handle=/home/oracle/backup/0eu1u68p_1_1.bak tag=TAG20190519T102319 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:01:23
Finished backup at 19-MAY-19
Starting backup at 19-MAY-19
current log archived
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=58 RECID=4 STAMP=1008671084
channel ORA_DISK_1: starting piece 1 at 19-MAY-19
channel ORA_DISK_1: finished piece 1 at 19-MAY-19
piece handle=/home/oracle/backup/0hu1u6bg_1_1.bak tag=TAG20190519T102446 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_58_860888149.dbf RECID=4 STAMP=1008671084
Finished backup at 19-MAY-19
Starting Control File and SPFILE Autobackup at 19-MAY-19
piece handle=/home/oracle/backup/control/c-2082231315-20190519-01 comment=NONE
Finished Control File and SPFILE Autobackup at 19-MAY-19
RMAN>
--可以看到备份数据库的日志前后都自动归档了当前的redolog(57和58),所以备份完成后,当前日志sequence变为59.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------
1 1 58 52428800 512 1 YES INACTIVE 2060691 19-MAY-19 2060767 19-MAY-19
2 1 59 52428800 512 1 NO CURRENT 2060767 19-MAY-19 2.8147E+14
3 1 57 52428800 512 1 YES INACTIVE 2060436 19-MAY-19 2060691 19-MAY-19
此时把备份集传输到B机,比如/u03/backup目录下,期望恢复到/u03/oradata/PROD1目录下。如果最终只是根据这个备份集去恢复,那最多恢复完sequence 58就结束了,找不到sequence 59(因为59还是当前current的redolog)。Oracle认为这就是最基本的不完全恢复,需要resetlogs操作。
--指定恢复到/u03/oradata/
RMAN> run {
2> set newname for database to '/u03/oradata/PROD1/%U';
3> restore database;
4> }
--切换到上步恢复出来的copy复本:
RMAN> switch database to copy;
datafile 1 switched to datafile copy "/u03/oradata/PROD1/data_D-PROD1_TS-SYSTEM_FNO-1"
datafile 2 switched to datafile copy "/u03/oradata/PROD1/data_D-PROD1_TS-SYSAUX_FNO-2"
datafile 3 switched to datafile copy "/u03/oradata/PROD1/data_D-PROD1_TS-UNDOTBS1_FNO-3"
datafile 4 switched to datafile copy "/u03/oradata/PROD1/data_D-PROD1_TS-USERS_FNO-4"
datafile 5 switched to datafile copy "/u03/oradata/PROD1/data_D-PROD1_TS-EXAMPLE_FNO-5"
--尝试恢复数据库:
RMAN> recover database;
Starting recover at 19-MAY-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=102 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=9 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=112 device type=DISK
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=58
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/0hu1u6bg_1_1.bak
channel ORA_DISK_1: errors found reading piece handle=/home/oracle/backup/0hu1u6bg_1_1.bak
channel ORA_DISK_1: failover to piece handle=/u03/backup/0hu1u6bg_1_1.bak tag=TAG20190519T102446
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_58_860888149.dbf thread=1 sequence=58
unable to find archived log
archived log thread=1 sequence=59
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/19/2019 11:04:21
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 59 and starting SCN of 2060767
RMAN>
可以看到最后有报错信息,就是告诉你找不到sequence 59的日志,这是必然的,因为59还是A机current的redo日志。
2.resetlogs前必须确认路径正确
**2.1 先查看控制文件和数据文件头记录的scn是否一致**
SQL> select checkpoint_change# from v$datafile;
CHECKPOINT_CHANGE#
------------------
2060767
2060767
2060767
2060767
2060767
SQL> select checkpoint_change# from v$datafile_header;
CHECKPOINT_CHANGE#
------------------
2060767
2060767
2060767
2060767
2060767
2.2 此时如果尝试直接OPEN会报错
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
提示我们开库必须使用RESETLOGS或者NORESETLOGS选项。
2.3 重点来了,现在可以open resetlogs吗?
当然不行!记得一定要确认好路径!!
--查询发现临时文件以及redo日志的路径都不是我们所期望的:
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u03/oradata/PROD1/data_D-PROD1_TS-SYSTEM_FNO-1
/u03/oradata/PROD1/data_D-PROD1_TS-SYSAUX_FNO-2
/u03/oradata/PROD1/data_D-PROD1_TS-UNDOTBS1_FNO-3
/u03/oradata/PROD1/data_D-PROD1_TS-USERS_FNO-4
/u03/oradata/PROD1/data_D-PROD1_TS-EXAMPLE_FNO-5
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/PROD1/temp01.dbf
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/PROD1/redo03.log
/u01/app/oracle/oradata/PROD1/redo02.log
/u01/app/oracle/oradata/PROD1/redo01.log
--rename重命名为我们期望的目录:
SQL> alter database rename file '/u01/app/oracle/oradata/PROD1/temp01.dbf' to '/u03/oradata/PROD1/temp01.dbf';
Database altered.
SQL> alter database rename file '/u01/app/oracle/oradata/PROD1/redo01.log' to '/u03/oradata/PROD1/redo01.log';
Database altered.
SQL> alter database rename file '/u01/app/oracle/oradata/PROD1/redo02.log' to '/u03/oradata/PROD1/redo02.log';
Database altered.
SQL> alter database rename file '/u01/app/oracle/oradata/PROD1/redo03.log' to '/u03/oradata/PROD1/redo03.log';
Database altered.
--再次检查确认:
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u03/oradata/PROD1/temp01.dbf
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u03/oradata/PROD1/redo03.log
/u03/oradata/PROD1/redo02.log
/u03/oradata/PROD1/redo01.log
--最终尝试open开库:
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.
总结:很多初级人员有可能是对set newname for database这个有误解,以为这里的database包括了临时文件,redo日志文件,误以为自己已经把新库所有路径都指向到了期望位置。但实际并不是这样,这也说明了不确认的操作一定要在测试环境测试验证后才可以在生产环境操作。大家可以想象一下,如果是理解有误没确认日志路径直接执行了resetlogs,那么如果B机正好有别的库用到同名的这些路径,亦或是整个恢复操作就是直接在A机的本机其他目录临时基于某个时间点恢复出一套库,那将会是一场大的生产事故。
Oracle数据库恢复之resetlogs的更多相关文章
- Oracle 【IT实验室】数据库备份与恢复之:如何对Oracle数据库文件进行恢复与备份
任何数据库在长期使用过程中,都会存在一定的安全隐患.对于数据库管理员来说不能仅寄希望于计算机操作系统的安全运行,而是要建立一整套的数据库备份与恢复机制.当数据库发生故障后,希望能重新建立一个完整的数据 ...
- Oracle备份恢复之rman备份oracle数据库
备份需求和rman备份 oracle数据库的备份相关问答: 1)备份时数据库处于何种状态? 备份时数据库处于OPEN状态,这样数据库可以正常工作. 2)备份的数据备份在什么地方? 备份在本地磁盘. 3 ...
- RMAN数据库恢复之对数据库进行完全介质恢复
RMAN数据库恢复之对数据库进行完全介质恢复环境:控制文件和参数文件SPFILE及归档文件.重做日志文件都在.其它数据文件丢失.恢复方法:使用之前创建的全库备份进行恢复1.删除数据文件: SQL> ...
- [转帖]oracle备份恢复之recover database的四条语句区别
oracle备份恢复之recover database的四条语句区别 https://www.cnblogs.com/andy6/p/5925433.html 需要学习一下. 1 recover d ...
- Oracle数据库升级(10.2.0.4->11.2.0.4)
环境: RHEL5.4 + Oracle 10.2.0.4 目的: 在本机将数据库升级到11.2.0.4 之前总结的Oracle数据库异机升级:http://www.cnblogs.com/jyzha ...
- Oracle数据库基础知识
oracle数据库plsql developer 目录(?)[-] 一 SQL基础知识 创建删除数据库 创建删除修改表 添加修改删除列 oracle cascade用法 添加删除约束主键外 ...
- oracle数据库相关知识点
已知表如下:
- 【转】oracle数据库开发的一些经验积累
1.不安装Oracle客户连接Oracle 8的方法 请将以下文件拷贝到运行文件所在目录 一.ODBC动态库 : ctl3d32.dll msvcrt40.dll odbc16gt.dll odbc ...
- 服务器断电,Oracle数据库无法启动解决方案
数据库没有备份的情况下,数据库所在服务器由于意外断电,导致服务器启动之后,Oracle数据库startup报错. 1. 数据库没开归档模式 2. 无备份 解决方案: 1 2 3 4 5 6 7 8 9 ...
随机推荐
- viewport详解
本文主要讲解viewpor相关知识. 参考资料&内容来源 博客园:https://www.cnblogs.com/zaoa/p/8630393.html 博客园:http://www.cnbl ...
- Git you are not allowed to push code to protected branches on this project?
error: You are not allowed to push code to protected branches on this project....error: failed to pu ...
- 已知段地址,求CPU寻址范围
已知段地址为0001H,仅通过变化偏移地址寻址,则CPU的寻址范围是? 物理地址 = 段地址×16 + 偏移地址 所以物理地址的范围是[16×1H+0H, 16×1H+FFFFH] 也就是[10H×1 ...
- Kibana + ElasticSearch
上面一张介绍了ElasticSearch的安装和简单用法. 现在应该都知道ElasticSearch是用来做全文搜索的,那今天我就简单介绍下Kibana. 它是专门用来查看ElasticSearch内 ...
- 【题解】P4886快递员
[题解]P4886 快递员 淀粉质好题!!!加深了我对点分治的理解.最近分治学了好多啊. 题目大意 给定你一颗有边权的树,再给你\(m\)和点对,请你在树上选出来一个点,使得所有点对到这个点的距离的最 ...
- 我的Android进阶之旅------>Android中可替换string的使用,getString(int resId, Object... formatArgs)
官方文档如下描述: 地址:http://developer.android.com/reference/android/content/Context.html#getString%28int,%20 ...
- SSH Tunnel扫盲(ssh port forwarding端口转发)
SSH的的Port Forward,中文可以称为端口转发,是SSH的一项非常重要的功能.它可以建立一条安全的SSH通道,并把任意的TCP连接放到这条通道中.下面仔细就仔细讨论SSH的这种非常有用的功能 ...
- SQL语句性能优化操作
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在where及order by涉及的列上建立索引. 2.应尽量避免在where子句中对字段进行null值判断,创建表时NULL是默认值,但大多数时候应 ...
- Spring Boot2.0之 yml的使用
yml Spring Boot 默认读取 .yml .properties 结尾的 yml非常好的作用,比properties更节约 结构清晰 server: port: 8090 con ...
- 9.1 NOIP普及组试题精解(2)
9-4 soldier.c #include <stdio.h> #define MAXN 21 }; int n, m, x, y; //n,m为B点的行列坐标位置,x,y为马的坐标位置 ...