首页 > 其他分享 >[20240911]查看超长视图的定义2.txt

[20240911]查看超长视图的定义2.txt

时间:2024-09-12 21:28:44浏览次数:8  
标签:NULL 20240911 number 视图 decode time sql txt id

[20240911]查看超长视图的定义2.txt

--//昨天看了链接:https://www.anbob.com/archives/8295.html,提供了另外的方式获得超长定义试图的长文本。
--//我重复验证看看.

1.环境:
SYS@book> @ver2
==============================
PORT_STRING                   : x86_64/Linux 2.4.xx
VERSION                       : 21.0.0.0.0
BANNER                        : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
BANNER_FULL                   : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
BANNER_LEGACY                 : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
CON_ID                        : 0
PL/SQL procedure successfully completed.

2.测试:
select
 addr,
 to_number(addr,'XXXXXXXXXXXXXXXX') addr_dec,
 to_number(lag(addr,1) over (order by indx),'xxxxxxxxxxxxxxxx') lag_addr_dec,
 to_char(
 to_number(addr,'XXXXXXXXXXXXXXXX') -
 to_number(lag(addr,1) over (order by indx),'xxxxxxxxxxxxxxxx'),
 'xxxxxxxxxxxxxxxx'
 ) row_size_hex,
 to_number(addr,'XXXXXXXXXXXXXXXX') -
 to_number(lag(addr,1) over (order by indx),'xxxxxxxxxxxxxxxx') row_size,
 indx
from x$kqfvt
where indx <= 10
order by 1;

ADDR               ADDR_DEC LAG_ADDR_DEC ROW_SIZE_HEX        ROW_SIZE       INDX
---------------- ---------- ------------ ----------------- ---------- ----------
0000000016BECC00  381602816                                                    0
0000000016BECC20  381602848    381602816                20         32          1
0000000016BECC40  381602880    381602848                20         32          2
0000000016BECC60  381602912    381602880                20         32          3
0000000016BECC80  381602944    381602912                20         32          4
0000000016BECCA0  381602976    381602944                20         32          5
0000000016BECCC0  381603008    381602976                20         32          6
0000000016BECCE0  381603040    381603008                20         32          7
0000000016BECD00  381603072    381603040                20         32          8
0000000016BECD20  381603104    381603072                20         32          9
0000000016BECD40  381603136    381603104                20         32         10
11 rows selected.

--//我的测试版本也许与原作者不同,查看x$kqfvt行的长度,您会发现行长度为32(对方的测试结果40).

SELECT ta.kqftanam, co.kqfconam, co.kqfcodty, co.kqfcotyp, co.kqfcomax,
       co.kqfcolsz, co.kqfcolof, co.kqfcosiz, co.kqfcooff, co.kqfcoidx,
       co.kqfcoipo
  FROM x$kqfta ta, x$kqfco co
 WHERE co.kqfcotab = ta.indx
   AND kqftanam LIKE UPPER('%kqfvt%')
 ORDER BY ta.kqftanam, co.kqfcooff, co.indx;

KQFTANAM   KQFCONAM     KQFCODTY   KQFCOTYP   KQFCOMAX   KQFCOLSZ   KQFCOLOF   KQFCOSIZ   KQFCOOFF   KQFCOIDX   KQFCOIPO
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
X$KQFVT    ADDR               23          9          0          0          0          8          0          1          0
X$KQFVT    INDX                2         11          0          0          0          4          0          2          0
X$KQFVT    INST_ID             2         11          0          0          0          4          0          0          0
X$KQFVT    CON_ID              2         11          0          0          0          2          0          0          0
X$KQFVT    KQFTPSEL            1          6          0          0          0       4000          0          0          0
--//X$KQFVT包含5个字段,可以发现一个细节,实际上占用8+4+4+2+4000 = 4018.而实际上行长仅仅32个字节.
--//也就是不能以普通表方式思考看待X$ fixed table.
--//是否可以这样理解INST_ID,CON_ID 可以通过函数取出,KQFTPSEL通过addr指向的地址取出.

SYS@book> @ xind X$KQFVT
TABLE_NAME                     INDEX_NUMBER COLUMN_NAME                    COLUMN_POSITION     CON_ID
------------------------------ ------------ ------------------------------ --------------- ----------
X$KQFVT                                   1 ADDR                                         0          0
X$KQFVT                                   2 INDX                                         0          0
--//仅仅存在2个索引addr,indr.

SYS@book> select i.addr,t.addr from x$kqfvi i,x$kqfvt t where i.kqfvinam = 'GV$ACTIVE_SESSION_HISTORY' and t.indx = i.indx;
ADDR             ADDR
---------------- ----------------
0000000016BDE4C0 0000000016BF3880

--//sql语句的信息保存在地址0000000016BF3880指向的地址.

SYS@book> oradebug setmypid
Statement processed.

SYS@book> oradebug peek 0x0000000016BF3880 32
[016BF3880, 016BF38A0) = 16E985C0 00000000 16C30640 00000000 00000000 00000000 00000000 00000000
--//sql语句保存在地址0000000016E985C0开始处.受KQFTPSEL varchar2(4000)限制仅仅取出4000字节.

SYS@book> @ fchaz 0000000016BF3880
no rows selected

SYS@book> @ fchaz 16E985C0
no rows selected
--//这些地址不再sga uga等地方,到底在哪里呢?

SYS@book> @ spid
       SID    SERIAL# PROCESS                  SERVER    SPID                               PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------------------------------ ------- ---------- --------------------------------------------------
       288      19200 3795                     DEDICATED 3796                                62          4 alter system kill session '288,19200' immediate;

$ pmap -x 3796 | head -10
3796:   oraclebook (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
Address           Kbytes     RSS   Dirty Mode  Mapping
0000000000400000  422472   37660       0 r-x-- oracle
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
000000001a292000    1540     396       4 r---- oracle
000000001a413000     468      28      24 rw--- oracle
000000001a488000     344     196     196 rw---   [ anon ]
000000001ad7e000     316     284     284 rw---   [ anon ]
0000000060000000   10240       0       0 rw-s- SYSV00000000 (deleted)
0000000060c00000  770048       0       0 rw-s- SYSV00000000 (deleted)
000000008fc00000    8192       0       0 rw-s- SYSV00000000 (deleted)

SYS@book> @ calcx 422472*1024

                                DEC                  HEX
----------------------------------- --------------------
                   432611328.000000 0000000019c92000

SYS@book> @ calc 0x400000 + x0000000019c92000

                                DEC                  HEX
----------------------------------- --------------------
                   436805632.000000             1A092000
                   
--//0x400000 = 4194304
--//4194304+422472*1024 = 436805632
--//4194304+422472*1024 = 0x1a092000

$ echo p/x 0x400000+422472*1024 | gdb -q
(gdb) $1 = 0x1a092000
(gdb) quit

--//很明显在执行文件oracle里面,也就是通过strings抽取文本,可以找到对应的sql文本.
--//我以前通过抽取libserver.a,效果一样的.

$ strings /u01/app/oracle/product/21.0.0/dbhome_1/lib/libserver.a | grep  "x\$kewash.*x\$ash" > cc1.txt
$ strings $(which oracle) |grep "x\$kewash.*x\$ash" > cc2.txt
$ diff cc1.txt cc2.txt
--//结果不再贴出.

3.尝试通过脚本是否可以实现,测试看看:

$ cat ext_sql.sh
#! /bin/bash
tn="${1^^}"
#echo $tn

# sqlplus -s -l / as sysdba << EOF
# set head off verify off feedback off
# select t.addr from x\$kqfvi i,x\$kqfvt t where i.kqfvinam = '$tn' and t.indx = i.indx;
# quit
# EOF

t_addr=$(sqlplus -s -l / as sysdba << EOF
set head off verify off feedback off
select t.addr addr from x\$kqfvi i,x\$kqfvt t where i.kqfvinam = '$tn' and t.indx = i.indx;
quit
EOF
)

t_addr=$(echo $t_addr|tr -d '\n ')
#echo x/s *0x${t_addr}
echo -e "set pagination off\nset print elements 0\n x/s *0x${t_addr}" | gdb -q -p $(pgrep ora_dbw0_${ORACLE_SID}) | grep '^(gdb)'

--//注:x/s 前面有1个*,表示指向地址的指针.没有set print elements 0仅仅取出前面1段文本.

$ . ext_sql.sh 'GV$ACTIVE_SESSION_HISTORy'
(gdb) (gdb) (gdb) 0x16e985c0:   "SELECT  /*+ qb_name(gv_ashv) no_merge ordered use_nl(s,a) */ a.inst_id, s.sample_id, s.sample_time,s.sample_time_utc, a.usecs_per_row, s.is_awr_sample, a.session_id, a.session_serial#, decode(a.session_type, 1, 'FOREGROUND', 'BACKGROUND'), a.flags, a.user_id, a.sql_id, decode(bitand(a.flags, power(2, 4)), NULL, 'N', 0, 'N', 'Y'), a.sql_child_number, a.sql_opcode, a.force_matching_signature, decode(a.top_level_sql_id, NULL, a.sql_id, a.top_level_sql_id), decode(a.top_level_sql_id, NULL, a.sql_opcode,        a.top_level_sql_opcode), a.sql_opname,a.sql_adaptive_plan_resolved,a.sql_full_plan_hash_value,a.sql_plan_hash_value, decode(a.sql_plan_operation, NULL, to_number(NULL),       a.sql_plan_line_id), a.sql_plan_operation, a.sql_plan_options, decode(a.sql_exec_id, 0, to_number(NULL), a.sql_exec_id), a.sql_exec_start, decode(a.plsql_entry_object_id,0,to_number(NULL),       a.plsql_entry_object_id), decode(a.plsql_entry_object_id,0,to_number(NULL),       a.plsql_entry_subprogram_id), decode(a.plsql_object_id,0,to_number(NULL),a.plsql_object_id), decode(a.plsql_object_id,0,to_number(NULL),a.plsql_subprogram_id), decode(a.qc_session_id, 0, to_number(NULL), a.qc_instance_id), decode(a.qc_session_id, 0, to_number(NULL), a.qc_session_id), decode(a.qc_session_id, 0, to_number(NULL), a.qc_session_serial#), decode(a.px_flags, 0, to_number(NULL), a.px_flags), decode(a.wait_time, 0, a.event,    NULL), decode(a.wait_time, 0, a.event_id, NULL), decode(a.wait_time, 0, a.event#,   NULL), a.seq#, a.p1text, a.p1, a.p2text, a.p2, a.p3text, a.p3, decode(a.wait_time, 0, a.wait_class,    NULL), decode(a.wait_time, 0, a.wait_class_id, NULL), a.wait_time, decode(a.wait_time, 0, 'WAITING', 'ON CPU'), a.time_waited, (case when a.blocking_session = 4294967295         then 'UNKNOWN'       when a.blocking_session = 4294967294         then 'GLOBAL'       when a.blocking_session = 4294967293         then 'UNKNOWN'       when a.blocking_session = 4294967292         then 'NO HOLDER'       when a.blocking_session = 4294967291         then 'NOT IN WAIT'       else 'VALID'  end), (case when a.blocking_session between 4294967291 and 4294967295         then to_number(NULL)       else a.blocking_session  end), (case when a.blocking_session between 4294967291 and 4294967295         then to_number(NULL)       else a.blocking_session_serial#  end), (case when a.blocking_session between 4294967291 and 4294967295         then to_number(NULL)       else a.blocking_inst_id  end), (case when a.blocking_session between 4294967291 and 4294967295         then NULL      else decode(bitand(a.flags, power(2, 3)),NULL, 'N', 0,'N','Y')  end), a.current_obj#, a.current_file#, a.current_block#, a.current_row#,a.top_level_call#, a.top_level_call_name, decode(a.consumer_group_id, 0, to_number(NULL), a.consumer_group_id), a.xid, decode(a.remote_instance#, 0, to_number(NULL), a.remote_instance#), a.time_model, a.in_connection_mgmt, a.in_parse, a.in_hard_parse, a.in_sql_execution, a.in_plsql_execution, a.in_plsql_rpc, a.in_plsql_compilation, a.in_java_execution, a.in_bind, a.in_cursor_close, a.in_sequence_load, a.in_inmemory_query, a.in_inmemory_populate, a.in_inmemory_prepopulate, a.in_inmemory_repopulate, a.in_inmemory_trepopulate, a.in_tablespace_encryption, decode(bitand(a.flags, power(2, 5)), NULL, 'N', 0, 'N', 'Y'), decode(bitand(a.flags, power(2, 6)), NULL, 'N', 0, 'N', 'Y'), decode(bitand(a.flags, power(2, 0)), NULL, 'N', 0, 'N', 'Y'), decode(bitand(a.flags, power(2, 2)), NULL, 'N', 0, 'N', 'Y'), decode(bitand(a.flags, power(2, 8)), NULL, 'N', 0, 'N', 'Y'), a.service_hash, a.program, a.module, a.action, a.client_id, a.machine, a.port, a.ecid, a.dbreplay_file_id, a.dbreplay_call_counter, decode(a.tm_delta_time, 0, to_number(null),        a.tm_delta_time), decode(a.tm_delta_time, 0, to_number(null),        a.tm_delta_cpu_time), decode(a.tm_delta_time, 0, to_number(null),        a.tm_delta_db_time), decode(a.delta_time, 0, to_number(null),         a.delta_time), decode(a.delta_time, 0, to_number(null),         a.delta_read_io_requests), decode(a.delta_time, 0, to_number(null),         a.delta_write_io_requests), decode(a.delta_time, 0, to_number(null),         a.delta_read_io_bytes), decode(a.delta_time, 0, to_number(null),         a.delta_write_io_bytes), decode(a.delta_time, 0, to_number(null),         a.delta_interconnect_io_bytes), decode(a.delta_time, 0, to_number(null),         a.delta_read_mem_bytes), decode(a.pga_allocated, 0, to_number(null), a.pga_allocated), decode(a.pga_allocated, 0, to_number(null),         a.temp_space_allocated), a.con_dbid, a.con_id, a.dbop_name, a.dbop_exec_id FROM  x$kewash s, x$ash a WHERE s.sample_addr = a.sample_addr and       s.sample_id   = a.sample_id   and       s.sample_time = a.sample_time and       nlssort(s.need_awr_sample,'nls_sort = binary') =       nlssort(a.need_awr_sample,'nls_sort = binary')"
(gdb) quit

$ . ext_sql.sh 'v$waitstat'
(gdb) (gdb) (gdb) 0x16e31ec0:   "select class,count,time, con_id from gv$waitstat where inst_id = USERENV('Instance') "
(gdb) quit

$ . ext_sql.sh 'v$waitstat'| sed 's/^(gdb).*:\t"//;s/"$//;/quit$/d'
select class,count,time, con_id from gv$waitstat where inst_id = USERENV('Instance')

4.附上xind.sql脚本:

$ cat xind.sql
-- Copyright 2023 lfree. All rights reserved.
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms and conditions.
--------------------------------------------------------------------------------
--
-- File name:   xind.sql
-- Purpose:     query X$ index
-- Author:      lfree
--
-- Usage:
--     @ xind <x$table_name,...>
--     @ xind <x$kglob,x$kgldp>
--------------------------------------------------------------------------------
set termout off
column column_string new_value column_string format a200
select decode('&1','','1=1','1','1=1','1=1','1=1','table_name in ('||''''||replace(upper('&1'),',',''',''')||''')' ) column_string from dual ;
set termout on

select * from V$INDEXED_FIXED_COLUMN where 1=1 and (&column_string);


标签:NULL,20240911,number,视图,decode,time,sql,txt,id
From: https://www.cnblogs.com/lfree/p/18411102

相关文章

  • [20240912]记录使用tnsping遇到的问题.txt
    [20240912]记录使用tnsping遇到的问题.txt--//tnsping用来检测数据库是否连接存在许多局限性,记录自己在使用tnsping遇到的问题.1.环境:--//关闭数据库开启监听.SYS@book>shutdownimmediate;Databaseclosed.Databasedismounted.ORACLEinstanceshutdown.--//服务端监听配置......
  • 探索MySQL视图的无限可能:优化查询、增强数据安全与简化数据访问
     作者简介:我是团团儿,是一名专注于云计算领域的专业创作者,感谢大家的关注 座右铭:   云端筑梦,数据为翼,探索无限可能,引领云计算新纪元 个人主页:团儿.-CSDN博客目录前言:正文:1.视图的定义:2.视图的优点:简单化:安全性:逻辑数据独立性:3.创建单表视图创表:插入数据:创建......
  • Stable Diffusion直接生成IP三视图,一招搞定,不用手绘和建模?(附模型)
    有了这套拆解公式,IP三视图简简单单!**SD生成一个Q版IP三视图模型。**标准的三视图,并且极富设计感,IP设计师的好帮手,用来辅助创意,建模参考。这个模型一般不需堆叠复杂的质量词,直接输入你想要的内容即可,描述越复杂可能效果越不是你想要的。一招搞定,不用手绘和建模?哪怕没有......
  • SortableTableView:Android 表格视图库
    在Android应用开发中,提供用户交云和数据展示的功能是非常重要的。SortableTableView是一个开源的Android库,它提供了一个简单的TableView组件以及一个更高级的可排序TableView,允许开发者实现复杂的表格视图和数据排序功能。文章目录......
  • Mac 上有哪些好用的 txt 纯文本编辑器?
    在Mac上,有很多优秀的纯文本编辑器供用户选择,这些编辑器不仅功能强大,而且界面友好,非常适合编写代码、管理笔记或是进行简单的文本处理。如果你想找一款第三方txt纯文本编辑器,用来代替默认的「文本编辑」,可以看看下面这三个。UltraEditUltraEdit自称是「Mac上最好的文本......
  • 20240911 模拟赛总结
    期望得分:100+0+30=130实际得分:100+20+30=150T1感觉没有大样例也还是可以猜到那么一点的结论。k=0无解。当k≠0时,考虑交换不含1的两项,一定能使这两个位置都符合gcd(i,ai)=1,如果最后长度为奇数剩一个位置出来怎么办?那就O(n)枚举一遍找到可行的位置和它换一下即可,易......
  • 麒麟操作系统的多任务视图工作模式
    麒麟操作系统可以通过建立多个任务视图,使多个工作同时进行,好比同时有多个电脑在工作。开启多任务视图工作模式如下操作:1.鼠标左键单击任务栏左下角“显示任务视图”按钮,如图1。图12.如图2,现有的任务视图就是下方的“工作区1”,还可以点击“新建工作区”按钮添加新的工作区。......
  • Django视图
    一、视图是什么视图函数,接受Web请求并且返回Web响应二、常用的request属性1、GET项目index.py添加方法:defrequest_get(request):#get():返回字符串,如果该键对应有多个值,取出该键的最后一个值#getlist():返回列表,如果该键对应有多个值,取出所有值......
  • VSCode 常用快捷键总结:涵盖编辑器操作、文件管理、查找替换、代码格式化、调试、视图
    编辑器操作光标与选择Ctrl+D:匹配当前选中的词汇或行,再次选中可操作。Alt+Click:在多个位置插入光标。Ctrl+Alt+↑/↓:在上下行插入光标。Shift+Alt+I:在选中范围内所有行结束符插入光标。Shift+Alt+(dragmouse):鼠标拖动区域,同时在多个行结束符插入光标。Ct......
  • 第四章 视图(views)
    4.视图4.1文件or文件夹4.2相对和绝对导入urls注意实现:不要再项目根目录做相对导入。原则:绝对导入相对导入(层级深)4.3视图参数urlpatterns=[path('login/',account.login,name="login"),path('auth/',order.auth,name='auth'),]fromdjango.sho......