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 ...
随机推荐
- JDK1.6官方下载
JDK1.6官方下载_JDK6官方下载地址:http://www.java.net/download/jdk6/6u10/promoted/b32/binaries/jdk-6u10-rc2-bin- ...
- Unity3D 4.x 使用Mecanim实现动画控制
Unity3D 4.x 版本号之后提供了一种新的动画机制Mecanim,尽管眼下还支持之前的Animation.但看到Unity3D 4.3 预览版里Sprite的动画也是基于Animator的,可知 ...
- Service的开启和停止以及生命周期
1.清单文件 <service android:name=".TestService"></service> 2.开启Service Intent inte ...
- 如何查看VS中预设的路径变量
类似"$(VCInstallDir)"之类的变量查询方法为:打开VS命令行提示窗口,输入 Set 命令. VS中“Tool” - “Visual Studio Command Pr ...
- UIViewController加载过程
UIViewController是视图和数据的桥梁,UIViewController是所有controller的基类,ios内置了很多试图控制器,如导航控制器,tableViewController等 ...
- 推荐五个最好的MySQL GUI工具
推荐五个最好的MySQL GUI工具 在本文中,我们会介绍一些最常用的MySQL GUI工具并附上下载链接.希望大家能更好的运用这些工具. AD:网+线下沙龙 | 移动APP模式创新:给你一个做APP ...
- C# c++ 传递函数指针
C#和c++之间相互传递函数指针 在C++和C#之中都有很多callback method,可以相互调用吗,怎么传递,是我表弟的问题. 1.定义c++ dll ,导出方法 // sort.cpp : ...
- MFC网页访问的实现示例
本示例使用MFC 类CInternetSession 建立连接,使用 CHttpFile读取内容. 首先,建立一个MFC对话框项目,界面如下: 1. 添加头文件: #include <afxin ...
- Canvas上绘制几何图形
重要的类自定义View组件要重写View组件的onDraw(Canvase)方法,接下来是在该 Canvas上绘制大量的几何图形,点.直线.弧.圆.椭圆.文字.矩形.多边形.曲线.圆角矩形,等各种形状 ...
- perl eval
eval 表达式: eval 块: eval 在第一种形式,通常称为一个字符串eval EXPR 返回值是被解析的和被执行的作为一个小小的Perl程序. 表达式的值(是它本身决定的在标量上下文环境)是 ...