首页 > 其他分享 >mount状态下获取undo段名称

mount状态下获取undo段名称

时间:2023-11-10 16:01:32浏览次数:38  
标签:NULL && mount undo 获取 ROWID bbed BLOCK

脚本功能

在某些场景下,数据库启动失败,需要在mount状态下获取Undo段的名称,可以使用以下两种方法来获取。

脚本使用示例

1、直接从system数据文件中获取

直接从system数据文件中过滤,如果system数据文件较大,过滤时间会较长。方法如下:

[oracle@testdb-v2 tmp]$ strings /u01/app/oracle/oradata/testdb/system01.dbf | grep ^_SYSSMU | awk -F'$' '{print $1"$"}' | sort -u
_SYSSMU10_235314541$
_SYSSMU11_2013590764$
_SYSSMU12_2158721311$
_SYSSMU1_3336193855$
_SYSSMU13_3502728648$
_SYSSMU14_4065935650$
_SYSSMU15_2247773548$
_SYSSMU16_784885449$
_SYSSMU2_1849491058$
_SYSSMU3_2454584446$
_SYSSMU4_2145095103$
_SYSSMU5_1329709080$
_SYSSMU6_2221133880$
_SYSSMU7_3984710251$
_SYSSMU8_684059844$
_SYSSMU9_2039187731$

2、使用BBED获取

2.1、获取undo$表所在数据块号

库在open状态可以通过undo$查询undo段的名称。但在mount状态下,该表无法查询。此时在相同版本的数据库中查询,确认undo$在哪个数据块。

SQL> select distinct DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID),DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) from undo$ order by 2 asc;

DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------ ------------------------------------
                                   1                                  225

2.2、执行bbed脚本获取undo段名称

脚本如下:

#!/bin/ksh
# $Id: bbed-wrap.sh,v1.1 2006/05/24 09:44:03 oracle Exp oracle $
# $Author: mmalvezz $
FILE=$1
BLOCK=$2
ORADATATYPE=${3:-"/rn2cntn"}
BBED=$ORACLE_HOME/bin/bbed
PARFILE=$(pwd)/bbed.par
DBA="file   ${FILE}  block  ${BLOCK}"
export DBA ORADATATYPE
PORT=$(uname)
[ $PORT == "Linux" ] && AWK=awk
[ $PORT == "SunOS" ] && AWK=nawk
NUMROWS=$(echo p $DBA kdbh.kdbhnrow| $BBED  parfile=bbed.par | grep kdbhnrow |${AWK} '{print $5}')
[ $NUMROWS -eq 0 ] && exit
echo "There are $NUMROWS rows in block $BLOCK on file $FILE"
Idx=0
while [ $Idx -lt $NUMROWS ]
do
echo x ${ORADATATYPE} $DBA *kdbr[$Idx] | $BBED parfile=bbed.par|${AWK} -F: 'BEGIN {
flag=0;
cnt=0;
}
{ if($1  ~ "cols") numcol=$2; }
# read only rows that are not chained, see kd3.h for details
{
if(($1 ~ "flag") && ($2 ~ "KDRHFL, KDRHFF, KDRHFH" ))
flag=1;
}
{
if(($1 ~ "col" ) && ($1 ~ "\\[") && (flag==1))
{
printf("\x22%s\x22", $2);
if(++cnt < numcol)
printf(",");
}
}
END { printf("\n"); }
'
((Idx+=1))
done

执行脚本,命令如下:

[oracle@testdb-v2 bbed]$ ./bbed_wrap_tmp.sh 1 225 "/rncnnnnnnnnnnnnnnnnncct"

There are 17 rows in block 225 on file 1
" 0 "," SYSTEM"," 0 "," 1 "," 128 "," 0 "," 0 "," 0 "," 0 "," 0 "," 3 "," 0 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 0 "
" 1 "," _SYSSMU1_3336193855$"," 1 "," 3 "," 128 "," 29830822 "," 1 "," 10534 "," 731 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 2 "," _SYSSMU2_1849491058$"," 1 "," 3 "," 144 "," 29830820 "," 1 "," 2761 "," 650 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 3 "," _SYSSMU3_2454584446$"," 1 "," 3 "," 160 "," 29830843 "," 1 "," 2644 "," 764 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 4 "," _SYSSMU4_2145095103$"," 1 "," 3 "," 176 "," 29830935 "," 1 "," 2702 "," 531 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 5 "," _SYSSMU5_1329709080$"," 1 "," 3 "," 192 "," 29830933 "," 1 "," 2729 "," 767 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 6 "," _SYSSMU6_2221133880$"," 1 "," 3 "," 208 "," 29831015 "," 1 "," 3136 "," 1074 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 7 "," _SYSSMU7_3984710251$"," 1 "," 3 "," 224 "," 29831019 "," 1 "," 2731 "," 632 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 8 "," _SYSSMU8_684059844$"," 1 "," 3 "," 240 "," 29830937 "," 1 "," 2762 "," 940 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 9 "," _SYSSMU9_2039187731$"," 1 "," 3 "," 256 "," 29831021 "," 1 "," 2729 "," 756 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 10 "," _SYSSMU10_235314541$"," 1 "," 3 "," 272 "," 29830824 "," 1 "," 2831 "," 618 "," 0 "," 3 "," 2 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 11 "," _SYSSMU11_2013590764$"," 1 "," 5 "," 8 "," 988316 "," 0 "," 31 "," 15 "," 0 "," 2 "," 5 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 12 "," _SYSSMU12_2158721311$"," 1 "," 5 "," 24 "," 988318 "," 0 "," 77 "," 69 "," 0 "," 2 "," 5 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 13 "," _SYSSMU13_3502728648$"," 1 "," 5 "," 40 "," 988310 "," 0 "," 17 "," 10 "," 0 "," 2 "," 5 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 14 "," _SYSSMU14_4065935650$"," 1 "," 6 "," 8 "," 1064730 "," 0 "," 81 "," 65 "," 0 "," 2 "," 6 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 15 "," _SYSSMU15_2247773548$"," 1 "," 6 "," 24 "," 1064606 "," 0 "," 74 "," 80 "," 0 "," 2 "," 6 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "
" 16 "," _SYSSMU16_784885449$"," 1 "," 6 "," 40 "," 1064752 "," 0 "," 104 "," 76 "," 0 "," 2 "," 6 "," *NULL*"," *NULL*"," *NULL*"," *NULL*"," 2 "

脚本说明

./bbed_wrap_tmp.sh 1 225 "/rncnnnnnnnnnnnnnnnnncct"

# 1 225  数据文件号和块编号
# /rncnnnnnnnnnnnnnnnnncct 和undo$列的各个数据类型对应

注意:
如果只写成/rnc,执行该脚本输出内容不能换行,需注意

2.3、批量列类型转换

转换SQL如下:

SQL> select '/r'||replace(wm_concat(ty),',','') from 
  2  (select case data_type when 'NUMBER' then 'n'
  3  when 'DATE' then 't'
  4  else 'c' END  ty from dba_tab_columns where table_name='UNDO$' order by column_id);

'/R'||REPLACE(WM_CONCAT(TY),',','')
--------------------------------------------------------------------------------
/rncnnnnnnnnnnnnnnnnncct

标签:NULL,&&,mount,undo,获取,ROWID,bbed,BLOCK
From: https://blog.51cto.com/u_13482808/8303796

相关文章

  • 获取iphone手机里面app的包名packagename
    首先进入appstore,查找你所要的app其次进入分享此app->拷贝链接,可以发送到社交软件:如网易云app的链接如下:https://apps.apple.com/cn/app/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90-1%E4%BA%BF%E6%AD%A3%E7%89%88%E6%9B%B2%E5%BA%93%E6%9C%89%E5%A3%B0%E5%86%85%E5%AE%B9/i......
  • 使用Python调用API接口获取拼多多商品数据:一篇详细说明文章
    一、引言拼多多是中国著名的电商平台之一,提供了丰富的商品信息和购物服务。为了更好地利用拼多多的数据资源,我们可以使用Python编程语言调用拼多多的API接口,获取商品数据并进行处理和分析。本文将详细介绍如何使用Python完成这一任务,包括API的基本概念、接口调用流程、代码实现和数......
  • 获取当前页面URL信息
    1,设置或获取对象指定的文件名或路径。window.location.pathname结果:/admin/index/index.html2,设置或获取整个URL为字符串。window.location.href结果:http://192.168.1.11/admin/index/news_edit.html?id=4,33,设置或获取与URL关联的端口号码。window.location......
  • java: 执行Linux命令,获取结果
    packagecom.css.k3.k3xk.action;importjava.io.BufferedReader;importjava.io.InputStreamReader;publicclassMyCommandExecutor{publicstaticStringexecuteCommand(Stringcommand,Stringparameter){Stringresult=null;try{......
  • C++中获取数组长度
    #include<iostream>usingnamespacestd;template<classT>intlength(T&arr){//cout<<sizeof(arr[0])<<endl;//cout<<sizeof(arr)<<endl;returnsizeof(arr)/sizeof(arr[0]);}intmain(){i......
  • MySQL 数据库表格创建、数据插入及获取插入的 ID:Python 教程
    创建表格要在MySQL中创建表格,请使用"CREATETABLE"语句。确保在创建连接时定义了数据库的名称。示例创建一个名为"customers"的表格:importmysql.connectormydb=mysql.connector.connect(host="localhost",user="yourusername",password="yourpassword&qu......
  • MySQL 数据库表格创建、数据插入及获取插入的 ID:Python 教程
    创建表格要在MySQL中创建表格,请使用"CREATETABLE"语句。确保在创建连接时定义了数据库的名称。示例创建一个名为"customers"的表格:importmysql.connectormydb=mysql.connector.connect(host="localhost",user="yourusername",password="yourpassword&qu......
  • 递归获取指定目录下的指定类型的文件
     1:递归获取指定目录下的指定类型的文件     public class FileTool    {        /// <summary>        ///  私有变量        ///  </summary>        private static List<FileInfo> lst = new List<FileInfo......
  • 使用命令行工具获取Ubuntu22的公网IP和私有IP
    1.想在互联网冲浪,公网IP是必不可少的(一般是路由器的公网IP)$curlifconfig.me2.私有IP一般是路由器分配的IP,私有IP在局域网内的计算机通信,然后利用路由器的公网IP与互联网上的计算机通信#注意是ifconfig,而不是windows中的dos命令ipconfig$ifconfigor$hostname-I3.为......
  • 获取随机数工具类
    1.通过Random获取随机数由System.Random中提供,它生成的数字被称为伪随机数,它是以相同的概率从一组有限的数字中选取的,所选的数字并不具有完全的随机性,但就实用而言,其随机程度已经足够了。实现思路:Randomr1=newRandom();inta1=r1.Next(1,100); 2.使用Guid生成随机......