Oracle DSI系列 01 DSI初识BBED

Wesley13
• 阅读 628

DSI是Data Server Internals的缩写,是Oracle公司内部用来培训Oracle售后工程师使用的教材。

1 bbed工具使用
BBED工具介绍
BBED stands for Block Browser and EDitor.
BBED只是一款工具,类似于ultraEdit,单纯的会用BBED来修改数据没有任何意义!关键是要知道为什么要这么改!
在充分了解Block格式和Oracle的各种机制的基础上广泛使用BBED, 用它来帮你构造测试案例,
用它来帮你验证测试结果,用它来帮你深入理解Oracle!

本系列测试版本

oracle:11.2.0.4.0

os:centos 6.5

sid:orcl

bbed的安装--(Oracle Block Brower and EDitor Tool)
用来直接查看和修改数据文件数据的一个工具,是Oracle一款内部工具
oracle 11g中缺bbed包,oracle11g bbed install and example

1.上传(sbbdpt.o ssbbded.o bbedus.msb,该三个文件拷贝oracle的linux64版本的)文件,11g是没有这3个文件,在10g里面有

$ORACLE_HOME/rdbms/lib/ssbbded.o
$ORACLE_HOME/rdbms/lib/sbbdpt.o
$ORACLE_HOME/rdbms/mesg/bbedus.msb

[root@DSI opt]# cp bbedus.msb sbbdpt.o ssbbded.o $ORACLE_HOME/rdbms/lib/.
[root@DSI opt]# chown -R oracle:oinstall $ORACLE_HOME/rdbms/lib/
[oracle@DSI ~]$ ll $ORACLE_HOME/rdbms/lib/ssbbded.o
-rw-r--r-- 1 oracle oinstall 1191 Apr 22 10:35 /u01/app/oracle/product/11.2.0/db_1/rdbms/lib/ssbbded.o

执行如下命令:

[oracle@DSI ~]$ cd $ORACLE_HOME/rdbms/lib
[oracle@DSI lib]$ make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed

Linking BBED utility (bbed)
rm -f /u01/app/oracle/product/11.2.0/db_1/bin/bbed
gcc -o /u01/app/oracle/product/11.2.0/db_1/bin/bbed -m64 -z noexecstack -L/u01/app/oracle/product/11.2.0/db_1/rdbms/lib/ -L/u01/app/oracle/product/11.2.0/db_1/lib/ -L/u01/app/oracle/product/11.2.0/db_1/lib/stubs/  /u01/app/oracle/product/11.2.0/db_1/lib/s0main.o /u01/app/oracle/product/11.2.0/db_1/rdbms/lib/ssbbded.o /u01/app/oracle/product/11.2.0/db_1/rdbms/lib/sbbdpt.o `cat /u01/app/oracle/product/11.2.0/db_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -ldbtools11 -lclntsh  `cat /u01/app/oracle/product/11.2.0/db_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat /u01/app/oracle/product/11.2.0/db_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnnz11 -lzt11 -lztkg11 -lclient11 -lnnetd11  -lvsn11 -lcommon11 -lgeneric11 -lmm -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 `cat /u01/app/oracle/product/11.2.0/db_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat /u01/app/oracle/product/11.2.0/db_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lclient11 -lnnetd11  -lvsn11 -lcommon11 -lgeneric11   -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 -lclient11 -lnnetd11  -lvsn11 -lcommon11 -lgeneric11 -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11   `cat /u01/app/oracle/product/11.2.0/db_1/lib/sysliblist` -Wl,-rpath,/u01/app/oracle/product/11.2.0/db_1/lib -lm    `cat /u01/app/oracle/product/11.2.0/db_1/lib/sysliblist` -ldl -lm   -L/u01/app/oracle/product/11.2.0/db_1/lib

2.进入BBED
bbed
blockedit ##默认密码

[oracle@DSI lib]$ bbed
Message 112 not found; No message file for product=RDBMS, facility=BBED
BBED-00113: file not found

[oracle@DSI lib]$ ll /u01/app/oracle/product/11.2.0/db_1/bin/bbed
-rwxr-xr-x 1 oracle oinstall 255078 Apr 22 10:37 /u01/app/oracle/product/11.2.0/db_1/bin/bbed
[oracle@DSI lib]$ cp bbedus.msb /u01/app/oracle/product/11.2.0/db_1/rdbms/mesg/
[oracle@DSI lib]$ bbed
Password: 

BBED: Release 2.0.0.0.0 - Limited Production on Mon Apr 22 10:42:37 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************
BBED>

进行bbed参数文件配置

SQL> select file#||chr(9)||name||chr(9)||bytes from v$datafile;

FILE#||CHR(9)||NAME||CHR(9)||BYTES
--------------------------------------------------------------------------------
1    /u01/app/oracle/oradata/orcl/system01.dbf    775946240
2    /u01/app/oracle/oradata/orcl/sysaux01.dbf    629145600
3    /u01/app/oracle/oradata/orcl/undotbs01.dbf    1184890880
4    /u01/app/oracle/oradata/orcl/users01.dbf    5242880

[oracle@DSI ~]$ vim par.txt
blocksize=8192
listfile=filelist.txt
mode=edit
[oracle@DSI ~]$ vim filelist.txt
1    /u01/app/oracle/oradata/orcl/system01.dbf    775946240
2    /u01/app/oracle/oradata/orcl/sysaux01.dbf    629145600
3    /u01/app/oracle/oradata/orcl/undotbs01.dbf    1184890880
4    /u01/app/oracle/oradata/orcl/users01.dbf    5242880
[oracle@DSI ~]$ pwd
/home/oracle
[oracle@DSI ~]$ vim .bash_profile 
[oracle@DSI ~]$ source .bash_profile 
[oracle@DSI ~]$ more .bash_profile 
alias bbed='bbed parfile=par.txt password=blockedit'
[oracle@DSI ~]$ bbed

BBED: Release 2.0.0.0.0 - Limited Production on Mon Apr 22 16:07:15 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> info
 File#  Name                                                        Size(blks)
 -----  ----                                                        ----------
     1  /u01/app/oracle/oradata/orcl/system01.dbf                        94720
     2  /u01/app/oracle/oradata/orcl/sysaux01.dbf                        76800
     3  /u01/app/oracle/oradata/orcl/undotbs01.dbf                      144640
     4  /u01/app/oracle/oradata/orcl/users01.dbf                           640

初次查看

BBED> set file 4 block 1
    FILE#              4
    BLOCK#             1

BBED> map /v
 File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
 Block: 1                                     Dba:0x01000001
------------------------------------------------------------
 Data File Header

 struct kcvfh, 860 bytes                    @0       ##头部
    struct kcvfhbfh, 20 bytes               @0       
    struct kcvfhhdr, 76 bytes               @20      
    ub4 kcvfhrdb                            @96      
    struct kcvfhcrs, 8 bytes                @100     
    ub4 kcvfhcrt                            @108     
    ub4 kcvfhrlc                            @112     
    struct kcvfhrls, 8 bytes                @116     
    ub4 kcvfhbti                            @124     
    struct kcvfhbsc, 8 bytes                @128     
    ub2 kcvfhbth                            @136     
    ub2 kcvfhsta                            @138     
    struct kcvfhckp, 36 bytes               @484     
    ub4 kcvfhcpc                            @140     
    ub4 kcvfhrts                            @144     
    ub4 kcvfhccc                            @148     
    struct kcvfhbcp, 36 bytes               @152     
    ub4 kcvfhbhz                            @312     
    struct kcvfhxcd, 16 bytes               @316     
    sword kcvfhtsn                          @332     
    ub2 kcvfhtln                            @336     
    text kcvfhtnm[30]                       @338     
    ub4 kcvfhrfn                            @368     
    struct kcvfhrfs, 8 bytes                @372     
    ub4 kcvfhrft                            @380     
    struct kcvfhafs, 8 bytes                @384     
    ub4 kcvfhbbc                            @392     
    ub4 kcvfhncb                            @396     
    ub4 kcvfhmcb                            @400     
    ub4 kcvfhlcb                            @404     
    ub4 kcvfhbcs                            @408     
    ub2 kcvfhofb                            @412     
    ub2 kcvfhnfb                            @414     
    ub4 kcvfhprc                            @416     
    struct kcvfhprs, 8 bytes                @420     
    struct kcvfhprfs, 8 bytes               @428     
    ub4 kcvfhtrt                            @444     

 ub4 tailchk                                @8188

3.常用命令:set、 find、 dump、 modify 、sum apply、examine、map 、print、 veritfy 

(1)set file 4 block 32
    set dba 0x01000020
    set offset 0           --0表示第一个字节开始
    set block  1           --1表示第一个块开始
    set count 8192         --默认是显示512字节
 (2)find /x 05d67g         --查指定的字符串在指定数据块中的具体位置
    f                      --find的简写,表示继续从当前位置开始往下查询字符串05d67g
 (3)dump                   --十六进制查看block
    dump /v                --查看十六进制内容的同时以文本方式“翻译”十六进制显示的内容,相当于对当前block执行strings命令
 (4)modify /x d43          --修改指定block,指定offset的数据块块内记录的内容
 (5)sum apply              --计算修改后的数据块的checksum值,然后写入数据块的offset为16-17的位置
 (6) map                   --会通过偏移量来显示block里的详细信息,
      map /v               --可以查看更详细的信息
      p kcbh
      p ktbbh
      p kdbh
      p kdbt
      p kcvfh
      p kcvfh.kcvfhrfn
      p kcvfh.kcvfhckp
      p *kdbr[0]  --第一行记录
      x /rnc      -examine /read number char  用16进制翻译成我们能看懂的文件
这个输出结果默认是16进制的。我们可以将其修改成其他格式
/x  Hex
/d  signed decimal
/u  unsigned decimal
/o  Octal
/c  Character
/n  Oracle Number
/t  Oracle Date
/i  Oracle ROWID

参考博客

https://blog.csdn.net/tianlesoftware/article/details/5006580

https://www.cnblogs.com/polestar/p/4243646.html

几个常用的
set 设定当前的环境
show 查看当前的环境参数,跟sqlplus的同名命令类似。
dump 列出指定block的内容,dump命令可以将block 的内从显示到屏幕。 每次显示的bytes由count 控制,默认是512 bytes。 使用 /v 选项,可以显示更多详细信息
find 在指定的block中查找指定的字符串,结果是显示出字符串,及其偏移量--offset,偏移量就是在block中的字节数
modify 修改指定block的指定偏移量的值,可以在线修改。
--BBED> modify /c dmm dba 1, 115362 offset 8155
copy 把一个block的内容copy到另一个block中
verify 检查当前环境是否有坏块
--BBED> verify dba 6,15
sum 计算block的checksum,modify之后block就被标识为坏块,current checksum与reqired checksum不一致,sum命令可以计算出新的checksum并应用到当前块。
--BBED> sum dba 1,115362 apply
undo 回滚当前的修改操作,如果手误做错了,undo一下就ok了,回到原来的状态。undo命令是回滚最后一次的操作
--BBED> undo
revert 回滚所有之前的修改操作,意思就是 undo all
--BBED> revert dba 1,115362
corrupt 将一个block 标记为corrupt,这样db 在操作时就会跳过该block,从而避免错误
--BBED> corrupt dba 6,15
--注意: undo 命令不能undo 一个corruption,但是revert 命令却可以

find
create table yhq(name1 varchar2(100));
insert into yhq values('yhq is DBA!');
insert into yhq values('yhq is mysql DBA!');

select
rowid,
dbms_rowid.rowid_relative_fno(rowid) rel_fno,
dbms_rowid.rowid_block_number(rowid) blockno,
dbms_rowid.rowid_row_number(rowid) rowno
from yhq;
----查看block 情况
SQL> select
rowid,
dbms_rowid.rowid_relative_fno(rowid) rel_fno,
dbms_rowid.rowid_block_number(rowid) blockno,
dbms_rowid.rowid_row_number(rowid) rowno
from yhq;  2    3    4    5    6  

ROWID              REL_FNO     BLOCKNO      ROWNO
------------------ ---------- ---------- ----------
AAAVRbAABAAAWahAAA        1       91809      0
AAAVRbAABAAAWahAAB        1       91809      1
BBED> set file 1 block 91809
    FILE#              1
    BLOCK#             91809

BBED> find /c yhq top
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 91809            Offsets: 8156 to 8159           Dba:0x004166a1
------------------------------------------------------------------------
 79687120 

 <32 bytes per line>
 --bbed 显示在offset 8156的为位置,我们dump 该offset 看看,如果我们要继续搜索yhq,那么只需要按下f 就可以了,不需要跟参数
 BBED> dump /v dba 1,91809 offset 8156 count 128
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 91809   Offsets: 8156 to 8191  Dba:0x004166a1
-------------------------------------------------------
 79687120 6973206d 7973716c 20444241 l yhq is mysql DBA
 212c0101 0b796871 20697320 44424121 l !,...yhq is DBA!
 0106f2a6                            l ..

 <16 bytes per line>

BBED解析DB_NAME
DB_NAME数据库名,长度不能超过8个字符,记录在datafile、 redolog和control file中

BBED> p kcvfh  ##指定具体的元素进行print
struct kcvfh, 860 bytes                     @0       
   struct kcvfhbfh, 20 bytes                @0       
      ub1 type_kcbh                         @0        0x0b
      ub1 frmt_kcbh                         @1        0xa2
      ub1 spare1_kcbh                       @2        0x00
      ub1 spare2_kcbh                       @3        0x00
      ub4 rdba_kcbh                         @4        0x01000001
      ub4 bas_kcbh                          @8        0x00000000
      ub2 wrp_kcbh                          @12       0x0000
      ub1 seq_kcbh                          @14       0x01
      ub1 flg_kcbh                          @15       0x04 (KCBHFCKV)
      ub2 chkval_kcbh                       @16       0x1220
      ub2 spare3_kcbh                       @18       0x0000
   struct kcvfhhdr, 76 bytes                @20      
      ub4 kccfhswv                          @20       0x00000000
      ub4 kccfhcvn                          @24       0x0b200400
      ub4 kccfhdbi                          @28       0x5b6f76cf
      text kccfhdbn[0]                      @32      O ##dbname
      text kccfhdbn[1]                      @33      R
      text kccfhdbn[2]                      @34      C
      text kccfhdbn[3]                      @35      L

BBED> dump
 File: /u01/app/oracle/oradata/orcl/users01.dbf (4)
 Block: 1                Offsets:    0 to  511           Dba:0x01000001
------------------------------------------------------------------------
 0ba20000 01000001 00000000 00000104 20120000 00000000 0004200b cf766f5b 
 4f52434c 00000000 ee010000 80020000 00200000 04000300 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 443e0000 00000000 582bfa3b 4f2bfa3b 01000000 00000000 00000000 
 00000000 00000000 00000400 4a000000 00000000 49000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 04000000 05005553 45525300 00000000 00000000 
 00000000 00000000 00000000 00000000 04000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
 00000000 26f60d00 00000000 d22ffa3b 01000000 49000000 8b7d0000 10000000 

 <32 bytes per line>


SQL> show parameter db_name

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
db_name                  string     orcl

SQL> select chr(to_number(substr('4f52434c00000000',rownum*2-1,2),'xxxxxxxx')) from 
dba_objects where rownum<=9;  2  

CHR(
----
O
R
C
L

诊断Trace files
alter session set events 'immediate trace name controlf level N'; ##控制文件
alter session set events 'immediate trace name file_hdrs level N';##文件头部信息
alter session set events 'immediate trace name redohdr level N';##日志文件头部信息
alter system dump undo header "_SYSSMU17_3012809736$"; ##undo文件
alter system dump datafile 3 block 256;
alter system dump logfile '/u01/app/oracle/oradata/ocm/redo01.log';
alter session set events 'immediate trace name treedump level 64952 ';

Recovery算法

Oracle为了在任何情况下都能顺利执行recovery操作,采用了一 系列的算法/设计来保证recovery的成功实施:
Page Fix
Write-Ahead-Log
Log-Force-at-Commit
Online-Log Switch Management
Checkpointing
Thread-Open Flag
Incremental Checkpointing
Two-Pass Recovery

Recovery方法
Recovery for a thread starts at last checkpoint
Recovery progresses, redo record by redo record, until all available redo has been applied
Find the block
Block time > Redo record time: Skip block
Block time = Redo record time: Apply changes
Block time < Redo record time: Stuck recovery (ORA-600 [3020])
No generation of redo

解决思路
查看告警日志
Dump控制文件和数据文件头
BBED修复
正常shutdown immediate

[oracle@DSI trace]$ pwd
/u01/app/oracle/diag/rdbms/orcl/orcl/trace
[oracle@DSI trace]$ tail -n 100 alert_orcl.log

检查点
      ub1 kcvcpetb[7]                       @519      0x00
   ub4 kcvfhcpc                             @140      0x0000004a ##检查点
   ub4 kcvfhrts                             @144      0x00000000
   ub4 kcvfhccc                             @148      0x00000049 ##控制文件
   struct kcvfhbcp, 36 bytes                @152

BBED> p kcvfhcpc
ub4 kcvfhcpc                                @140      0x0000004a

BBED> 
BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x00000049
##文件头kcvfhcpc的检查点计数器的值(0x0000004a)比控制文件kcvfhccc计数器的值小(0x00000049)的话,数据库打开和关闭就会有问题
,需要修改值


当前控制文件中的SCN号
SQL> col name format a65
SQL> select file#,to_char(checkpoint_change#,'999999999999') from v$datafile;

     FILE# TO_CHAR(CHECK
---------- -------------
     1      929146
     2      929146
     3      929146
     4      929146
数据文件的状态
SQL> set pagesize 9999
SQL> set linesize 9999

SQL> select file#,status,name from v$datafile;

     FILE# STATUS  NAME
---------- ------- -----------------------------------------------------------------
     1 SYSTEM  /u01/app/oracle/oradata/orcl/system01.dbf
     2 ONLINE  /u01/app/oracle/oradata/orcl/sysaux01.dbf
     3 ONLINE  /u01/app/oracle/oradata/orcl/undotbs01.dbf
     4 ONLINE  /u01/app/oracle/oradata/orcl/users01.dbf
添加测试数据文件表空间
SQL> CREATE TABLESPACE test DATAFILE '/u01/app/oracle/oradata/orcl/test01.dbf' SIZE 50M;

Tablespace created.

SQL> select file#,status,name from v$datafile;

     FILE# STATUS  NAME
---------- ------- -----------------------------------------------------------------
     1 SYSTEM  /u01/app/oracle/oradata/orcl/system01.dbf
     2 ONLINE  /u01/app/oracle/oradata/orcl/sysaux01.dbf
     3 ONLINE  /u01/app/oracle/oradata/orcl/undotbs01.dbf
     4 ONLINE  /u01/app/oracle/oradata/orcl/users01.dbf
     5 ONLINE  /u01/app/oracle/oradata/orcl/test01.dbf

模拟故障,
https://www.cnblogs.com/polestar/p/4243646.html

1 将datafile 5 online

SQL> alter database datafile 5 offline;
alter database datafile 5 offline
*
ERROR at line 1:
ORA-01145: offline immediate disallowed unless media recovery enabled ##数据库处于归档模式才能将数据文件offline
SQL> select name,log_mode from v$database;

NAME                                  LOG_MODE
----------------------------------------------------------------- ------------
ORCL                                  NOARCHIVELOG

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size            2257352 bytes
Variable Size          511708728 bytes
Database Buffers      264241152 bytes
Redo Buffers            6791168 bytes
Database mounted.
SQL> alter database archivelog; ##修改为归档模式

Database altered.

SQL> alter database open;

Database altered.

SQL> select name,log_mode from v$database;

NAME                                  LOG_MODE
----------------------------------------------------------------- ------------
ORCL                                  ARCHIVELOG

SQL> alter database datafile 5 offline;

Database altered.

SQL> select file#,status,name from v$datafile;

     FILE# STATUS  NAME
---------- ------- -----------------------------------------------------------------
     1 SYSTEM  /u01/app/oracle/oradata/orcl/system01.dbf
     2 ONLINE  /u01/app/oracle/oradata/orcl/sysaux01.dbf
     3 ONLINE  /u01/app/oracle/oradata/orcl/undotbs01.dbf
     4 ONLINE  /u01/app/oracle/oradata/orcl/users01.dbf
     5 RECOVER /u01/app/oracle/oradata/orcl/test01.dbf ##文件状态已经被修改

2 更改文件的scn号

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
     1           930121
     2           930121
     3           930121
     4           930121
     5           930121

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
     1           930517
     2           930517
     3           930517
     4           930517
     5           930121 ##多执行几次,这里已经不一样了
##查看需要恢复datafile的scn
SQL> select file#,online_status,change# from v$recover_file;

     FILE# ONLINE_    CHANGE#
---------- ------- ----------
     5 OFFLINE     930121

3 把datafile设置为online

SQL> alter database datafile 5 online;
alter database datafile 5 online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/test01.dbf'
##提示需要进行数据恢复
##/u01/app/oracle/diag/rdbms/orcl/orcl/trace/
Tue Apr 23 09:31:31 2019
alter database datafile 5 online
ORA-1113 signalled during: alter database datafile 5 online...


利用bbed修改数据文件5号的scn号
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

利用bbed查看文件1和文件5的scn号
Oracle根据4个属性来判断datafile 是否和其他的datafile 一致,如果都一致,可以正常操作,如果不一致,那么会报ORA-01113错误
  kscnbas (at offset 484) - SCN of last change to the datafile.
  kcvcptim (at offset 492) -Time of the last change to the datafile.
  kcvfhcpc (at offset 140) - Checkpoint count.
  kcvfhccc (at offset 148) - Unknown, but is always 1 less than thecheckpoint point count
这四个属性值存在File header中,即文件的第一个数据块中

[oracle@DSI ~]$ bbed

BBED: Release 2.0.0.0.0 - Limited Production on Mon Apr 22 18:05:42 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> info
 File#  Name                                                        Size(blks)
 -----  ----                                                        ----------
     1  /u01/app/oracle/oradata/orcl/system01.dbf                        94720
     2  /u01/app/oracle/oradata/orcl/sysaux01.dbf                        76800
     3  /u01/app/oracle/oradata/orcl/undotbs01.dbf                      144640
     4  /u01/app/oracle/oradata/orcl/users01.dbf                           640

BBED> set file 1 block 1
    FILE#              1
    BLOCK#             1

BBED> map /v
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 1                                     Dba:0x00400001
------------------------------------------------------------
 Data File Header

 struct kcvfh, 860 bytes                    @0       
    struct kcvfhbfh, 20 bytes               @0       
    struct kcvfhhdr, 76 bytes               @20      
    ub4 kcvfhrdb                            @96      
    struct kcvfhcrs, 8 bytes                @100     
    ub4 kcvfhcrt                            @108     
    ub4 kcvfhrlc                            @112     
    struct kcvfhrls, 8 bytes                @116     
    ub4 kcvfhbti                            @124     
    struct kcvfhbsc, 8 bytes                @128     
    ub2 kcvfhbth                            @136     
    ub2 kcvfhsta                            @138     
    struct kcvfhckp, 36 bytes               @484     
    ub4 kcvfhcpc                            @140     
    ub4 kcvfhrts                            @144     
    ub4 kcvfhccc                            @148     
    struct kcvfhbcp, 36 bytes               @152     
    ub4 kcvfhbhz                            @312     
    struct kcvfhxcd, 16 bytes               @316     
    sword kcvfhtsn                          @332     
    ub2 kcvfhtln                            @336     
    text kcvfhtnm[30]                       @338     
    ub4 kcvfhrfn                            @368     
    struct kcvfhrfs, 8 bytes                @372     
    ub4 kcvfhrft                            @380     
    struct kcvfhafs, 8 bytes                @384     
    ub4 kcvfhbbc                            @392     
    ub4 kcvfhncb                            @396     
    ub4 kcvfhmcb                            @400     
    ub4 kcvfhlcb                            @404     
    ub4 kcvfhbcs                            @408     
    ub2 kcvfhofb                            @412     
    ub2 kcvfhnfb                            @414     
    ub4 kcvfhprc                            @416     
    struct kcvfhprs, 8 bytes                @420     
    struct kcvfhprfs, 8 bytes               @428     
    ub4 kcvfhtrt                            @444     

 ub4 tailchk                                @8188  

BBED> p kcvfhckp
struct kcvfhckp, 36 bytes                   @484     
   struct kcvcpscn, 8 bytes                 @484     
      ub4 kscnbas                           @484      0x000e38a5
      ub2 kscnwrp                           @488      0x0000
   ub4 kcvcptim                             @492      0x3bfa9b54
   ub2 kcvcpthr                             @496      0x0001
   union u, 12 bytes                        @500     
      struct kcvcprba, 12 bytes             @500     
         ub4 kcrbaseq                       @500      0x0000004e
         ub4 kcrbabno                       @504      0x00000b88
         ub2 kcrbabof                       @508      0x0010
   ub1 kcvcpetb[0]                          @512      0x02
   ub1 kcvcpetb[1]                          @513      0x00
   ub1 kcvcpetb[2]                          @514      0x00
   ub1 kcvcpetb[3]                          @515      0x00
   ub1 kcvcpetb[4]                          @516      0x00
   ub1 kcvcpetb[5]                          @517      0x00
   ub1 kcvcpetb[6]                          @518      0x00
   ub1 kcvcpetb[7]                          @519      0x00

BBED> p kcvfhcpc
ub4 kcvfhcpc                                @140      0x00000053

BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x00000052
##这里kcvfhcpc比控制文件kcvfhccc的检查点的值要大,小的话肯定要报错,启动或关闭不了

--修改kscnbas
BBED> modify /x 9972fb3b dba 5,1 offset 492
BBED-00209: invalid number (9972fb3b)
--报无法修改,看看两个文件的484至487的4个字节值的异同
BBED> dump /v dba 1,1 offset 484 count 32
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 1       Offsets:  484 to  515  Dba:0x00400001
-------------------------------------------------------
 8d8d0e00 00000000 9972fb3b 01000000 l .........r񬬮.
 4f000000 02000000 10000000 02000000 l O...............

 <16 bytes per line>

BBED> dump /v dba 5,1 offset 484 count 32
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1       Offsets:  484 to  515  Dba:0x01400001
-------------------------------------------------------
 49310e00 00000000 fb8ffa3b 01000000 l I1......󸹮...
 49000000 6de80000 10000000 02000000 l I...m欮........

 <16 bytes per line>

--观察文件1和文件5的前四个字节的异同,只修改484,485前两字节
##modify /x 8d8d dba 5,1 offset 484
BBED> modify /x 8d8d dba 5,1 offset 484
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1                Offsets:  484 to  515           Dba:0x01400001
------------------------------------------------------------------------
 8d8d0e00 00000000 fb8ffa3b 01000000 49000000 6de80000 10000000 02000000 

 <32 bytes per line>
-修改kcvcptim
BBED> dump /v dba 1,1 offset 492 count 4
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 1       Offsets:  492 to  495  Dba:0x00400001
-------------------------------------------------------
 9972fb3b                            l .r

 <16 bytes per line>

BBED> dump /v dba 5,1 offset 492 count 4
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1       Offsets:  492 to  495  Dba:0x01400001
-------------------------------------------------------
 fb8ffa3b                            l 

 <16 bytes per line>
##modify /x 9972 dba 5,1 offset 492
BBED> modify /x 9972 dba 5,1 offset 492
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1                Offsets:  492 to  495           Dba:0x01400001
------------------------------------------------------------------------
 9972fa3b 

 <32 bytes per line>
--修改kcvfhcpc
BBED> dump /v dba 1,1 offset 140 count 4
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 1       Offsets:  140 to  143  Dba:0x00400001
-------------------------------------------------------
 57000000                            l W...

 <16 bytes per line>

BBED> dump /v dba 5,1 offset 140 count 4
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1       Offsets:  140 to  143  Dba:0x01400001
-------------------------------------------------------
 04000000                            l ....

 <16 bytes per line>
##modify /x 5700 dba 5,1 offset 140
BBED> modify /x 5700 dba 5,1 offset 140
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1                Offsets:  140 to  143           Dba:0x01400001
------------------------------------------------------------------------
 57000000 

 <32 bytes per line>
--修改kcvfhccc
BBED> dump /v dba 1,1 offset 148 count 4
 File: /u01/app/oracle/oradata/orcl/system01.dbf (1)
 Block: 1       Offsets:  148 to  151  Dba:0x00400001
-------------------------------------------------------
 56000000                            l V...

 <16 bytes per line>

BBED> dump /v dba 5,1 offset 148 count 4
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1       Offsets:  148 to  151  Dba:0x01400001
-------------------------------------------------------
 03000000                            l ....

 <16 bytes per line>
##modify /x 5600 dba 5,1 offset 148
BBED> modify /x 5600 dba 5,1 offset 148
 File: /u01/app/oracle/oradata/orcl/test01.dbf (5)
 Block: 1                Offsets:  148 to  151           Dba:0x01400001
------------------------------------------------------------------------
 56000000 

 <32 bytes per line>

应用修改
BBED> sum apply
Check value for File 5, Block 1:
current = 0x1c88, required = 0x1c88

SQL> alter database datafile 5 online; 
alter database datafile 5 online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/test01.dbf'
alter database datafile 5 online
ORA-1113 signalled during: alter database datafile 5 online...
Tue Apr 23 09:49:04 2019
Checker run found 1 new persistent data failures

##测试到这里了,对bbed修改oracle块的还是差一点意思,为了后面的测试继续,这里只好使用rman先恢复

RMAN> restore datafile 5;
RMAN> recover datafile 5;

SQL> alter database datafile 5 online;

Database altered.
SQL> alter system switch logfile;

System altered.

SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
     1           958624
     2           958624
     3           958624
     4           958624
     5           958624
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
3年前
swap空间的增减方法
(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这