oracle 之数据字典屣履造门。
oracle数据字典包括四部分,分别是RDBMS(X$),数据字典表、动态性能视图(v$)和数据字典视图。
1)RDBMS(X$)内部 表:
该部分内容是oracle最低层的表数据,这些表维持着oracle的整个视图,就像我们人体的血液在我们人体流动维持生命一样。
因此这些表只能查看、研究不建议修改。oracle对修改内部表产生的后果不负责技术支持工作。
在查看参数文件的时候我曾经提到x$ksppi和X$ksppcv这两个内部表。
研究内部表:
oracle@oracle:~> sqlplus "/as sysdba"
连接到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
--------------------
READ WRITE
grant select on x$ksppi to xiaohai
*
第 1 行出现错误:
ORA-02030: 只能从固定的表/视图查询
研究内部表方法如下:
SYS@orcl#set autotrace trace explain;
SYS@orcl#select * from v$parameter;
----------------------------------------------------------
Plan hash value: 1128103955
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4414 | 1 (100)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 4414 | 1 (100)| 00:00:01 |
|* 2 | FIXED TABLE FULL|
X$KSPPI | 1 | 249 | 0 (0)| 00:00:01 |
| 3 | FIXED TABLE FULL
| X$KSPPCV | 100 | 406K| 0 (0)| 00:00:01 |
------------------------------------------------------------------------------
---------------------------------------------------
filter(TRANSLATE("KSPPINM",'_','#') NOT LIKE '#%' OR
"KSPPSTDF"='FALSE' OR BITAND("KSPPSTVF",5)>0)
2 - filter("X"."INST_ID"=USERENV('INSTANCE') AND
TRANSLATE("KSPPINM",'_','#') NOT LIKE '##%')
Generates a report on the execution path used by the SQL optimizer and the statement execution statistics. The report is useful to monitor and tune the performance of DML statements.
set autotrace on explain; 生成执行计划并显示查询信息;
set autotrace on statistics;只生成语句的统计信息并显示查询信息。
set autotrace on ; 即生成语句报告有显示语句的执行统计信息和计划
set autotrace traceonly; 和on一样,区别就是不显示查询信息,查询的数据依然会fetch但是不会print,只显示统计信息和执行计划;
eg:
SYS@orcl#set autotrace on explain
SYS@orcl#select * from t2;
---------- --------------------
7521 WARD
执行计划
----------------------------------------------------------
Plan hash value: 1513984157
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T2 | 1 | 20 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
-----
- dynamic sampling used for this statement
SP2-0735: 未知的 SET 选项开头 "statistice..."
SYS@orcl#set autotrace on statistics;
SYS@orcl#select * from t2;
---------- --------------------
7521 WARD
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
600 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SYS@orcl#select * from t2;
---------- --------------------
7521 WARD
执行计划
----------------------------------------------------------
Plan hash value: 1513984157
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T2 | 1 | 20 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
-----
- dynamic sampling used for this statement
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
600 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SYS@orcl#select * from t;
执行计划
----------------------------------------------------------
Plan hash value: 1601196873
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 180 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T | 5 | 180 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
1184 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
便于语句调优。在此记录加深一下印象。呵呵,原来这个工具还有多种花样。
#select kvitval,kvittag,kvitdsc from x$kvit
2 ;
---------- -------------------- --------------------------------------------------------------------------------
1 ksbcpu number of logical CPUs in the system used by Oracle
0 ksbcpucore number of physical CPU cores in the system used by Oracle
0 ksbcpusocket number of physical CPU sockets in the system used by Oracle
1 ksbcpu_hwm high water mark of number of CPUs used by Oracle
0 ksbcpucore_hwm high water mark of number of CPU cores on system
0 ksbcpusocket_hwm high water mark of number of CPU sockets on system
1 ksbcpu_actual number of available CPUs in the system
1 ksbcpu_dr CPU dynamic reconfiguration supported
33456 kcbnbh number of buffers
25 kcbldq large dirty queue if kcbclw reaches this
40 kcbfsp Max percentage of LRU list foreground can scan for free
---------- -------------------- --------------------------------------------------------------------------------
2 kcbcln Initial percentage of LRU list to keep clean
800 kcbnbf number buffer objects
0 kcbwst Flag that indicates recovery or db suspension
0 kcteln Error Log Number for thread open
0 kcvgcw SGA: opcode for checkpoint cross-instance call
0 kcvgcw SGA:opcode for pq checkpoint cross-instance call
kcbldq和kcbfsp是关于dbwr进程进行脏数据写入磁盘的条件。
输入 par 的值: db_large_dirty
------------------------------ -------------------- --------------------------------------------------
_db_large_dirty_queue 25 Number of buffers which force dirty queue to be wr
itten
SYS@orcl#
输入 par 的值: db_block_max_scan
------------------------------ -------------------- --------------------------------------------------
_db_block_max_scan_pct 40 Percentage of buffers to inspect when looking for
free
SYS@orcl#
ORACLE 例程已经启动。
Fixed Size 2148720 bytes
Variable Size 562038416 bytes
Database Buffers 234881024 bytes
Redo Buffers 6807552 bytes
SYS@orcl#show parameter _db_block
------------------------------------ ---------------------- ------------------------------
_db_block_max_scan_pct integer 50
SYS@orcl#exit
从 Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开
oracle@oracle:~/test> sqlplus "/as sysdba"
连
接到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
输入 par 的值: db_block_max_scan
原值 2: where x.indx=y.indx and x.ksppinm like '%&par%'
新值 2: where x.indx=y.indx and x.ksppinm like '%db_block_max_scan%'
------------------------------ -------------------- --------------------------------------------------
_db_block_max_scan_pct 50 Percentage of buffers to inspect when looking for
free
SYS@orcl#
SYS@orcl#alter system reset "_db_block_max_scan_pct";
在创建数据库的时候安装sql.bsp文件进行创建,在数据库启动的时候进行先关字典表的创建。可以通过跟踪数据库启动的过程进行分析。
eg:
startup nomount;
alter session set events '10046 trace nam context level 12';
alter database mount;
alter database open;
如下是截取的跟踪文件信息:
509 CREATE TABLE USER$("USER#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"TYPE#" NUMBER NOT NULL,"PASSWORD" VARCHAR2(30),"DATATS#" NUMBER NOT NULL,"TEMPTS#" NUM BER NOT NULL,"CTIME" DATE NOT NULL,"PTIME" DATE,"EXPTIME" DATE,"LTIME" DATE,"RESOURCE$" NUMBER NOT NULL,"AUDIT$" VARCHAR2(38),"DEFROLE" NUMBER NOT NULL,"DEFGRP #" NUMBER,"DEFGRP_SEQ#" NUMBER,"ASTATUS" NUMBER NOT NULL,"LCOUNT" NUMBER NOT NULL,"DEFSCHCLASS" VARCHAR2(30),"EXT_USERNAME" VARCHAR2(4000),"SPARE1" NUMBER,"SPA RE2" NUMBER,"SPARE3" NUMBER,"SPARE4" VARCHAR2(1000),"SPARE5" VARCHAR2(1000),"SPARE6" DATE) STORAGE ( OBJNO 22 TABNO 1) CLUSTER C_USER#(USER#)
510 END OF STMT
511 PARSE #1:c=0,e=456,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=4,tim=1371736252499680
512 BINDS #1:
513 EXEC #1:c=0,e=217,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1371736252499956
=====================
480 PARSING IN CURSOR #1 len=637 dep=1 uid=0 oct=1 lid=0 tim=1371736252496043 hv=1077251290 ad='8fd93c08' sqlid='3cgdmzx03b36u'
481 CREATE TABLE OBJ$("OBJ#" NUMBER NOT NULL,"DATAOBJ#" NUMBER,"OWNER#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"NAMESPACE" NUMBER NOT NULL,"SUBNAME" VARCHAR2 (30),"TYPE#" NUMBER NOT NULL,"CTIME" DATE NOT NULL,"MTIME" DATE NOT NULL,"STIME" DATE NOT NULL,"STATUS" NUMBER NOT NULL,"REMOTEOWNER" VARCHAR2(30),"LINKNAME" V ARCHAR2(128),"FLAGS" NUMBER,"OID$" RAW(16),"SPARE1" NUMBER,"SPARE2" NUMBER,"SPARE3" NUMBER,"SPARE4" VARCHAR2(1000),"SPARE5" VARCHAR2(1000),"SPARE6" DATE) PCTFR EE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE ( INITIAL 16K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 18 EXTENTS (FILE 1 BLOCK 121) )
482 END OF STMT
483 PARSE #1:c=0,e=552,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=4,tim=1371736252496039
484 BINDS #1:
485 EXEC #1:c=0,e=205,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1371736252496308
当我们创建表的时候,其实是向先关数据字典写入数据,分别是obj$,con$,col$,tab$等等。可以跟踪sql语句进行分析。
当然了我们创建完表之后,可以通过包进行查看我们当时的ddl语句。
eg:
SYS@orcl#select table_name from user_tables where table_name='T';
------------------------------------------------------------
T
--------------------------------------------------------------------------------
( "TABLESPACE_NAME" VARCHAR2(30) NOT NULL ENABLE,
SYS@orcl#SET LONG 20000
SYS@orcl#R
1* select dbms_metadata.get_ddl('TABLE','T') FROM DUAL
--------------------------------------------------------------------------------
( "TABLESPACE_NAME" VARCHAR2(30) NOT NULL ENABLE,
"USERNAME" VARCHAR2(30) NOT NULL ENABLE,
"BYTES" NUMBER,
"MAX_BYTES" NUMBER,
"BLOCKS" NUMBER,
"MAX_BLOCKS" NUMBER,
"DROPPED" VARCHAR2(3)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
--------------------------------------------------------------------------------
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
研究一下这个dbms_metadata包。
Overview
This pkg implements the mdAPI, a means to retrieve the aggregated
definitions of database objects as either XML docs. or their creation DDL,
or to submit the XML documents to execute the DDL.
-------------------------------------------------------------------
SECURITY
This package is owned by SYS with execute access granted to PUBLIC.
It runs with invokers rights, i.e., with the security profile of
the caller. It calls DBMS_METADATA_INT to perform privileged
functions.
The object views defined in catmeta.sql implement the package's security
policy via the WHERE clause on the public views which include syntax to
control user access to metadata: if the current user is SYS or has
SELECT_CATALOG_ROLE, then all objects are visible; otherwise, only
objects in the schema of the current user are visible.
然后我们在看看这个function是get_ddl内容如下:
FUNCTION get_ddl (
object_type IN VARCHAR2,
name IN VARCHAR2,
schema IN VARCHAR2 DEFAULT NULL,
version IN VARCHAR2 DEFAULT 'COMPATIBLE',
model IN VARCHAR2 DEFAULT 'ORACLE',
transform IN VARCHAR2 DEFAULT 'DDL')
RETURN CLOB;
那么我刚刚传的参数是object_type为table,name为T。另外这个包还有很多功能,后续多多实践进行学习。
3)静态数据字典视图。
包括dba_视图,all_视图,user_视图。上级包括下级。如dba_tables,all_tables,user_tables;
eg:
SYS@orcl#set autotrace traceonly explain;
SYS@orcl#select * from dba_tables;
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("T"."BOBJ#"="CO"."OBJ#"(+))
5 - access("CX"."OWNER#"="CU"."USER#"(+))
7 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
8 - access("O"."OWNER#"="U"."USER#")
10 - access("T"."TS#"="TS"."TS#")
12 - access("T"."FILE#"="S"."FILE#"(+) AND "T"."BLOCK#"="S"."BLOCK#"(+) AND
"T"."TS#"="S"."TS#"(+))
13 - access("O"."OBJ#"="T"."OBJ#")
14 - filter(BITAND("T"."PROPERTY",1)=0)
15 - filter(BITAND("O"."FLAGS",128)=0)
20 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
---------------------------------------------------
1 - filter("O"."OWNER#"=USERENV('SCHEMAID') OR EXISTS (SELECT 0 FROM
"SYS"."OBJAUTH$" "OA",SYS."X$KZSRO" "X$KZSRO" WHERE "GRANTEE#"="KZ
SROROL" AND
WHERE
PRV")=(-47) OR
))
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("T"."BOBJ#"="CO"."OBJ#"(+))
5 - access("CX"."OWNER#"="CU"."USER#"(+))
7 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
8 - access("T"."TS#"="TS"."TS#")
10 - access("T"."FILE#"="S"."FILE#"(+) AND "T"."BLOCK#"="S"."BLOCK#"(+) AND
"T"."TS#"="S"."TS#"(+))
12 - filter("O"."OWNER#"=USERENV('SCHEMAID') AND BITAND("O"."FLAGS",128)=0)
13 - filter(BITAND("T"."PROPERTY",1)=0)
14 - access("O"."OBJ#"="T"."OBJ#")
19 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
显而易见了。呵呵。
4)动态视图
明天继续学习。。。。
+++++++++++++++++++++++++++++++++++++++++++↖(^ω^)↗小海¥¥¥¥¥¥¥¥¥¥¥
oracle 之数据字典屣履造门。的更多相关文章
- <Oracle Database>数据字典
数据字典 数据字典是由Oracle服务器创建和维护的一组只读的系统表,它存放了有关数据库和数据库对象的信息,Oracle服务器依赖这些信息来管理和维护Oracle数据库. 数据字典分为两大类:一种是基 ...
- oracle数据库数据字典应用
oracle数据字典 数据字典是由oracle服务器创建和维护的一组只读的系统表.数据字典分为两类:一是基表,二是数据字典视图. 数据字典视图包括用户名.用户权限.对象名.约束和审计等信息,是通过运行 ...
- Oracle——系统数据字典常用命令(查看表所属空间层目录等)
发生背景: 项目前后台交互对接时候,经常存在对底层表蒙圈情况尤其是oracle数据库,所在层级不同会导致操作对象直接的改变,从而发生意向不到的事情:很多时候需要了解我们所操作对象所处的层级等相关信息, ...
- Oracle 通过数据字典查询系统信息
简介:数据字典记录了数据库系统的信息,他是只读表和视图的集合,数据字典的所有者是sys用户.注:用户只能在数据字典上执行查询操作,而维护和修改是由系统自己完成的. 1.数据字典的组成:数据字典包括数据 ...
- Oracle静态数据字典
select * from user_tab_comments a where a.comments like '%操作%' 数据字典 寻找数据库中注释带有“操作”二字的所有表 静态数据字典 这类 ...
- 转://工作中 Oracle 常用数据字典集锦
DBA工作中数据字典就等同于我们本和笔,时时刻刻也分不开的,不管是看状态,还是监控,都需要数据字典的支持,本文整理出来常用的数据字典系列,帮助大家来记住和汇总以便查询利用 ALL_CATALOG Al ...
- oracle 导出数据字典
一.查看当前用户下表名,及表名的备注 select * from user_tab_comments where table_name like 'T_ONLINE%' 二.查询数据字典 -- 1. ...
- Oracle基本数据字典:v$database、v$instance、v$version、dba_objects
v$database: 视图结构: SQL> desc v$database; Name Null? Type - ...
- Oracle常用数据字典
1.查看所有存储过程.索引.表格.PACKAGE.PACKAGE BODY select * from user_objects; 2.查询所有的Job select * from user_jobs ...
随机推荐
- 自己定义progressdialog,改善用户体验
自己定义progressdialog,改善用户体验 效果图: 详细实现方式: 1.定义Dialog的Layout布局 2.设置动画anim 3.创建自己定义dialog的样式 4.创建共同拥有方法来控 ...
- android使用自己定义属性AttributeSet
这里为了演示使用自己定义变量,字体大小改用自己定义的属性. 首先要创建变量,创建了个values/attrs.xml文件,文件名称随意,可是要在values文件夹下: <?xml version ...
- php内存分析
1.一般来说,php倒不需要进行内存分析,但是遇到大循环时内存吃紧时就得要进行内存分析了,看看在哪里吃掉了内存. $m1 = memory_get_usage(); $m2 = memory_get_ ...
- java--内部类实现“类的多重继承”
class Fa1{ private int k = 1; void show() { System.out.println(k); } } class Fa2{ private int k = 10 ...
- Jsp的include指令静态导入和动态导入的区别
1.什么是静态导入? 静态导入指的是,将一个外部文件嵌入到当前JSP文件中,同时解析这个页面的JSP语句,它会把目标页面的其他编译指令也包含进来. include的静态导入指令使用语法: <%@ ...
- ListView 使用方法(Asp.Net)
您将须要用到的独有数据绑定控件. Fritz Onion 代码下载位置: ExtremeASPNET2008_03.exe (192 KB) Browse the Code Online 文件夹 L ...
- FileStream -- 复制文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Notepad++中如何设置自动换行以及行宽
view-->word wrap; setting->preference-->vertical edge settings; Notepad++中如何设置自动换行以及行宽 http ...
- ctfmon.exe开机无法自己主动启动
打开命令提示符(開始菜单--执行--输入:cmd),输入下面命令(复制粘贴就可以): reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Ru ...
- Qt之界面出现、消失动画效果
在学习Qt的这2.3个月里,对Qt越发感兴趣,从刚开始的盲目.无所适从到现在的学习.研究.熟练.掌握的过程中,我学到了很多东西,也学会了如何通过自学让自己更加成熟.强大起来,如何更有效地提高自己学习. ...