热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

OracleUndotablespace恢复(无备份)-mysql教程

OracleUndotablespace恢复系统环境:操作系统:RedHatEL55Oracle:Oracle11gR2Oracle9i后,采用了undotablespace管理undo数据,实现undo的自动管理,本案例演示了undo表空间被破坏后如何恢复;如果有备份,通过备份恢复非常容易,但在没有备份的

Oracle Undo tablespace恢复 系统环境: 操作系统:RedHat EL55 Oracle: Oracle 11gR2 Oracle 9i后,采用了undo tablespace管理undo数据,实现undo的自动管理,本案例演示了undo表空间被破坏后如何恢复;如果有备份,通过备份恢复非常容易,但在没有备份的

Oracle Undo tablespace恢复

系统环境:

操作系统:RedHat EL55

Oracle: Oracle 11gR2


Oracle 9i后,采用了undo tablespace管理undo数据,实现undo的自动管理,本案例演示了undo表空间被破坏后如何恢复;如果有备份,通过备份恢复非常容易,但在没有备份的情况下,就需要采用非常规手段来恢复了,呵呵。

1、案例应用环境

undo表空间undo segments:

14:34:44 SYS@ prod>select segment_name,segment_type,tablespace_name from dba_segments
14:35:03   2  where tablespace_name='UNDOTBS1';
SEGMENT_NAME         SEGMENT_TYPE       TABLESPACE_NAME
-------------------- ------------------ ------------------------------
_SYSSMU10_3550978943$ TYPE2 UNDO        UNDOTBS1
_SYSSMU9_1424341975$ TYPE2 UNDO         UNDOTBS1
_SYSSMU8_2012382730$ TYPE2 UNDO         UNDOTBS1
_SYSSMU7_3286610060$ TYPE2 UNDO         UNDOTBS1
_SYSSMU6_2443381498$ TYPE2 UNDO         UNDOTBS1
_SYSSMU5_1527469038$ TYPE2 UNDO         UNDOTBS1
_SYSSMU4_1152005954$ TYPE2 UNDO         UNDOTBS1
_SYSSMU3_2097677531$ TYPE2 UNDO         UNDOTBS1
_SYSSMU2_2232571081$ TYPE2 UNDO         UNDOTBS1
_SYSSMU1_3780397527$ TYPE2 UNDO         UNDOTBS1
10 rows selected.
Elapsed: 00:00:00.19

模拟应用环境:

14:43:16 SYS@ prod>select count(*) from scott.emp1;
  COUNT(*)
----------
         1
Elapsed: 00:00:00.06
14:43:54 SYS@ prod>insert into scott.emp1 select * from scott.emp;
14 rows created.
Elapsed: 00:00:00.08
14:44:04 SYS@ prod>commit;
Commit complete.
Elapsed: 00:00:00.03
14:44:06 SYS@ prod>select count(*) from scott.emp1;                    
  COUNT(*)
----------
        15
Elapsed: 00:00:00.01
14:44:20 SYS@ prod>insert into scott.emp1 select * from scott.emp where rownum <4;
3 rows created.
Elapsed: 00:00:00.03
14:44:40 SYS@ prod>select count(*) from scott.emp1;   
  COUNT(*)
----------
        18
Elapsed: 00:00:00.01

关库前,事务未提交!


开启新的会话,模拟断电,将数据库非正常关闭:


[oracle@rh6 dbs]$ sqlplus '/as sysdba'

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 26 14:46:11 2014

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

14:46:12 SYS@ prod>shutdown abort;

ORACLE instance shut down.


Undo tablesapce datafile被破坏:

[oracle@rh6 dbs]$ rm /u01/app/oracle/oradata/prod/undotbs01.dbf


2、Open database时数据库报错

[oracle@rh6 prod]$ sqlplus '/as sysdba'
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 26 14:47:26 2014
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.
14:47:26 SYS@ prod>startup
ORACLE instance started.
Total System Global Area  835104768 bytes
Fixed Size                  2217952 bytes
Variable Size             775948320 bytes
Database Buffers           54525952 bytes
Redo Buffers                2412544 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: '/u01/app/oracle/oradata/prod/undotbs01.dbf'

告警日志:

ALTER DATABASE OPEN
Errors in file /u01/app/oracle/diag/rdbms/prod/prod/trace/prod_dbw0_7481.trc:
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: '/u01/app/oracle/oradata/prod/undotbs01.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Errors in file /u01/app/oracle/diag/rdbms/prod/prod/trace/prod_ora_7503.trc:
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: '/u01/app/oracle/oradata/prod/undotbs01.dbf'
ORA-1157 signalled during: ALTER DATABASE OPEN...

14:47:37 SYS@ prod>show parameter undo
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS1
14:48:18 SYS@ prod>

3、在没有备份的情况下进行修复:


创建pfile:

14:48:18 SYS@ prod>create pfile from spfile;

File created.

Elapsed: 00:00:00.09

查看undo tablespace使用的undo segments:

[oracle@rh6 dbs]$ cd /u01/app/oracle/oradata/prod/

[oracle@rh6 prod]$ strings system01.dbf | grep _SYSSMU | cut -d $ -f 1 | sort -u

and substr(drs.segment_name,1,7) != '_SYSSMU'

D' and substr(drs.segment_name,1,7) != ''_SYSSMU'' ' );

_SYSSMU10_3550978943

_SYSSMU10_3904554333

_SYSSMU11_286947212

_SYSSMU12_3068564564

_SYSSMU13_2761193625

_SYSSMU1_3780397527

_SYSSMU14_2421411996

_SYSSMU15_1683924174

_SYSSMU16_2313212396

_SYSSMU17_2041439332

_SYSSMU1_783380902

_SYSSMU18_2800789714

_SYSSMU19_53723967

_SYSSMU20_3850939844

_SYSSMU2_2232571081

_SYSSMU2_3138176977

_SYSSMU3_1645411166

_SYSSMU3_2097677531

_SYSSMU4_1152005954

_SYSSMU4_870421980

_SYSSMU5_1527469038

_SYSSMU5_2525172762

_SYSSMU6_2443381498

_SYSSMU6_3753507049

_SYSSMU7_1260614213

_SYSSMU7_3286610060

_SYSSMU8_2012382730

_SYSSMU8_2806087761

_SYSSMU9_1424341975

_SYSSMU9_973944058

注意:通过system01.dbf查出了,正在使用的undo segment,以上按使用时间做了排序,注意只选择那些排在最前面的(相同回滚段);默认每个undo tablespace 会应用10个undo segments。

编辑pfile,添加Oracle隐含参数,跳过undo segments的检测:

[oracle@rh6 dbs]$ cat initprod.ora

*.undo_tablespace='SYSTEM'

*.undo_management='MANUAL'

*._corrupted_rollback_segments=(_SYSSMU10_3550978943$,_SYSSMU9_1424341975$,_SYSSMU8_2012382730$,_SYSSMU7_3286610060$,_SYSSMU6_2443381498$,_SYSSMU5_1527469038$,_SYSSMU4_1152005954$,_SYSSMU3_2097677531$,_SYSSMU2_2232571081$,_SYSSMU1_3780397527$)

*._allow_resetlogs_corruption=true


通过pfile启动instance:


14:56:33 SYS@ prod>startup force pfile=$ORACLE_HOME/dbs/initprod.ora

ORACLE instance started.

Total System Global Area 835104768 bytes

Fixed Size 2217952 bytes

Variable Size 775948320 bytes

Database Buffers 54525952 bytes

Redo Buffers 2412544 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 3 - see DBWR trace file

ORA-01110: data file 3: '/u01/app/oracle/oradata/prod/undotbs01.dbf'


14:56:52 SYS@ prod>alter database datafile 3 offline drop;

Database altered.


14:57:11 SYS@ prod>alter database open;

Database altered.

Elapsed: 00:00:05.25

14:57:23 SYS@ prod>


告警日志:

alter database open
Beginning crash recovery of 1 threads
Started redo scan
Completed redo scan
 read 157 KB redo, 43 data blocks need recovery
Started redo application at
 Thread 1: logseq 3, block 451
Recovery of Online Redo Log: Thread 1 Group 3 Seq 3 Reading mem 0
  Mem# 0: /dsk1/oradata/prod/redo03a.log
  Mem# 1: /dsk2/oradata/prod/redo03b.log
Completed redo application of 0.04MB
Completed crash recovery at
 Thread 1: logseq 3, block 766, scn 1878512
 43 data blocks read, 43 data blocks written, 157 redo k-bytes read
Thu Jun 26 14:57:19 2014
LGWR: STARTING ARCH PROCESSES
Thu Jun 26 14:57:19 2014
ARC0 started with pid=20, OS id=7638 
ARC0: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC0: STARTING ARCH PROCESSES
Thread 1 advanced to log sequence 4 (thread open)
Thu Jun 26 14:57:20 2014
ARC1 started with pid=21, OS id=7641 
Thread 1 opened at log sequence 4
  Current log# 1 seq# 4 mem# 0: /dsk1/oradata/prod/redo01a.log
  Current log# 1 seq# 4 mem# 1: /dsk2/oradata/prod/redo01b.log
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Thu Jun 26 14:57:20 2014
SMON: enabling cache recovery
Thu Jun 26 14:57:21 2014
ARC2 started with pid=22, OS id=7643 
ARC1: Archival started
ARC2: Archival started
Thu Jun 26 14:57:21 2014
ARC2: Becoming the 'no FAL' ARCH
ARC2: Becoming the 'no SRL' ARCH
ARC1: Becoming the heartbeat ARCH
ARC3 started with pid=23, OS id=7645 
Archived Log entry 31 added for thread 1 sequence 3 ID 0xfaf1e60 dest 2:
Thu Jun 26 14:57:21 2014
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Database Characterset is ZHS16GBK
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
ARC3: Archival started
ARC0: STARTING ARCH PROCESSES COMPLETE
Starting background process QMNC
Thu Jun 26 14:57:23 2014
QMNC started with pid=24, OS id=7647 
Completed: alter database open
Thu Jun 26 14:57:26 2014
Starting background process CJQ0
Thu Jun 26 14:57:26 2014
CJQ0 started with pid=27, OS id=7661

4、创建新的undo tablespace

14:59:27 SYS@ prod>show parameter undo
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      MANUAL
undo_retention                       integer     900
undo_tablespace                      string      SYSTEM
14:59:34 SYS@ prod>create undo tablespace undotbs2
14:59:53   2  datafile '/u01/app/oracle/oradata/prod/undotbs2.dbf' size 100m
15:00:09   3  autoextend on;
15:01:28 SYS@ prod>create spfile from pfile;
File created.
Elapsed: 00:00:00.12
15:02:23 SYS@ prod>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
15:02:39 SYS@ prod>startup
ORACLE instance started.
Total System Global Area  835104768 bytes
Fixed Size                  2217952 bytes
Variable Size             775948320 bytes
Database Buffers           54525952 bytes
Redo Buffers                2412544 bytes
Database mounted.
Database opened.
15:03:36 SYS@ prod>alter system set undo_management=auto scope=spfile;
System altered.
Elapsed: 00:00:00.09
15:03:49 SYS@ prod>alter system set undo_tablespace=undotbs2 scope=spfile;
System altered.
Elapsed: 00:00:00.04
15:04:09 SYS@ prod>startup force;
ORACLE instance started.
Total System Global Area  835104768 bytes
Fixed Size                  2217952 bytes
Variable Size             775948320 bytes
Database Buffers           54525952 bytes
Redo Buffers                2412544 bytes
Database mounted.
Database opened.
15:04:28 SYS@ prod>show parameter undo
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS2
15:04:36 SYS@ prod>select usn,name from v$rollname;
       USN NAME
---------- ------------------------------
         0 SYSTEM
        21 _SYSSMU21_2312338076$
        22 _SYSSMU22_3375463809$
        23 _SYSSMU23_4084707454$
        24 _SYSSMU24_386518199$
        25 _SYSSMU25_2810228709$
        26 _SYSSMU26_2968904537$
        27 _SYSSMU27_3269963619$
        28 _SYSSMU28_707429450$
        29 _SYSSMU29_2754652023$
        30 _SYSSMU30_1737877121$
11 rows selected.
Elapsed: 00:00:00.05


15:04:44 SYS@ prod>create pfile from spfile;
File created.

将隐含参数从pfile删除:

[oracle@rh6 dbs]$ cat initprod.ora 
prod.__db_cache_size=16777216
prod.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
#*._allow_resetlogs_corruption=true
#*._corrupted_rollback_segments='_SYSSMU10_3550978943$','_SYSSMU9_1424341975$','_SYSSMU8_2012382730$','_SYSSMU7_3286610060$','_SYSSMU6_2443381498$','_SYSSMU5_1527469038$','_SYSSMU4_1152005954$','_SYSSMU3_2097677531$','_SYSSMU2_2232571081$','_SYSSMU1_3780397527$'
*.audit_file_dest='/u01/app/oracle/admin/prod/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/prod/control01.ctl','/dsk1/oradata/prod/control02.ctl'#Restore Controlfile
*.db_16k_cache_size=25165824
*.db_block_size=8192
*.db_cache_size=16777216
*.db_domain=''
*.db_keep_cache_size=0
*.db_name='prod'
*.db_recycle_cache_size=12582912
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=prodXDB)'
*.log_archive_dest_1='location=/dsk4/arch_prod'
*.log_archive_dest_2='location=/dsk4/arch1'
*.log_archive_dest_state_1='DEFER'
*.log_archive_format='arch_%t_%s_%r.log'
*.memory_target=0
*.O7_DICTIONARY_ACCESSIBILITY=TRUE
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=838860800
*.shared_pool_reserved_size=12582912
*.shared_pool_size=200886080
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS2'

重新创建spfile:

15:04:44 SYS@ prod>create spfile from pfile;
File created.

@至此,undo tablespace恢复完毕!

推荐阅读
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 构建基于BERT的中文NL2SQL模型:一个简明的基准
    本文探讨了将自然语言转换为SQL语句(NL2SQL)的任务,这是人工智能领域中一项非常实用的研究方向。文章介绍了笔者在公司举办的首届中文NL2SQL挑战赛中的实践,该比赛提供了金融和通用领域的表格数据,并标注了对应的自然语言与SQL语句对,旨在训练准确的NL2SQL模型。 ... [详细]
  • 在Ubuntu 16.04 LTS上配置Qt Creator开发环境
    本文详细介绍了如何在Ubuntu 16.04 LTS系统中安装和配置Qt Creator,涵盖了从下载到安装的全过程,并提供了常见问题的解决方案。 ... [详细]
  • 本文详细介绍了如何在 Linux 平台上安装和配置 PostgreSQL 数据库。通过访问官方资源并遵循特定的操作步骤,用户可以在不同发行版(如 Ubuntu 和 Red Hat)上顺利完成 PostgreSQL 的安装。 ... [详细]
  • 本文详细分析了Hive在启动过程中遇到的权限拒绝错误,并提供了多种解决方案,包括调整文件权限、用户组设置以及环境变量配置等。 ... [详细]
  • MySQL缓存机制深度解析
    本文详细探讨了MySQL的缓存机制,包括主从复制、读写分离以及缓存同步策略等内容。通过理解这些概念和技术,读者可以更好地优化数据库性能。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
  • 掌握远程执行Linux脚本和命令的技巧
    本文将详细介绍如何利用Python的Paramiko库实现远程执行Linux脚本和命令,帮助读者快速掌握这一实用技能。通过具体的示例和详尽的解释,让初学者也能轻松上手。 ... [详细]
  • 从 .NET 转 Java 的自学之路:IO 流基础篇
    本文详细介绍了 Java 中的 IO 流,包括字节流和字符流的基本概念及其操作方式。探讨了如何处理不同类型的文件数据,并结合编码机制确保字符数据的正确读写。同时,文中还涵盖了装饰设计模式的应用,以及多种常见的 IO 操作实例。 ... [详细]
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 在即将迎来26岁生日之际,作者的人生陷入了低谷。经过近三年的硕士学习后,最终决定退学,并且面临没有工作经验的困境。尽管如此,作者依然坚定地选择为自己的人生负责。 ... [详细]
  • 使用Python在SAE上开发新浪微博应用的初步探索
    最近重新审视了新浪云平台(SAE)提供的服务,发现其已支持Python开发。本文将详细介绍如何利用Django框架构建一个简单的新浪微博应用,并分享开发过程中的关键步骤。 ... [详细]
  • 本文详细介绍了美国最具影响力的十大财团,包括洛克菲勒、摩根、花旗银行等。这些财团在历史发展过程中逐渐形成,并对美国的经济、政治和社会产生深远影响。 ... [详细]
author-avatar
霸气的艳子_612
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有