首先,壞塊分為物理壞塊和邏輯壞塊,前者通常是硬體的問題,后者是oracle本身內部的問題,
先給oracle資料庫開啟歸檔模式
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /oracle/app/product/11.2.0/db_1/dbs/arch
Oldest online log sequence 6
Current log sequence 8
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 759943168 bytes
Fixed Size 2257112 bytes
Variable Size 654315304 bytes
Database Buffers 96468992 bytes
Redo Buffers 6901760 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/app/product/11.2.0/db_1/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
創建壞塊修復實驗的表空間,用戶和所需權限
--創建一個大小為1m的表空間
create tablespace test datafile '/oracle/app/oradata/xtts11g/test01.dbf' size 1m;
--創建test用戶
create user test identified by test default tablespace test temporary tablespace temp profile DEFAULT;
--授予相關的測驗權限
grant connect,dba,resource,unlimited tablespace to test;
創建表和模擬資料
SQL> conn test/test;
Connected.
SQL> create table test tablespace test as select * from scott.emp;
Table created.
SQL> insert into test select * from test;
14 rows created.
SQL> /
28 rows created.
SQL> /
56 rows created.
SQL> /
112 rows created.
SQL> /
224 rows created.
SQL> /
448 rows created.
SQL> /
896 rows created.
SQL> /
1792 rows created.
SQL> /
3584 rows created.
SQL> /
7168 rows created.
SQL> /
insert into test select * from test
*
ERROR at line 1:
ORA-01653: unable to extend table TEST.TEST by 8 in tablespace TEST
SQL> select count(*) from test;
COUNT(*)
----------
14336
觸發檢查點,將資料寫入到資料檔案中
SQL> alter system checkpoint;
System altered.
進行模擬壞塊前,先用rman進行備份
[oracle@mongodb ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Feb 20 13:46:55 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: XTTS11G (DBID=1621650015)
RMAN> backup tablespace 'TEST' tag=zq;
Starting backup at 20-FEB-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=406 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/oracle/app/oradata/xtts11g/test01.dbf
input datafile file number=00006 name=/oracle/app/oradata/xtts11g/test02.dbf
channel ORA_DISK_1: starting piece 1 at 20-FEB-21
channel ORA_DISK_1: finished piece 1 at 20-FEB-21
piece handle=/oracle/app/product/11.2.0/db_1/dbs/01vnlmnq_1_1 tag=ZQ comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 20-FEB-21
RMAN>
關閉資料庫,用bbed篡改資料檔案
bbed安裝方法
cp ssbbded.o $ORACLE_HOME/rdbms/lib
cp sbbdpt.o $ORACLE_HOME/rdbms/lib
cp bbedus.msg $ORACLE_HOME/rdbms/mesg
cp bbedus.msb $ORACLE_HOME/rdbms/mesg
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
bbed的安裝介質在我的資源分享中可以免費下載,linux和aix的都有
使用bbed修改資料檔案,人為制造壞塊
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@mongodb ~]$ cd $ORACLE_HOME/rdbms/lib
[oracle@mongodb lib]$ ls bbed
bbed
[oracle@mongodb lib]$ vi par.txt
blocksize=8192
listfile=filelist.txt
mode=edit
[oracle@mongodb lib]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 22 13:54:47 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select file#||chr(9)||name||chr(9)||bytes from v$datafile;
FILE#||CHR(9)||NAME||CHR(9)||BYTES
--------------------------------------------------------------------------------
1 /oracle/app/oradata/xtts11g/system01.dbf 796917760
2 /oracle/app/oradata/xtts11g/sysaux01.dbf 534773760
3 /oracle/app/oradata/xtts11g/undotbs01.dbf 89128960
4 /oracle/app/oradata/xtts11g/users01.dbf 5242880
5 /oracle/app/oradata/xtts11g/test01.dbf 1048576
6 /oracle/app/oradata/xtts11g/test02.dbf 106496
6 rows selected.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@mongodb lib]$ vi filelist.txt
1 /oracle/app/oradata/xtts11g/system01.dbf 796917760
2 /oracle/app/oradata/xtts11g/sysaux01.dbf 534773760
3 /oracle/app/oradata/xtts11g/undotbs01.dbf 89128960
4 /oracle/app/oradata/xtts11g/users01.dbf 5242880
5 /oracle/app/oradata/xtts11g/test01.dbf 1048576
6 /oracle/app/oradata/xtts11g/test02.dbf 106496
選擇5號資料檔案
[oracle@mongodb lib]$ ./bbed parfile=par.txt password=blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Mon Feb 22 13:56:20 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> set dba 5,19
DBA 0x01400013 (20971539 5,19)
破壞尾部8188偏移量
BBED> map
File: /oracle/app/oradata/xtts11g/test01.dbf (5)
Block: 19 Dba:0x01400013
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @100
struct kdbt[1], 4 bytes @114
sb2 kdbr[170] @118
ub1 freespace[837] @458
ub1 rowdata[6893] @1295
ub4 tailchk @8188
BBED> set offset 8188
OFFSET 8188
BBED> m /x ff 8188
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
File: /oracle/app/oradata/xtts11g/test01.dbf (5)
Block: 19 Offsets: 8188 to 8191 Dba:0x01400013
------------------------------------------------------------------------
ff06c348
<32 bytes per line>
BBED> sum apply
Check value for File 5, Block 19:
current = 0x084c, required = 0x084c
BBED> verify
DBVERIFY - Verification starting
FILE = /oracle/app/oradata/xtts11g/test01.dbf
BLOCK = 19
Block 19 is corrupt
Corrupt block relative dba: 0x01400013 (file 0, block 19)
Fractured block found during verification
Data in bad block:
type: 6 format: 2 rdba: 0x01400013
last change scn: 0x0000.001048c3 seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x48c306ff
check value in block header: 0x84c
computed block checksum: 0x0
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 : 1
Total Blocks Influx : 2
Message 531 not found; product=RDBMS; facility=BBED
可以看到已經成功制造了壞塊,現在使用dbv和查詢再次驗證下
[oracle@mongodb lib]$ dbv file=/oracle/app/oradata/xtts11g/test01.dbf
DBVERIFY: Release 11.2.0.4.0 - Production on Mon Feb 22 14:01:04 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE = /oracle/app/oradata/xtts11g/test01.dbf
Page 19 is influx - most likely media corrupt
Corrupt block relative dba: 0x01400013 (file 5, block 19)
Fractured block found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x01400013
last change scn: 0x0000.001048c3 seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x48c306ff
check value in block header: 0x84c
computed block checksum: 0x0
DBVERIFY - Verification complete
Total Pages Examined : 128
Total Pages Processed (Data) : 109
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 17
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 1
Total Pages Marked Corrupt : 1
Total Pages Influx : 1
Total Pages Encrypted : 0
Highest block SCN : 1067203 (0.1067203)
SQL> startup
ORACLE instance started.
Total System Global Area 759943168 bytes
Fixed Size 2257112 bytes
Variable Size 654315304 bytes
Database Buffers 96468992 bytes
Redo Buffers 6901760 bytes
Database mounted.
Database opened.
SQL> conn test/test;
Connected.
SQL> select count(*) from test;
select count(*) from test
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 19)
ORA-01110: data file 5: '/oracle/app/oradata/xtts11g/test01.dbf'
利用備份恢復壞塊
[oracle@mongodb lib]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Feb 22 14:21:59 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: XTTS11G (DBID=1621650015)
RMAN> blockrecover datafile 5 block 19;
Starting recover at 22-FEB-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=406 device type=DISK
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00005
channel ORA_DISK_1: reading from backup piece /oracle/app/product/11.2.0/db_1/dbs/06vnqvog_1_1
channel ORA_DISK_1: piece handle=/oracle/app/product/11.2.0/db_1/dbs/06vnqvog_1_1 tag=ZQ
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 22-FEB-21
[oracle@mongodb lib]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 22 14:25:30 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn test/test;
Connected.
SQL> select count(*) from test;
COUNT(*)
----------
14336
至此,修復完成,當然這是有備份情況下的壞塊修復,接下來我還會更新沒有備份的時候的壞塊處理方式,有興趣的小伙伴可以關注一下博主,過幾日繼續更新,覺得文章有用的點個贊把!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/262454.html
標籤:其他
上一篇:MySQL 按時間單位進行分組
