oracle x$ tables
前言
如果对动态性能视图(v$_)感兴趣的话,会发现这些视图都是访问的内部结构表(x$开头),也就是常说的fixed tables
。要进一步分析这类表,你首先得了解几个重要的x$表。
- x$kqfta - 关于x$结构的标题信息,名称、大小、字段数量等
- x$kqfvi - 动态性能视图的名称列表
- x$kqfvt - 定义x$kqfvi中各个视图的select语句
- x$kqfdt - 衍生表:在x$kqfta结构中的一些衍生出来的同义词和视图
- x$kqfco - 每个x$kqfta中的表的字段列表
v$fixed_view_definition
这些x$表名称晦涩难懂,不过可以看看哪些动态性能视图用到了这些fixed table,通过v$fixed_view_definition或者v$fixed_table就能查到定义。
1 | SQL> @v V$FIXED_VIEW_DEFINITION |
通过查看v$fixed_view_definition视图的定义发现,V$FIXED_VIEW_DEFINITION
最终是查询的GV$FIXED_VIEW_DEFINITION
视图,而带G开头的视图才是查询的x$表,GV$视图代表的查询RAC环境中的GLOBAL
,而V$视图则表示查询本节点当中的信息。
同理看看v$fixed_table的构成
1 | SQL> @v v$fixed_table |
通过上面的视图构成SQL可以知道,fixed table
其实本质上就是由基础内存结构(x$kqfta),基于这些内存结构构造的视图(x$kqfvi)以及衍生出来的表(x$kqfdt)union all组成。
那么什么是衍生表呢,有两种方式来回答这个问题。第一直接通过查询x$kqfdt,另一种就是找到哪里用到它了,这里是完整的x$kqfdt清单(19.16.0.0)
1 | col KQFDTNAM for a40 |
同一个fixed表衍生出多个不同的fixed表,这里以X$KGLOB
举例,它衍生出11个不同的fixed表,这样做的目的可能在于oracle想表示出:不同的衍生表以相互不兼容的方式代表同一源fixed表的不同组成部分,举一个例子:
1 | SQL_ID cgs3s9kvnt9hz, child number 0 |
查询v$sql视图,执行计划里显示的是查询X$KGLCURSOR_CHILD表。有趣的是X$KGLCURSOR_CHILD
在x$kqfta表中查不到,只能在x$kqfdt中查到
1 | SQL> select * from x$kqfta where KQFTANAM='X$KGLCURSOR_CHILD'; |
X$表索引
除此之外,这个执行计划还有个特别的地方,就是在访问X$KGLCURSOR_CHILD表时,后面还接了一个(ind:2),走了FIXED TABLE FIXED INDEX
的访问路径。要知道x$kglob表是一个表示Library Cache的内存结构,所以这个索引并不是我们理解的传统意义上的索引,仅仅表示Oracle根据谓词判断出有一个特别有效的访问路径,也就是通过filter里的”KGLOBT03”=’123456789’。既然有ind:2了,那么是否还有其他访问路径呢。可以通过视图v$index_fixed_columns
来查看
1 | SQL> select * from v$indexed_fixed_column where table_name = 'X$KGLOB'; |
注意INDEX_NUMBER列表示使用了KGLOBT03字段作为第2索引来访问表,也与执行计划中的ind:2
保持一致。也可以通过其他方式来验证KGLNAHSH字段对应v$sql.hash_value,KGLOBT03字段对应v$sql.sql_id。
1 | select child_number, plan_hash_value, sql_text from V$sql where |
X$表数据从哪来
X$表通常展示内存里的数据,所以无论你什么时候来查询X$表,都是通过访问内存结构然后解析成可读的信息展示出来。
比如要查询V$SESSION视图用到的X$KSUSE表
1 | SQL> SELECT addr, indx, ksuudnam FROM x$ksuse WHERE rownum <= 5; |
查询上面的内存地址是存放在哪个内存区域
1 | SQL> @fcha 00000000A8B13588 |
这个表示X$KSUSE读取的持久化分配的内存空间SGA里的一部分,那试下其他的看看
1 | SQL> select addr,indx from x$kcccp where rownum<=5; |
注意x$kcccp
表读取的是UGA内存,这里就会引出另外一个问题了。有些X$表并不是直接读取内存当中存放的信息,而是通过一些辅助函数。所以当你去查询这些X$表时,会首先来调用一个辅助函数,它会去获取所需的源数据,然后将其拷贝至你的UGA内存区域当中,按照X$表的格式解析和展示出来。如果对访问x$kcccp
表的过程做trace的话,会发现主要是在等待control file sequential read事件(为了获取检查点信息)。
1 | SQL> @snapper stats,gather=w 2 1 964 |
所以访问这个X$表不仅仅只是被动的读取内存结构,其辅助函数首先会为会话分配一些运行时的内存(UGA中的kxsFrame4kPage块),然后拷贝结果到这块内存区域,所以X$数组和偏移量解析代码能够读取并展示给查询引擎。
这里X$表中的ADDR地址信息不一定代表源数据的最终结果,而是在解析过程中被解析的最终数组是什么样子。有时候解析的数据结构就是最终的源数据,有时候辅助函数需要做一些实实在在的工作(比如获取latchs然后遍历完X$KSMSP的链表,或者直接做一些物理读比如上面的读取控制文件信息)。
现在重复查询x$kcccp表
1 | SQL> select addr,indx from x$kcccp where rownum<=5; |
可以看到即使我们查询的是同样的数据,但是每次返回的ADDR都不一样。这并不代表源端的controlfile内存信息重新加载了,这个addr只是表示在执行SQL过程中所使用到的临时SQL游标的内存存放地址,因为这个就是辅助函数最后解析到的内存结构,所以就导致每次执行时得到的地址都不一样。
只要内存地址是在SGA当中,我们就可以说这个ADDR反映的是源数据实际存放的位置。但是当其在UGA或者PGA当中时,这也许只是代表了临时游标的内存地址。
附录
表名 | 描述 |
---|---|
x$activeckpt | active checkpoint |
x$bh | buffer header |
x$ckptbuf | checkpoint buffer (queue) |
x$dbgalertext | debug alert extented |
x$dbglogext | debug log extended |
x$dbgricx, x$dbgrifx, x$dbgrikx, x$dbgripx | debug tables |
x$dbkece | debug kernel error, critical error |
x$dbkefefc | debug kernel error, fatal error flood control |
x$dglparam | data guard logical parameters |
x$diag_alert_ext | diagnostics alert extended |
x$diag_hm_run, x$diag_vhm_run | diagnostics health monitor runs |
x$diag_ips_configuration | diagnostics incident packaging service configuration |
x$dnfs_meta | dNFS metadata |
x$dra_failure | data recovery advisor failures |
x$drm_history, x$drm_history_stats | dynamic remastering history, stats |
x$jskjobq | job scheduling ?, job queue |
x$k2gte, x$k2gte2 | kernel 2-phase commit, global transaction entry |
x$kbrpstat | kernel backup recovery process(?) statistics |
x$kcbbes | kernel cache, buffer ? |
x$kcbbf | kernel cache, buffer buffer_handles |
x$kcbfwait | kernel cache, buffer file wait |
x$kcbkpfs | kernel cache, buffer ckpt prefetch statistics |
x$kcbkwrl | kernel cache, buffer write list |
x$kcbldrhist | kernel cache, buffer load direct read history |
x$kcbobh | kernel cache, buffer, objectqueue buffer header |
x$kcboqh | kernel cache, buffer, object queue header |
x$kcbsw | kernel cache, buffer statistics why |
x$kcbuwhy | kernel cache, buffer why |
x$kcbwbpd | kernel cache, buffer workingset buffer pool descriptor |
x$kcbwds | kernel cache, buffer workingset descriptors |
x$kcbwh | kernel cache, buffer where/why |
x$kcccf | kernel cache, controlfilemanagement control file |
x$kcccp | kernel cache, controlfile checkpoint progress |
x$kccdi | kernel cache, controlfilemanagement database information |
x$kccle | kernel cache, controlfile logfile entry |
x$kccnrs, x$kccrsp | kernel cache, controlfile non-guaranteed restorepoint; kernel cache, controlfile restore point |
x$kcfis* | kernel cache, file intelligent scan |
x$kclcrst | kernel cache, (RAC) lock, consistent read statistics |
x$kclfh | kernel cache, (RAC) lock file hashtable |
x$kclfi | kernel cache, (RAC) lock file index |
x$kclfx | kernel cache, (RAC) lock (element) freelist statistics |
x$kcluh | kernel cache, (RAC) lock undo header |
x$kclui | kernel cache, (RAC) lock undo index |
x$kcmscn | kernel cache, maximum SCN |
x$kcrfstrand | kernel cache, redo file strand |
x$kcrfx | kernel cache, redo file context |
x$kcrrlns | kernel cache, recovery process LNS |
x$kdxst | kernel data, index status |
x$kdxhs | kernel data, index histogram |
x$kewrtb | kernel server (manageability), workload repository tables |
x$kfdat | kernel file, disk allocation table? |
x$kffxp | kernel file, file extent map |
x$kfklib | kernel file, - library |
x$kghlu | kernel generic, heap LRUs |
x$kglcursor | kernel generic, librarycache cursor |
x$kgllk | kernel generic, librarycache lock |
x$kglob | kernel generic, librarycache object |
x$kglpn | kernel generic, librarycache pin |
x$kglrd | kernel generic, librarycache readonly dependency |
x$kglst | kernel generic, librarycache statistics |
x$kgltr | kernel generic, librarycache translation |
x$kgskvft | kernel generic, service, ?? fixed table |
x$kjxm | kernel RAC cross-instance (?) messaging |
x$kjznhangs, x$kjznhangses | kernel RAC diag node hang session |
x$kmgsct | kernel memory, granule scoreboard ? |
x$kmgstfr | kernel memory, granule - transfer |
x$knstmvr | kernel replication, statistics materialized view refresh |
x$kqdpg | kernel query, dictionary PGA |
x$kqfco | kernel query, fixed table columns |
x$kqfdt | kernel query, fixed derived table |
x$kqfp | kernel query, fixed package |
x$kqfsz | kernel query, fixed size (size of fixed objects in current version of Oracle) |
x$kqfta | kernel query, fixed table |
x$kqfvi | kernel query, fixed view |
x$kqlfsqce | kernel query, librarycache fixedtable sql cursor environment |
x$kqrpd | kernel query, rowcache parent definition |
x$kqrsd | kernel query, rowcache subordinate definition |
x$krbmsft | kernel recovery, - search file ? |
x$krcfh, x$krcfde, x$krcfbh, x$krcbit | kernel recovery, changetracking file, header, descriptor, bitmap header, bitmap block |
x$ksbdd | kernel service, background detached (process) definition |
x$ksbsrvdt | kernel service, background server detached (process) |
x$ksbtabact | kernel service, background - action |
x$ksimsi | kernel service, instance management serial (and) instance (numbers) |
x$ksipc_info and x$ksipc_proc_stats | kernel service IPC info and process stats |
x$ksi_reuse_stats | kernel service, instance, reuse stats |
x$ksled, x$kslei, x$ksles | kernel service, lock, event descriptors, events for instance, events for session |
x$kslemap | kernel service, lock, event map |
x$kslhot | kernel service, lock, hot (blocks) |
x$ksllclass | kernel service, lock,, latch class |
x$ksllw | kernel service, lock, latch where |
x$kslpo | kernel service, latch posting |
x$ksmdd | kernel service, memory segmented (array) definition |
x$ksmfs | kernel service, memory fixed SGA |
x$ksmfsv | kernel service, memory fixed SGA variables |
x$ksmhp | kernel service, memory heap |
x$ksmjch, x$ksmjs | kernel service, memory, java chunks, java (pool) statistics |
x$ksmlru | kernel service, memory LRU |
x$ksmls | kernel service, memory large (pool) statistics |
x$ksmmem | kernel service, memory |
x$ksmns | kernel service, memory numa (pool) statistics |
x$ksmpgdst | kernel service, memory PGA detailed statistics |
x$ksmpp | kernel service, memory pga heap |
x$ksmsp | kernel service, memory sga heap |
x$ksmspr | kernel service, memory shared pool reserved |
x$ksmsp_dsnew | kernel service, memory shared pool, - statistics new |
x$ksmsp_nwex | kernel service, memory shared pool ? |
x$ksmss | kernel service, memory sga statistics |
x$ksmsst, x$ksmstrs | kernel service, memory, sga streams (pool), streams (pool) statistics |
x$ksmssinfo | kernel service, memory sga OS (level) info |
x$ksmup | kernel service, memory uga heap |
x$ksolsfts | kernel service, object level statistics, fts? |
x$ksppcv | kernel service, parameter, current (session) value |
x$ksppi | kernel service, parameter, parameter info |
x$ksppsv | kernel service, parameter, system value |
x$kspspfh | kernel service, parameter spfile header |
x$ksrcctx, x$ksrcdes | kernel service, (intra-instance) broadcast, channel context, channel description |
x$ksrchdl | kernel service, (intra-instance) broadcast, channel ? |
x$kstex | kernel service, trace execution |
x$ksulop | kernel service, user long operation |
x$ksulv | kernel service, user locale value |
x$ksupgp, x$ksupgs | kernel service, user, process group, process group sniped |
x$ksupl, x$ksuru | kernel service, user, process (resource) limit, resource usage |
x$ksuprlat | kernel service, user process latch |
x$ksuse | kernel service, user session |
x$ksusecon | kernel service, user session connection |
x$ksusm | kernel service, user session migration |
x$ksuvmstat | kernel service, user virtual memory statistics |
x$kswsastab | kernel service, workgroup services, service table |
x$ksxafa | kernel service, execution, - file affinity |
x$ksxm_dft | kernel service, execution, modification dml frequency tracking |
x$ksxpclient | kernel service, ipc, client |
x$ksxpif | kernel service, ipc, interface |
x$ksxpping | kernel service, ipc, ping |
x$ksxp_stats | kernel service, ipc, stats |
x$ktcn* | kernel transaction, change notification * |
x$ktcxb | kernel transaction, control, transaction object |
x$ktfbfe | kernel tablespace, file bitmap free extent |
x$ktfbhc | kernel tablespace, file bitmap header control |
x$ktfbnstat | kernel tablespace, file bigfile - stat |
x$ktfbue | kernel tablespace, file bitmap used extent |
x$ktifb, x$ktiff, x$ktifp, x$ktifv | kernel transaction, in-memory flush, ? |
x$ktprhist | kernel transaction, parallel (transaction) recovery history |
x$ktsimapool | kernel transaction, - in-memory pool |
x$ktsj* | kernel transaction, space job(?) |
x$ktskstat | kernel transaction/tablespace, segment shrink statistics |
x$ktslchunk | kernel transaction/tablespace, space LOB chunk |
x$ktspstat | kernel tablespace, space statistics |
x$ktsso | kernel transaction, sort segment |
x$ktugd | kernel transaction, undo global data |
x$ktuqqry | kernel transaction, undo - query |
x$kturhist | kernel transaction, undo recovery history |
x$ktusmst | kernel transaction, undo system managed, statistics |
x$ktuxe | kernel transaction, undo transaction entry |
x$kvii, x$kvit | kernel (performance) view, instance, initialization, transitory (parameters) |
x$kwqbpmt | kernel OLTP queue ? |
x$kxdbio_stats, x$kxdcm*, x$kxdrs | kernel Exadata, block (level) intelligent operations stats, callback for metrics, resilvering |
x$kxfbbox | kernel execution, fast (parallel process) black box |
x$kxfpbs | kernel execution, fast (parallel) process batch size |
x$kxfpcds, x$kxfpcms, x$kxfpcst | kernel execution, fast (parallel) process, coordinator, dequeue stats, message stats, (query) stats |
x$kxfpinstload | kernel execution, fast (parallel) process instance load |
x$kxfpsds, x$kxfpsms, x$kxfpsst | kernel execution, fast (parallel) process, slave, dequeue stats, message stats, (query) stats |
x$kxsbd | kernel execution, SQL bind data |
x$kxttstecs, x$kxttstehs, x$kxttsteis, x$kxttstets | kernel execution, temporary table stats, column stats, histograms, index stats, table stats |
x$kywm* | kernel - workload management |
x$kzspr, x$kzsro | kernel security, session, privilege, role |
x$le | lock element |
x$lobsegstat, x$lobstat, x$logstathist | LOB (segment) stats, history |
x$logbuf_readhist | Log buffer read histogram |
x$messages | (background process) messages |
x$modact_length | (sql) module action length (limit) |
x$qesmmiwt | query execution, sql memory management ? |
x$qesmmsga | query execution, sql memory management ? |
x$qksbgses, x$qksbgsys | query compilation service, bug session or system |
x$qksceses, x$qkscesys | query compilation service, compilation environment, session or system |
x$skgxp_connection, x$skgxp_port | OS kernel generic interface IPC, connections, ports |
x$targetrba | target RBA |
x$trace | trace |
x$uganco | user global area, network connection |
x$xplton, x$xpltoo | explain plan sql trace(?) operation name, option |
x$xs_sessions | ? sessions |
x$zasa* | ? |