zoukankan      html  css  js  c++  java
  • oracle坏块问题的处理

    一、背景

    今天有用户反映数据库连不上了,查看日志发现有数据库坏块。

    查看数据库日志,有如下报错:

    ORA-01578: ORACLE , 93642)
    ORA-01110: 1: '/oracle/app/orcldata/orcl/system01.dbf'
    ORACLE Instance orcl (pid = 13) - Error 1578 encountered while recovering transaction (89, 2) on object 226.
    Errors in file /oracle/app/diag/rdbms/orcl/orcl/trace/orcl_smon_3345.trc:

    二、查询坏块方法

    (1)通过trc文件查看

    查看上面err的具体trc:

    如上,坏块信息很明确。

    (2)简单语句查询

    select * from v$database_block_corruption;
    

    (3)DBV查看坏块

    dbv file=system01.dbf  blocksize=8192
    

    有一个坏块

    三、坏块的处理

    根据文件号和块号查出损坏的是对象,表还是LOB segment

    select tablespace_name,segment_type,owner,segment_name from dba_extents where file_id=1 and 93642 between block_id AND block_id + blocks - 1;
    

    其中1是文件号,93642是block号

    (1)索引损坏

    #如果被损坏的块是索引,通常可以通过索引重建来解决
    
    alter index indexname rebuild;

    (1)表损坏

     segment_type为table

    #可以使用10231事件忽略坏块,然后使用CTAS方式重建表最后rename table,别忘记rebuild index
    
    alter session SET EVENTS '10231 trace name context forever,level 10';
    
    create table tab_new as select * from tab;
    
    rename tab to tab_bak;
    
    rename tab_new to new;
    
    alter index indexname rebuild;
    
    alter session SET EVENTS '10231 trace name context off';
    

    注:根据表名查看索引名

    SELECT * FROM ALL_INDEXES WHERE TABLE_NAME='IDL_CHAR$';

    使用rman工具恢复:

    ---使用rman工具的blockrecover 
    
    blockrecover datafile xx block xx;--修复单个坏块
    blockrecover corruption list;--修复全部坏块
    

      

    (3)LOB segment损坏

    如果损坏的是LOB segment

    #先找出segment信息
    select owner, segment_name, segment_type from dba_extents where file_id = 38 and 295563 between block_id and block_id + blocks - 1;
    
    #输出如下
    owner=HGHIS
    segment_name=SYS_LOB0000119493C00006$$
    segment_type=LOBSEGMENT
    
    #找到表明和LOB字段
    select table_name, column_name from dba_lobs where segment_name = 'SYS_LOB0000119493C00006$$' and owner = 'HGHIS';
    
    #输出如下
    table_name = EMR_CASE
    column_name = WORD
    
    #找到坏块的bad rowid,使用以下plsql脚本
    create table bad_rows (row_id ROWID,oracle_error_code number);
    
  • 相关阅读:
    02_Python基础
    python 学习网站
    Docker搭建MySQL服务
    Ubuntu源、Python虚拟环境及pip源配置
    Ubuntu18.04完全卸载mysql5.7并安装mysql8.0的安装方法
    MySQL 数据库
    数据库连接池
    ssm整合开发的相关步骤和增删改查
    Springmvc执行流程
    资源映射之----在springmvc中如何访问WEB-INF目录下的文件和系统文件夹中的文件
  • 原文地址:https://www.cnblogs.com/jinyuanliu/p/10408925.html
Copyright © 2011-2022 走看看