ITPub博客

首页 > 数据库 > Oracle > 【TUNE_ORACLE】查看Oracle的坏块在空闲空间中还是在已用空间中的SQL参考

【TUNE_ORACLE】查看Oracle的坏块在空闲空间中还是在已用空间中的SQL参考

原创 Oracle 作者:Attack_on_Jager 时间:2021-09-09 16:10:51 0 删除 编辑

实验环境

搭建平台:VMware Workstation

OS:RHEL 6.10

Grid&DB:Oracle 11.2.0.4


SQL参考

说明:如果没有在RMAN执行命令“backup check logical validate database”,就不会在视图 v$database_block_corruption中灌入数据,则 以下SQL也就可能不会有任何输出!


--如果使用sqlplus查询先要格式化

set lines 200 pages 10000

col segment_name format a30

SELECT e.owner,

       e.segment_type,
       e.segment_name,
       e.partition_name,
       c.file#,
       greatest(e.block_id, c.block#) corr_start_block#,
       least(e.block_id + e.blocks - 1, c.block# + c.blocks - 1) corr_end_block#,
       least(e.block_id + e.blocks - 1, c.block# + c.blocks - 1) -
       greatest(e.block_id, c.block#) + 1 blocks_corrupted,
       null description
  FROM dba_extents e, v$database_block_corruption c
 WHERE e.file_id = c.file#
   AND e.block_id <= c.block# + c.blocks - 1
   AND e.block_id + e.blocks - 1 >= c.block#
UNION
SELECT s.owner,
       s.segment_type,
       s.segment_name,
       s.partition_name,
       c.file#,
       header_block corr_start_block#,
       header_block corr_end_block#,
       1 blocks_corrupted,
       'Segment Header' description
  FROM dba_segments s, v$database_block_corruption c
 WHERE s.header_file = c.file#
   AND s.header_block between c.block# and c.block# + c.blocks - 1
UNION
SELECT null owner,
       null segment_type,
       null segment_name,
       null partition_name,
       c.file#,
       greatest(f.block_id, c.block#) corr_start_block#,
       least(f.block_id + f.blocks - 1, c.block# + c.blocks - 1) corr_end_block#,
       least(f.block_id + f.blocks - 1, c.block# + c.blocks - 1) -
       greatest(f.block_id, c.block#) + 1 blocks_corrupted,
       'Free Block' description
  FROM dba_free_space f, v$database_block_corruption c
 WHERE f.file_id = c.file#
   AND f.block_id <= c.block# + c.blocks - 1
   AND f.block_id + f.blocks - 1 >= c.block#
 ORDER BY file#, corr_start_block#;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69992972/viewspace-2791269/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
在某银行任职DBA,拥有多年数据库运维经验,擅长Oracle,MySQL。尤其擅长Oracle的SQL优化,数据库性能调优,数据库备份、恢复与迁移。拥有的认证:OCM 12c,OCM 11g,MySQL OCP,RHCE,阿里云ACP,巨杉SCDP,软考系统集成工程师认证,Oracle Iaas OCA,OBCA,TDSQL认证,TBase认证

注册时间:2021-01-11

  • 博文量
    102
  • 访问量
    260143