设为首页 收藏本站
查看: 841|回复: 0

[经验分享] Oracle 读写-只读表空间回复详解

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-10-11 09:17:40 | 显示全部楼层 |阅读模式
(一) 使用备份时的控制文件进行恢复,如下图,即使用备份位置的控制文件进行恢复
Center.jpg
1) 创建测试表空间ts1及相关测试表(表空间为ts1
SYS@ORCL>create tablespace ts1 datafile '/u01/app/oracle/oradata/ORCL/ts1.dbf' size 10m;

Tablespace created.

SYS@ORCL>create table scott.t(x int) tablespace ts1;

Table created.

SYS@ORCL>insert into scott.t select rownum from dual connect by rownum<=10;

10 rows created.

SYS@ORCL>commit;

Commit complete.

SYS@ORCL>
2) 通过RMAN备份ts1表空间和控制文件
RMAN> backup tablespace ts1 include current controlfile;

Starting backup at 17-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=141 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/u01/app/oracle/oradata/ORCL/ts1.dbf
channel ORA_DISK_1: starting piece 1 at 17-JAN-13
channel ORA_DISK_1: finished piece 1 at 17-JAN-13
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_01_17/o1_mf_nnndf_TAG20130117T101646_8hgqrg9h_.bkp tag=TAG20130117T101646 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 17-JAN-13
channel ORA_DISK_1: finished piece 1 at 17-JAN-13
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_01_17/o1_mf_ncnnf_TAG20130117T101646_8hgqrhvd_.bkp tag=TAG20130117T101646 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 17-JAN-13

RMAN>
3) 删除t表部分记录
SYS@ORCL>delete scott.t where x>=6;

5 rows deleted.

SYS@ORCL>commit;

Commit complete.

SYS@ORCL>
4) 切换几次日志,让上面的动作归档(对于测试来说,意义不是特别的大)
SYS@ORCL>alter system switch logfile;

System altered.

SYS@ORCL>/

System altered.

SYS@ORCL>/

System altered.

SYS@ORCL>/

System altered.

SYS@ORCL>
5) 在users表空间上创建t1
SYS@ORCL>create table scott.t1(x int) tablespace users;

Table created.

SYS@ORCL>insert into scott.t1 select rownum from dual connect by rownum<=2;

2 rows created.

SYS@ORCL>commit;

Commit complete.

SYS@ORCL>
6) 将表ts1修改为只读模式
SYS@ORCL>alter tablespace ts1 read only;

Tablespace altered.

SYS@ORCL>select tablespace_name,status from dba_tablespaces where tablespace_name='TS1';

TABLESPACE_NAME              STATUS
------------------------- ---------
TS1                            READ ONLY

SYS@ORCL>select file_id,file_name,status,online_status from dba_data_files where tablespace_name='TS1';

    FILE_ID FILE_NAME                                            STATUS     ONLINE_
---------- --------------------------------------------- --------- -------
           6 /u01/app/oracle/oradata/ORCL/ts1.dbf            AVAILABLE ONLINE

SYS@ORCL>
7) 删除ts1表空间数据文件和所有控制文件
SYS@ORCL>!rm /u01/app/oracle/oradata/ORCL/ts1.dbf
SYS@ORCL>!rm /u01/app/oracle/oradata/ORCL/*.ctl
8) 重启数据库到nomount状态
SYS@ORCL>shutdown abort;
ORACLE instance shut down.
SYS@ORCL>
SYS@ORCL>startup nomount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              96470608 bytes
Database Buffers          184549376 bytes
Redo Buffers                2973696 bytes
SYS@ORCL>
9) 通过RMAN备份的控制文件完成控制文件的恢复,恢复完成,数据库修改为mount
RMAN> restore controlfile from '/u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_01_17/o1_mf_ncnnf_TAG20130117T101646_8hgqrhvd_.bkp';

Starting restore at 17-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:05
output filename=/u01/app/oracle/oradata/ORCL/control01.ctl
output filename=/u01/app/oracle/oradata/ORCL/control02.ctl
output filename=/u01/app/oracle/oradata/ORCL/control03.ctl
Finished restore at 17-JAN-13

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN>
10) 恢复ts1表空间
RMAN> restore tablespace ts1;

Starting restore at 17-JAN-13
Starting implicit crosscheck backup at 17-JAN-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
Crosschecked 2 objects
Finished implicit crosscheck backup at 17-JAN-13

Starting implicit crosscheck copy at 17-JAN-13
using channel ORA_DISK_1
Finished implicit crosscheck copy at 17-JAN-13

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_01_17/o1_mf_ncnnf_TAG20130117T101646_8hgqrhvd_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00006 to /u01/app/oracle/oradata/ORCL/ts1.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_01_17/o1_mf_nnndf_TAG20130117T101646_8hgqrg9h_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2013_01_17/o1_mf_nnndf_TAG20130117T101646_8hgqrg9h_.bkp tag=TAG20130117T101646
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 17-JAN-13

RMAN>
11) 表空间恢复完毕,尝试open数据库
--当然,我们知道一定是无法open数据库的,因为控制文件恢复的是老版本的
SYS@ORCL>!ls /u01/app/oracle/oradata/ORCL/ts1.dbf
/u01/app/oracle/oradata/ORCL/ts1.dbf

SYS@ORCL>alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

--提示resetlogs方式打开
SYS@ORCL>alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/ORCL/system01.dbf'

--提示需要恢复1号数据文件
SYS@ORCL>recover datafile 1;
ORA-00283: recovery session canceled due to errors
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

--提示using BACKUP CONTROLFILE方式完成恢复
SYS@ORCL>
12) using backup controlfile恢复数据库
注:如果要恢复到控制文件SCN以后的时间。这时候,就需要用using backup controlfile. 恢复就不会受“当前controlfile所纪录的SCN”的限制。
这时候的限制就来自于你的语句(until time , until scn),或者可用的archive log(until cancel)
SYS@ORCL>recover database using backup controlfile until cancel;
ORA-00279: change 493760 generated at 01/16/2013 17:10:46 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_01_16/o1_mf_1_7_%u_.arc
ORA-00280: change 493760 for thread 1 is in sequence #7


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
--此处回车则是利用下一个归档日志文件进行恢复。不过在这里也可以输入CANCEL,表示恢复到此结束,不再使用后面的归档日志文件
……
--在恢复的过程中又出现了如下警告
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/ORCL/system01.dbf'

SYS@ORCL>
13) 尝试再次resetlogs打开数据库
SYS@ORCL>alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/ORCL/system01.dbf'


SYS@ORCL>
14) 采用极端办法
注:此时只能采取极端手段:隐含参数_allow_resetlogs_corruption强制启动数据库,设置此参数之后,在数据库Open过程中,Oracle会跳过某些一致性检查,从而使数据库可能跳过不一致状态,Open打开:
--查看隐藏参数_allow_resetlogs_corruption,默认值为false
SYS@ORCL>SELECT ksppstvl, ksppdesc  
  2    FROM x$ksppi x, x$ksppcv y  
  3   WHERE x.indx = y.indx
  4    AND ksppinm = '_allow_resetlogs_corruption';  

KSPPSTVL   KSPPDESC
---------- --------------------------------------------------
FALSE      allow resetlogs even if it will cause corruption

SYS@ORCL>
--将隐藏参数设置为true
SYS@ORCL>alter system set "_allow_resetlogs_corruption"=true scope=spfile;

System altered.

SYS@ORCL>
--由于是静态参数,重启数据库使其生效
SYS@ORCL>shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SYS@ORCL>
--数据库启动到mount状态
SYS@ORCL>startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              83887696 bytes
Database Buffers          197132288 bytes
Redo Buffers                2973696 bytes
Database mounted.
SYS@ORCL>
15) 再次尝试open数据库,提示RESETLOGS方式open
SYS@ORCL>alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


SYS@ORCL>
16) 数据库成功以resetlogs方式open
SYS@ORCL>alter database open resetlogs;

Database altered.

SYS@ORCL>
SYS@ORCL>select count(*) from scott.t;

  COUNT(*)
----------
         5

SYS@ORCL>select count(*) from scott.t1;
select count(*) from scott.t1
                           *
ERROR at line 1:
ORA-00942: table or view does not exist


SYS@ORCL>
17) 恢复参数,重启数据库
SYS@ORCL>alter system set "_allow_resetlogs_corruption"=false scope=spfile;

System altered.

SYS@ORCL>startup force;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              88082000 bytes
Database Buffers          192937984 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
SYS@ORCL>
5.1.1. 小结如果在生产中使用了只读表空间,那么切记,在修改为只读以后,第一件事儿就是备份,这样会省去不必要的麻烦和损失。




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-25818-1-1.html 上篇帖子: ORA-00942: table or view does not exist 下篇帖子: ORA-38760: This database instance failed to turn on flashback database Oracle 空间
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表