[20160405]bbed修改文件头.txt

简介: [20160405]bbed修改文件头.txt --以前做过一次,重复测试: http://blog.itpub.net/267265/viewspace-746222/ 如果数据库数据文件损坏,并且archivelog损坏,这样无法完全恢复,如果仅仅某个数据文件的scn与其他文件不同步,导致该数据文件无法mount.

[20160405]bbed修改文件头.txt

--以前做过一次,重复测试:
http://blog.itpub.net/267265/viewspace-746222/

如果数据库数据文件损坏,并且archivelog损坏,这样无法完全恢复,如果仅仅某个数据文件的scn与其他文件不同步,导致该数据文件无法mount.
正常可以像odu之类的工具恢复.但是在实际上如果修改数据文件的scn保持同步,这样数据库可以正常打开,选择常规的方法imp/exp以及expdp/impdp
方式恢复,这样虽然丢失一部分数据,至少一定程度减少损失.

--以前测试有点乱.

1.环境:
--冷备份数据库:

$ cp tea01.dbf tea01.dbf_ORG

 

SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name BOOK

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    770      SYSTEM               ***     /mnt/ramdisk/book/system01.dbf
2    1580     SYSAUX               ***     /mnt/ramdisk/book/sysaux01.dbf
3    1435     UNDOTBS1             ***     /mnt/ramdisk/book/undotbs01.dbf
4    500      USERS                ***     /mnt/ramdisk/book/users01.dbf
5    346      EXAMPLE              ***     /mnt/ramdisk/book/example01.dbf
6    100      SUGAR                ***     /mnt/ramdisk/book/sugar01.dbf
7    1        TEA                  ***     /mnt/ramdisk/book/tea01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    400      TEMP                 32767       /mnt/ramdisk/book/temp01.dbf

SYS@book> select * from scott.empx where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 YYYY       CLERK           7902 1980-12-17 00:00:00        800                    20

SYS@book> update scott.empx set ename='ZZZZ' where EMPNO=7369;
1 row updated.

SYS@book> commit ;
Commit complete.

alter system archive log current ;
/
/
/

2.假设现在数据库破坏,tea文件仅仅存在旧的备份,看看是否online看看.
SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

$ cp tea01.dbf tea01.dbf_0405
$ mv tea01.dbf_ORG tea01.dbf

--模拟归档丢失.
$ cd /u01/app/oracle/archivelog/
$ mv book book.xxx
$ mkdir book

3.测试:

SYS@book> startup
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'

--都是归档,无法恢复.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ----------------
    1        13227502431 2016-04-05 11:33:18                7       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227502431 2016-04-05 11:33:18             1834       13227286650 ONLINE              1004 NO  /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227502431 2016-04-05 11:33:18           923328       13227286650 ONLINE               924 NO  /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227502431 2016-04-05 11:33:18            16143       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/users01.dbf    USERS
    5        13227502431 2016-04-05 11:33:18           952916       13227286650 ONLINE               921 NO  /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227502431 2016-04-05 11:33:18          1314508       13227286650 ONLINE               937 NO  /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227500866 2016-03-31 08:53:17      13227207527       13227286650 ONLINE                25 NO  /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

SYS@book> @ &r/10to16 13227502431
10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146bab5f 0x5fab6b14-03000000

SYS@book> @ &r/10to16 13227500866
10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146ba542 0x42a56b14-03000000

BBED> p kcvfh.kcvfhckp.kcvcpscn.kscnbas dba 7,1
ub4 kscnbas                                 @484      0x146ba542

BBED> p kcvfh.kcvfhckp.kcvcpscn.kscnbas dba 1,1
ub4 kscnbas                                 @484      0x146bab5f

BBED> assign dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas = dba 1,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas;
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
ub4 kscnbas                                 @484      0x146bab5f

BBED> sum apply dba 7.1
BBED-00205: illegal or out of range DBA (File 0, Block 7)

BBED> sum apply dba 7,1
Check value for File 7, Block 1:
current = 0x0b12, required = 0x0b12

BBED> verify dba 7,1
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/tea01.dbf
BLOCK = 1


DBVERIFY - Verification complete

Total Blocks Examined         : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing   (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing   (Index): 0
Total Blocks Empty            : 0
Total Blocks Marked Corrupt   : 0
Total Blocks Influx           : 0
Message 531 not found;  product=RDBMS; facility=BBED

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ---------------
    1        13227502431 2016-04-05 11:33:18                7       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227502431 2016-04-05 11:33:18             1834       13227286650 ONLINE              1004 NO  /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227502431 2016-04-05 11:33:18           923328       13227286650 ONLINE               924 NO  /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227502431 2016-04-05 11:33:18            16143       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/users01.dbf    USERS
    5        13227502431 2016-04-05 11:33:18           952916       13227286650 ONLINE               921 NO  /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227502431 2016-04-05 11:33:18          1314508       13227286650 ONLINE               937 NO  /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227502431 2016-03-31 08:53:17      13227207527       13227286650 ONLINE                25 NO  /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

SYS@book> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'


SYS@book> recover datafile 7 ;
Media recovery complete.
SYS@book> alter database open ;
Database altered.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                            TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------- ---------------
    1        13227502434 2016-04-05 11:43:01                7       13227286650 ONLINE              1009 YES /mnt/ramdisk/book/system01.dbf  SYSTEM
    2        13227502434 2016-04-05 11:43:01             1834       13227286650 ONLINE              1005 YES /mnt/ramdisk/book/sysaux01.dbf  SYSAUX
    3        13227502434 2016-04-05 11:43:01           923328       13227286650 ONLINE               925 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
    4        13227502434 2016-04-05 11:43:01            16143       13227286650 ONLINE              1009 YES /mnt/ramdisk/book/users01.dbf   USERS
    5        13227502434 2016-04-05 11:43:01           952916       13227286650 ONLINE               922 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
    6        13227502434 2016-04-05 11:43:01          1314508       13227286650 ONLINE               938 YES /mnt/ramdisk/book/sugar01.dbf   SUGAR
    7        13227502434 2016-04-05 11:43:01      13227207527       13227286650 ONLINE                32 YES /mnt/ramdisk/book/tea01.dbf     TEA
7 rows selected.

--自动修复CHECKPOINT_COUNT记数.视乎11.2.0.4不再需要修改CHECKPOINT_COUNT.

SYS@book> select * from scott.empx where rownum<=1;
       EMPNO ENAME      JOB                MGR HIREDATE                     SAL         COMM       DEPTNO
------------ ---------- --------- ------------ ------------------- ------------ ------------ ------------
        7369 YYYY       CLERK             7902 1980-12-17 00:00:00          800                        20

--不过修改都丢失了.还原:
$ mv tea01.dbf_0405 tea01.dbf
$ cd /u01/app/oracle/archivelog/
$ mv book book.test
$ mv book.xxx/ book

SYS@book> startup mount
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
SYS@book> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'


SYS@book> recover datafile 7 ;
Media recovery complete.
SYS@book> alter database open ;

Database altered.

SYS@book> select * from scott.empx where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 ZZZZ       CLERK           7902 1980-12-17 00:00:00        800                    20

--OK,已经还原了.

--CHECKPOINT_COUNT的位置:

BBED> p kcvfh.kcvfhcpc dba 7,1
ub4 kcvfhcpc                                @140      0x00000023

BBED> p kcvfh.kcvfhcpc dba 1,1
ub4 kcvfhcpc                                @140      0x000003f3

SYS@book> @ &r/16to10 3f3
16 to 10 DEC
------------
        1011

SYS@book> @ &r/16to10 23
16 to 10 DEC
------------
          35

 

--实际上这样的测试存在许多问题,比如drop表,create表,这样在系统表空间存在定义,而数据文件已经丢失了.

目录
相关文章
ReadMe2.txt 文件内容拷贝 到 新的ReadMe.txt 分析 : 拷贝: 从ReadMe2.txt读取 写入到ReadMe.txt 1.创建两个文
ReadMe2.txt 文件内容拷贝 到 新的ReadMe.txt 分析 : 拷贝: 从ReadMe2.txt读取 写入到ReadMe.txt 1.创建两个文
|
Oracle 关系型数据库 数据库管理
[20180628]显示bbed x命令格式.txt
[20180628]显示bbed x命令格式.txt --//测试经常使用bbed x命令显示数据,里面的格式每次输入必须显示表结构才方便输入. --//如果字段很多非常麻烦,写一个脚本完成这个工作.
1302 0
|
Oracle 关系型数据库 数据库
[20180604]在内存修改数据(bbed).txt
[20180604]在内存修改数据(bbed).txt --//以前曾经做过在内存修改数据,通过oradebug poke命令修改内存信息,相关链接: --//http://blog.itpub.net/267265/viewspace-2124466/=>[20160904]在内存修改数据.txt --//今天测试看看是否通过bbed修改数据信息的情况.使用asmm,这样/dev/shm可以看到一个一个文件。
1080 0
|
数据库管理
[20180205]使用bbed相关问题.txt
[20180205]使用bbed相关问题.txt --//上个星期5使用bbed修改块遇到一些问题,做一个记录: 1.环境: SCOTT@book> @ ver1 PORT_STRING                    VERSION       ...
940 0
|
监控 Oracle 关系型数据库
[20171208]强制删除归档日志文件.txt
[20171208]强制删除归档日志文件.txt --//测试环境,产生日志太多,想强制删除. RMAN> delete archivelog all ; released channel: ORA_DISK_1 allocated channel: ORA...
1396 0
|
Oracle 关系型数据库 数据库管理
[20171124]bbed的使用问题2.txt
[20171124]bbed的使用问题2.txt --//bbed 是探究oracle数据块的好工具,有时候不用转储,直接可以它看oracle内部块的内部结构. --//在使用中要注意一些问题,昨天又犯类似错误,通过例子来说明: SCOTT@book> select rowid,dept.
1242 0
|
数据库管理
[20170412]bbed隐藏数据记录.txt
[20170412]bbed隐藏数据记录.txt --上午做了bbed恢复修改记录(不等长)的情况,http://blog.itpub.net/267265/viewspace-2137082/ --下午做一个隐藏数据记录的情况,实际上这样做有点多余,就是删除命令,看看bbed是否可以完成。
1128 0
|
Oracle 关系型数据库 数据库
[20170406]关于文件头转储.txt
[20170406]关于文件头转储.txt --//oracle 数据库文件头转储使用如下命令alter session set events 'immediate trace name file_hdrs level 12' ; --//实际上里面有一部分信息来自控制文件,在分析时注意,通过例子来说明: 1.
764 0
|
Oracle 关系型数据库 数据库管理
[20161124]bbed使用问题.txt
[20161124]bbed使用问题.txt --最近一致在使用bbed探究oracle数据库,遇到一些问题做一些记录。 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION  ...
873 0
|
Oracle 关系型数据库 数据库管理
[20161108]关于数据文件的问题.txt
[20161108]关于数据文件的问题.txt --昨天看了一些数据文件位图问题,今天探究数据文件的其他问题。 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION     ...
851 0