Small rookie of the oracle data dictionary

oracle data dictionary

A data dictionary
  data dictionary is the oracle database to store information about the place, almost all of the system information and object information can be queried in the data dictionary. The data dictionary is the core oracle database information system, which provides information about a set of database tables and a set of views, the views and tables are read-only. With the establishment of the database it is established, the data dictionary is automatically updated when the database to perform a specific action. The data-list with the data dictionary to record, verify and manage the ongoing operation.
the oracle, sys user is the owner of the data dictionary, data dictionary in the system to ensure that all of the database table space system, any user has the right to change the mode or data dictionary objects in the sys schema row. That can only query the data dictionary, can not be modified manually.

  It uses data dictionary
oracle thus more convenient to get information about the objects and the user of something by accessing the data storage structure dictionary. When the system performs a DDL statement, oracle will promptly modify the data dictionary. Any user can only use the data dictionary database to obtain information in the form of reading.

Information stored in the data dictionary

· Name of the user data

· Grant the user permissions and roles

Name-schema objects such as tables, views, indexex, procedures, functions, packages, triggers and so on.

· Specific information integrity constraints;

· The default values ​​for each field;

Use the database space;

· Audit function, in Oracle_Home \ productdb_l \ rdbms \ admin directory files cataudit.sql is used to create the data dictionary views pace for the audit.

• Object and strict management of users (for highly confidential management);

· Other general database information.

  Three kinds prefix data dictionary views
user_: Any user can read the views, not the same for each user to read it only provides the object information in the user's something current. Such as querying all objects in the current mode select object_name, object_type from user_objects;

all_: All users can view the user is read, the object that provides information related to a user. Queries such as the current user can access all objects in
the SELECT owner, object_name, object_type from all_objects;
DBA_: provides a view of the database administrator can only read, including the object information for all user view. The select owner, object_name, object_type from sys.dba_objects ;

Second, the data dictionary related queries

1, user queries

username from the SELECT dba_users ; - Only users with Administrator privileges can query

username from SELECT the all_users ; - or any user can use this

- View the current user's default username table space the SELECT, default_tablespace from USER_USERS ;

- Current User Roles * from the SELECT USER_ROLE_PRIVS ;

- the current user's system privileges and table-level privileges * from the SELECT user_sys_privs ;

select * from user_tab_privs;

2、查询 表空间 (拥有DBA权限的用户才能查询)

select * from dba_data_files;select * from dba_tablespaces; --表空间

select tablespace_name, sum(bytes), sum(blocks) from dba_free_space group by tablespace_name; --空闲表空间

select * from dba_data_files where tablespace_name='USERS'; -- 表空间对于的数据文件

select * from dba_segments where tablespace_name='USERS';--查询用户模式对象所使用过的正在使用空间大小select name, type, source_size, code_size from user_object_size;

3、查询数据库对象(拥有DBA权限的用户才能查询)

select * from dba_objects

select * from dba_objects where object_type = upper('package body');

select * from dba_objects where OBJECT_TYPE='TABLE' and OWNER='SCOTT'

  可根据拥有者查询下列对象类型(object_type)

cluster    databaselink
function   index
library   package
package body   procedure
sequence   synonym
table   trigger
type   undefined
view
4、查询表

--表使用的extent的信息。segment_type='ROLLBACK'

select * from dba_tables;select extent_id, bytes from dba_extents where segment_name='CUSTOMERS' and segment_type='TABLE' order by extent_id;

--    查看回滚段的空间分配信息列信息 SELECT * FROM user_tab_columns;select distinct table_name from user_tab_columns where column_name='ID';

-- 查看当前用户下所有的表select * from user_tables;--查看名称包含log字符的表select object_name, object_id from user_objects where instr(object_name, 'LOG') > 0;-- 查看某表的创建时间select object_name, created from user_objects where object_name = upper('&table_name');-- 查看某表的大小select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name = upper('&table_name');-- 查看放在oracle的内存的表select table_name, cache from user_tables where instr(cache, 'Y') > 0;

5、查询索引

select * from dba_indexes; -- 索引,包括主键索引

select * from all_indexes;select * from dba_ind_columns; -- 索引列

select i.index_name, i.uniqueness, c.column_name from user_indexes i, user_ind_columns c where i.index_name=c.index_name and i.table_name = 'PERSON'; --连接使用

-- 查看索引个数和类别select index_name, index_type, table_name from user_indexes order by table_name;-- 查看索引被索引的字段select * from user_ind_columns where index_name=upper('&index_name');-- 查看索引的大小select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name = upper('&index_name');

6、查询序列

select * from dba_sequences;select * from all_sequences;

查看序列号,last_number是当前值select * from user_sequences;

7、查询视图

select * from dba_views;select * from all_views;

可用目录desc all_views;来查看视图结构
其中,Text列可用于查询视图生产的脚本。

--查询当前用户视图的名称select view_name from user_views;

--查询创建视图的select语句select view_name, text_length from user_views;set long 2000;

--可以根据视图的text_length 值设定set long的大小select text from user_views where view_name = upper('&view_name');

8、查询聚簇

select * from dba_clusters;

9、查询快照

select * from dba_snapshots;

快照、分区应存在相对应的表空间

10、查询同义词

select * from dba_synonyms where table_owner='SCOTT';select * from ALL_synonyms where table_owner='SYSTEM';

  如果用户表可以被访问,那么同义词也可以被访问,用户表不能被访问,则同义词也不能被访问。

11、查询数据库链

select * from dba_db_links;

12、查询触发器(12)

select * from dba_triggers;

存储过程,函数从dba_objects查找

查询文本select text from user_source where name = 'PRO_PERSON_FINDBYID';

oracle总是将存储过程,函数放在system表空间。

13、查看函数和过程的状态

select object_name, status from user_objects where object_type='FUNCTION';select object_name, status from user_objects where object_type='PROCEDURE';

--查看源代码select * from all_source where owner='WUXX' and name=upper('&plsql_name');

14、查询约束

约束是和表关联的,可以在create table或alter table table_name add/drop/modify 来建立、修改、删除约束。
可以临时禁止约束,如:
alter table book_example
disable constraint book_example_l;
数据完整性约束

select constraint_name, constraint_type, table_name from dba_constraints;

15、查询回滚段
在所有的修改结果存入磁盘前,回滚段中保持恢复该事务所需的全部信息,必须以数据库发送的事务来相应确定其大小。(DML语句才可回滚,create, drop, truncate等DDL不能回滚)
回滚段数量=并发事务/4,但不能超过50个;是每个回滚段大小足够处理一个完整的事物;

create rollback segment r05 tablespace rbs;create rollback segment rbs_cvt tablespace rbs storage(initial 1M next 500k);

16、查询作业

select job, broken, next_date, interval, what from user_jobs;select job, broken, next_date, interval, what from dba_jobs;

--正在运行的作业select * from dba_jobs_running;

使用包exec dbms_job.sumit(:v_num, 'a;', sysdate, 'sysdate +(10/(24*60*60))');加入作业。间隔10秒

使用包exec dbms_job.sumit(:v_num, 'a;', sysdate, 'sysdate +(10/(24*60))');加入作业。间隔11分
使用表exec dbms_job.remove(21)删除21号作业。

其他信息查询
查询优化模式对象使用过的或正在使用的空间大小

select name, type, source_size, code_size from user_object_size;

查询字段的默认值

select table_name, column_name, data_default, low_value, hight_value from dba_tab_columns;

Guess you like

Origin www.cnblogs.com/czg-0705/p/11391983.html