<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>惜分飞 &#187; shell extents</title>
	<atom:link href="https://www.xifenfei.com/tag/shell-extents/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Sat, 07 Nov 2026 15:45:44 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>shell脚本获得extents分布</title>
		<link>https://www.xifenfei.com/2013/05/shell%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%be%97extents%e5%88%86%e5%b8%83.html</link>
		<comments>https://www.xifenfei.com/2013/05/shell%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%be%97extents%e5%88%86%e5%b8%83.html#comments</comments>
		<pubDate>Fri, 31 May 2013 14:42:56 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell extents]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=4455</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2013/05/shell%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%be%97extents%e5%88%86%e5%b8%83.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2013/05/shell%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%be%97extents%e5%88%86%e5%b8%83.html" target="_blank">shell脚本获得extents分布</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p>比较深入看过dba_extents视图的朋友都知道,它得到extent的信息不是通过普通的存储在数据库中的基表获得,而是x$相关的表获得(x$表是数据库启动时候在内存中创建,不存在数据文件中),因为当数据库未正常启动,我们无法直接确定某个block是否在某个对象中.其实关于extent的信息都已经记录在了segment header的block中,通过dump该block记录的rdba信息,未转化为file_id和block_id,这里写shell脚本实现把segment header dump 内容转化为类似dba_extents记录,方便在某些不能open的库中分析某个异常block是否属于某个表</p>
<pre class="brush: bash; title: ; notranslate">
#! /bin/bash

dec2bin(){
  val_16=$1
  ((num=$val_16));
  val=`echo $num`
  local base=$2
  [ $val -eq 0 ] &amp;&amp; bin=0
if [ $val -ge $base ]; then
    dec2bin $val $((base*2))
    if [ $val -ge $base ]; then
      val=$(($val-$base))
      bin=${bin}1
    else
      bin=${bin}0
    fi
  fi
  [ $base -eq 1 ] &amp;&amp; printf  $bin
}

for i in `grep &quot;length:&quot; $1 |awk '{print $1 $3}'`;
do

rdba=`echo ${i:0:10}`
blocks=`echo ${i:10}`
echo -n &quot;rdba:&quot;$rdba&quot;    &quot;

bin2=`dec2bin $rdba  1`

len=`expr length $bin2`
len_gd=22
len_jg=`expr $len - $len_gd`

file_no_2=`echo ${bin2:0:$len_jg}`
((file_no=2#$file_no_2))
echo -n &quot;file_id:&quot;$file_no&quot;    &quot;

block_no_2=`echo ${bin2:$len_jg}`
((block_no=2#$block_no_2))
echo -n &quot;block_id:&quot;$block_no&quot;    &quot;
echo  &quot;blocks:&quot;$blocks

done;
</pre>
<p>trace文件中部分信息</p>
<pre class="brush: bash; title: ; notranslate">
  -----------------------------------------------------------------
   0x00400901  length: 7     
   0x00402e10  length: 8     
   0x00402e60  length: 8     
   0x00402e68  length: 8     
   0x00402ea0  length: 8     
   0x00402f20  length: 8     
   0x00402f48  length: 8     
   0x00403050  length: 8     
   0x00403180  length: 8     
   0x00403b38  length: 8     
   0x00404c48  length: 8     
   0x00404c78  length: 8     
   0x00404cf8  length: 8     
   0x00404da8  length: 8     
   0x00404db8  length: 8     
   0x00404de8  length: 8     
   0x00404e80  length: 128   
   0x00405900  length: 128   
   0x00406500  length: 128   
   0x00406980  length: 128   
   0x00407480  length: 128   
   0x00407500  length: 128   
   0x00407680  length: 128   
   0x00407800  length: 128   
   0x00407880  length: 128   
   0x00407a00  length: 128   
   0x00407a80  length: 128   
   0x00407c80  length: 128   
…………
</pre>
<p>执行结果</p>
<pre class="brush: bash; title: ; notranslate">
[oracle@xifenfei tmp]$ ./get_extent.sh /u01/app/oracle/diag/rdbms/cdb/cdb/trace/cdb_ora_29565.trc
rdba:0x00400901    file_id:1    block_id:2305     blocks:7
rdba:0x00402e10    file_id:1    block_id:11792     blocks:8
rdba:0x00402e60    file_id:1    block_id:11872     blocks:8
rdba:0x00402e68    file_id:1    block_id:11880     blocks:8
rdba:0x00402ea0    file_id:1    block_id:11936     blocks:8
rdba:0x00402f20    file_id:1    block_id:12064     blocks:8
rdba:0x00402f48    file_id:1    block_id:12104     blocks:8
rdba:0x00403050    file_id:1    block_id:12368     blocks:8
rdba:0x00403180    file_id:1    block_id:12672     blocks:8
rdba:0x00403b38    file_id:1    block_id:15160     blocks:8
rdba:0x00404c48    file_id:1    block_id:19528     blocks:8
rdba:0x00404c78    file_id:1    block_id:19576     blocks:8
rdba:0x00404cf8    file_id:1    block_id:19704     blocks:8
rdba:0x00404da8    file_id:1    block_id:19880     blocks:8
rdba:0x00404db8    file_id:1    block_id:19896     blocks:8
rdba:0x00404de8    file_id:1    block_id:19944     blocks:8
rdba:0x00404e80    file_id:1    block_id:20096     blocks:128
rdba:0x00405900    file_id:1    block_id:22784     blocks:128
rdba:0x00406500    file_id:1    block_id:25856     blocks:128
rdba:0x00406980    file_id:1    block_id:27008     blocks:128
rdba:0x00407480    file_id:1    block_id:29824     blocks:128
rdba:0x00407500    file_id:1    block_id:29952     blocks:128
rdba:0x00407680    file_id:1    block_id:30336     blocks:128
rdba:0x00407800    file_id:1    block_id:30720     blocks:128
…………
</pre>
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2019/11/imp-00098-internal-error-impgst2.html" rel="bookmark" class="crp_title">IMP-00098: INTERNAL ERROR: impgst2</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2024/06/os-error-os-23.html" rel="bookmark" class="crp_title">O/S-Error: (OS 23) 数据错误(循环冗余检查)&#8212;故障处理</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2014/09/oracel%e5%9d%8f%e6%9f%a5%e8%af%a2%e5%af%b9%e8%b1%a1%e6%89%b9%e9%87%8f%e8%84%9a%e6%9c%ac.html" rel="bookmark" class="crp_title">ORACEL坏查询对象批量脚本</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/09/bbed_wrap%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%8f%96%e6%95%b0%e6%8d%ae%e5%9d%97%e5%86%85%e5%ae%b9.html" rel="bookmark" class="crp_title">bbed_wrap脚本获取数据块内容</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/03/%e8%ae%b0%e5%bd%95%e4%b8%80%e6%ac%a1ora-60013013%e5%a4%84%e7%90%86%e8%bf%87%e7%a8%8b.html" rel="bookmark" class="crp_title">记录一次ORA-600[13013]处理过程</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2022/04/segment-header-ora-1578.html" rel="bookmark" class="crp_title">segment header异常对象删除处理</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/07/%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%a5ora-00607ora-006004194%e9%94%99%e8%af%af.html" rel="bookmark" class="crp_title">数据库报ORA-00607/ORA-00600[4194]错误</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/04/%e8%ae%b0%e5%bd%95%e4%b8%80%e6%ac%a1ora-00600kdsgrp1%e5%88%86%e6%9e%90.html" rel="bookmark" class="crp_title">记录一次ORA-00600[kdsgrp1]分析</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/09/%e5%81%87%e5%9d%8f%e5%9d%97%e5%bc%95%e8%b5%b7%e6%81%90%e6%85%8c.html" rel="bookmark" class="crp_title">假坏块引起恐慌</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2024/05/truncate-idl_ub1-open-hang.html" rel="bookmark" class="crp_title">truncate IDL_UB1$导致数据库open hang</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/07/read-by-other-session%e7%ad%89%e5%be%85%e4%ba%8b%e4%bb%b6.html" rel="bookmark" class="crp_title">Read by other session等待事件</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2022/08/oracle-recovery-tools-repair-free-corruption-block.html" rel="bookmark" class="crp_title">Oracle Recovery Tools修复空闲坏块</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2013/05/shell%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%be%97extents%e5%88%86%e5%b8%83.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
