7 The Data Dictionary
001 |
This chapter describes the central set of read-only reference tables and
views of each Oracle database, known collectively as the data
dictionary. |
本章描述了 Oracle 数据库中一系列重要的只读参考表和视图(read-only reference tables and
views),这些表和视图被统称为数据字典(data
dictionary)。 |
||||||||||||||||||||||||
002 | This chapter contains the following topics: | 本章包含以下主题: | ||||||||||||||||||||||||
003 |
Introduction to the Data Dictionary |
7.1 数据字典简介 |
||||||||||||||||||||||||
004 |
One of the most important parts of an Oracle database is its data
dictionary, which is a read-only set of tables that provides
information about the database. A data dictionary contains:
|
数据字典(data
dictionary)是 Oracle 数据库的一个重要组成部分,这是一组用于记录数据库信息的只读(read-only)表。数据字典中包
含:
|
||||||||||||||||||||||||
005 |
The data dictionary is structured in tables and views, just like other
database data. All the data dictionary tables and views for a given
database are stored in that database's SYSTEM
tablespace. |
与数据库内的其他数据相同,数据字典也是以表及视图的形式组织的。一个数据库全部的数据字典表与数据字典视图都存储在该数据库的
SYSTEM 表空间内。 |
||||||||||||||||||||||||
006 |
Not only is the data dictionary central to every Oracle database, it is
an important tool for all users, from end users to application designers
and database administrators. Use SQL statements to access the data
dictionary. Because the data dictionary is read only, you can issue only
queries (SELECT statements) against it's
tables and views. |
数据字典不仅是 Oracle
数据库的基础组成部分,她也为所有用户--从终端用户,到应用程序设计者,再到数据库管理员--提供了一个重要的工具。数据字典可以通过 SQL
语句进行访问。由于数据字典是只读的,用户只能对这些表和视图执行查询操作(SELECT
语句)。 |
||||||||||||||||||||||||
007 |
|
另见: |
||||||||||||||||||||||||
008 |
Structure of the Data Dictionary |
7.1.1 数据字典的组织结构 |
||||||||||||||||||||||||
009 |
The data dictionary consists of the following: |
数据字典由以下两种结构组成: |
||||||||||||||||||||||||
010 |
Base Tables |
7.1.1.1 基表 |
||||||||||||||||||||||||
011 |
The underlying tables that store information about the associated
database. Only Oracle should write to and read these tables. Users
rarely access them directly because they are normalized, and most of the
data is stored in a cryptic format. |
基表(base table)用于存储相关的数据库信息。只有 Oracle
才能读写这些表。用户很少直接访问她们,因为这些表是规范化的(normalized),且其中的大部分数据的含义是普通用户无法理解的。 |
||||||||||||||||||||||||
012 |
User-Accessible Views |
7.1.1.2 用户访问视图 |
||||||||||||||||||||||||
013 |
The views that summarize and display the information stored in the base
tables of the data dictionary. These views decode the base table data
into useful information, such as user or table names, using joins and
WHERE clauses to simplify the information.
Most users are given access to the views rather than the base tables. |
用户访问视图(user-accessible view)用于对数据字典基表内存储的数据进行汇总与展示。这些视图利用连接(join)及
WHERE
子句简化基表中的数据,将其解码(decode)为用户可理解的信息,例如用户名,表名等。大多数数据库用户只能访问这些视图,而不能访问基表。 |
||||||||||||||||||||||||
014 |
SYS, Owner of the Data Dictionary |
7.1.2 SYS,数据字典的所有者 |
||||||||||||||||||||||||
015 |
The Oracle user SYS owns all base tables
and user-accessible views of the data dictionary. No Oracle user should
ever alter (UPDATE,
DELETE, or INSERT) any rows or
schema objects contained in the SYS schema,
because such activity can compromise data integrity. The security
administrator must keep strict control of this central account. |
Oracle 中的 SYS 用户拥有数据字典中的所有基表(base table)及用户访问视图(user-accessible view)。其他
Oracle 用户不应修改(UPDATE,DELETE,或
INSERT)SYS
方案中的对象定义及数据,否则将危害数据库的数据完整性(data integrity)。安全管理员必须严格控制此账户。 |
||||||||||||||||||||||||
016 |
|
警告: |
||||||||||||||||||||||||
017 |
How the Data Dictionary Is Used |
7.2 如何使用数据字典 |
||||||||||||||||||||||||
018 |
The data dictionary has three primary uses:
|
数据字典有三个主要用途:
|
||||||||||||||||||||||||
019 |
How Oracle Uses the Data Dictionary |
7.2.1 Oracle 如何使用数据字典 |
||||||||||||||||||||||||
020 |
Data in the base tables of the data dictionary is necessary for Oracle
to function. Therefore, only Oracle should write or change data
dictionary information. Oracle provides scripts to modify the data
dictionary tables when a database is upgraded or downgraded. |
数据字典基表(base table)中的数据是 Oracle 正常工作所必须的。因此,只有 Oracle
才能增加或修改数据字典中的信息。当用户对数据库进行升级(upgrade)或降级(downgrade)的操作时,Oracle
提供了修改数据字典表的脚本。 |
||||||||||||||||||||||||
021 |
|
警告: |
||||||||||||||||||||||||
022 |
During database operation, Oracle reads the data dictionary to ascertain
that schema objects exist and that users have proper access to them.
Oracle also updates the data dictionary continuously to reflect changes
in database structures, auditing, grants, and data. |
在数据库运行期间,Oracle 通过数据字典内的信息来确定方案对象(schema
object)是否存在,以及用户是否具备相应的权限。Oracle
会持续地更新数据字典,以便反映数据库在结构,数据,授权,监控(audit)等方面的变化。 |
||||||||||||||||||||||||
023 |
For example, if user Kathy creates a table named
parts, then new rows are added to the data dictionary that
reflect the new table, columns, segment, extents, and the privileges
that Kathy has on the table. This new information is then visible the
next time the dictionary views are queried. |
例如,用户 Kathy 创建了名为
parts 的表,则数据字典中将会增加记录这个新表,及相关列,数据段(segment),数据扩展(extent)的数据,并记录
Kathy 对此表的权限(privilege)信息。当数据字典再次被查询时,用户就能够看到这些信息。 |
||||||||||||||||||||||||
024 |
Public Synonyms for Data Dictionary Views |
7.2.1.1 数据字典视图的公共同义词 |
||||||||||||||||||||||||
025 |
Oracle creates public synonyms for many data dictionary views so users
can access them conveniently. The security administrator can also create
additional public synonyms for schema objects that are used systemwide.
Users should avoid naming their own schema objects with the same names
as those used for public synonyms. |
Oracle 为许多数据字典视图创建了公共同义词(public
synonym),以便用户能够方便地对其进行访问。安全管理员也可以为需要在全系统使用的方案对象(schema
object)创建公共同义词。用户应防止自身的方案对象名与公共同义词名重复。 |
||||||||||||||||||||||||
026 |
Cache the Data Dictionary for Fast Access |
7.2.1.2 缓存数据字典以便加速访问 |
||||||||||||||||||||||||
027 |
Much of the data dictionary information is kept in the SGA in the
dictionary cache, because Oracle constantly accesses the data
dictionary during database operation to validate user access and to
verify the state of schema objects. All information is stored in memory
using the least recently used (LRU) algorithm. |
由于 Oracle 在数据库运行中需要不断地访问数据字典来验证用户权限及方案对象状态,大量的数据字典信息将被缓存到 SGA 的数据字典缓存(dictionary cache)内。这些数据将依据最近最少使用(least
recently used,LRU)算法存储在内存中。 |
||||||||||||||||||||||||
028 |
Parsing information is typically kept in the caches. The
COMMENTS columns describing the tables and
their columns are not cached unless they are accessed frequently. |
解析信息(parsing information)通常会保存在缓存中。而用于描述表及列的 COMMENTS
通常不会被缓存,除非用户使用很频繁。 |
||||||||||||||||||||||||
029 |
Other Programs and the Data Dictionary |
7.2.1.3 其他程序与数据字典 |
||||||||||||||||||||||||
030 |
Other Oracle products can reference existing views and create additional
data dictionary tables or views of their own. Application developers who
write programs that refer to the data dictionary should refer to the
public synonyms rather than the underlying tables: the synonyms are less
likely to change between software releases. |
其他 Oracle 产品可能会引用已有的数据字典视图,并创建其专用数据字典表及视图。Oracle
应用程序开发者在程序中应该引用数据字典的公共同义词(public synonym)而非直接引用基表:因为公共同义词在不同版本的 Oracle
间通常会保持一致。 |
||||||||||||||||||||||||
031 |
How to Use the Data Dictionary |
7.2.2 如何使用数据字典 |
||||||||||||||||||||||||
032 |
The views of the data dictionary serve as a reference for all database
users. Access the data dictionary views with SQL statements. Some views
are accessible to all Oracle users, and others are intended for database
administrators only. |
所有数据库用户都可以参考数据字典视图提供的信息。用户可以使用 SQL 语句来访问数据字典视图。有些视图可以供所有 Oracle
用户使用,而有些只有 DBA 才能访问。 |
||||||||||||||||||||||||
033 |
The data dictionary is always available when the database is open. It
resides in the SYSTEM tablespace, which is
always online. |
只要数据库处于打开(open)状态,用户就可以使用数据字典。因为数据字典存储在 SYSTEM
表空间内,此表空间在数据库被打开后总是联机(online)的。 |
||||||||||||||||||||||||
034 |
The data dictionary consists of sets of views. In many cases, a set
consists of three views containing similar information and
distinguished from each other by their prefixes: |
数据字典视图可以被分为多组。大多数情况下,一组视图由三个包含相似信息的视图构成,其中的区别在于视图名称的前缀: |
||||||||||||||||||||||||
035 |
Table 7-1 Data Dictionary View Prefixes |
表7-1 数据字典视图的前缀 | ||||||||||||||||||||||||
036 |
|
|
||||||||||||||||||||||||
037 |
The set of columns is identical across views, with these exceptions:
|
同一组中各视图所包含的列是完全相同的,但有以下例外:
|
||||||||||||||||||||||||
038 |
See Also: |
另见: |
||||||||||||||||||||||||
039 |
Views with the Prefix USER |
7.2.2.1 以 USER 为前缀的视图 |
||||||||||||||||||||||||
040 |
The views most likely to be of interest to typical database users are
those with the prefix USER. These views:
|
普通数据库用户最常使用是以 USER 为前缀的数据字典视图。这些视图的特点是:
|
||||||||||||||||||||||||
041 |
For example, the following query returns all the objects contained
in your schema:SELECT object_name, object_type FROM USER_OBJECTS; |
例如:以下查询返回当前用户方案内的全部数据库对象:SELECT object_name, object_type FROM USER_OBJECTS; |
||||||||||||||||||||||||
042 |
Views with the Prefix ALL |
7.2.2.2 以 ALL 为前缀的视图 |
||||||||||||||||||||||||
043 |
Views with the prefix ALL refer to the user's overall perspective of
the database. These views return information about schema objects to
which the user has access through public or explicit grants of
privileges and roles, in addition to schema objects that the user
owns. For example, the following query returns information about all
the objects to which you have access:SELECT owner, object_name, object_type FROM ALL_OBJECTS; |
以 ALL
为前缀的视图反映了某个用户所能看到的全部数据库内容。其中除了包含用户所拥有的方案对象之外,还包含了用户可访问的公共对象,以及通过授予(grant)权限
或角色而能够访问的方案对象。以下查询返回当前用户所能访问的全部数据库对象:SELECT owner, object_name, object_type FROM ALL_OBJECTS; |
||||||||||||||||||||||||
044 |
Views with the Prefix DBA |
7.2.2.3 以 DBA 为前缀的视图 |
||||||||||||||||||||||||
045 |
Views with the prefix DBA show a global view of the entire database.
Synonyms are not created for these views, because
DBA views should
be queried only by administrators. Therefore, to query the
DBA
views, administrators must prefix the view name with its owner,
SYS,
as in the following:SELECT owner, object_name, object_type FROM SYS.DBA_OBJECTS; |
以 DBA 为前缀的视图能够展现整个数据库的全部内容。不应在这些视图上创建同义词,因为以 DBA
为前缀的视图只应由管理员查询。因此在查询
DBA
视图时,管理员必须在视图名之前加上其拥有者的前缀
SYS,如下所示:SELECT owner, object_name, object_type FROM SYS.DBA_OBJECTS; |
||||||||||||||||||||||||
046 |
Oracle recommends that you implement data dictionary protection to
prevent users having the ANY system
privileges from using such privileges on the data dictionary. If you
enable dictionary protection (O7_DICTIONARY_ACCESSIBILITY
is false), then access to objects in the SYS
schema (dictionary objects) is restricted to users with the
SYS schema. These users are
SYS and those who connect as
SYSDBA. |
Oracle 建议管理员对数据字典的访问加以控制,防止拥有 ANY
系统权限的用户任意访问数据字典。管理员可以开启数据字典保护(dictionary protection)功能(将 O7_DICTIONARY_ACCESSIBILITY
设为 false),则只有能够访问 SYS
方案的用户才能访问数据字典对象。这样的用户只有 SYS,及以
SYSDBA 登录的用户。 |
||||||||||||||||||||||||
047 |
See Also: |
另见: |
||||||||||||||||||||||||
048 |
The DUAL Table |
7.2.2.4 DUAL 表 |
||||||||||||||||||||||||
049 |
The table named DUAL is a small table in
the data dictionary that Oracle and user-written programs can reference
to guarantee a known result. This table has one column called
DUMMY and one row containing the value
X. |
名为 DUAL 的表是数据字典内的一个小表,Oracle
及用户程序可以使用此表来获得一个确定的值。此表只有一列名为 DUMMY;只有一行数据,值为
X。 |
||||||||||||||||||||||||
050 |
See Also: |
另见: |
||||||||||||||||||||||||
051 |
Dynamic Performance Tables |
7.3 动态性能表 |
||||||||||||||||||||||||
052 |
Throughout its operation, Oracle maintains a set of virtual tables that
record current database activity. These tables are called
dynamic
performance tables. |
在数据库运行过程中,Oracle 将维护一组虚拟表(virtual table)用于记录数据库的当前状态(current database
activity)。这组表被称为动态性能表(dynamic performance table)。 |
||||||||||||||||||||||||
053 |
Dynamic performance tables are not true tables, and they should not be
accessed by most users. However, database administrators can query and
create views on the tables and grant access to those views to other
users. These views are sometimes called
fixed views because they
cannot be altered or removed by the database administrator. |
动态性能表并不是真正的表,大多数用户不应访问其中的信息。但是数据库管理员可以对其进行查询,或在其上创建视图并将访问权限授予其他用户。这些视图有时被称为固定视图(fixed
view),因为数据库管理员不能将其修改或移除。 |
||||||||||||||||||||||||
054 |
SYS owns the dynamic performance tables;
their names all begin with V_$. Views are
created on these tables, and then public synonyms are created for the
views. The synonym names begin with V$. For
example, the V$DATAFILE view contains
information about the database's datafiles, and the
V$FIXED_TABLE view contains information
about all of the dynamic performance tables and views in the database. |
动态性能表由 SYS 用户所拥有;她们的名字都以
V_$ 开头。这些表上创建有视图,而视图上创建有公共同义词。这些公共同义词的名字都以
V$ 开头。例如,V$DATAFILE
视图包含了数据库文件的信息,V$FIXED_TABLE
视图包含了数据库中所有动态性能表及视图的信息。 |
||||||||||||||||||||||||
055 |
See Also: |
另见: |
||||||||||||||||||||||||
056 |
Database Object Metadata |
7.4 数据库对象元数据 |
||||||||||||||||||||||||
057 |
The DBMS_METADATA package provides
interfaces for extracting complete definitions of database objects. The
definitions can be expressed either as XML or as SQL DDL. Two styles of
interface are provided:
|
DBMS_METADATA 包为用户提供了获取数据库对象完整定义的接口。此包可以通过
XML 或 SQL DDL 的形式提供定义信息。此包具备两类接口:
|
||||||||||||||||||||||||
058 |
See Also: |
另见: |
[004] Auditing [052] current database activity [052] dynamic performance tables |
1、什么的 Parsing information? [028] Parsing information is typically kept in the caches. 2、是不是指 dynamic performance table? [053] These views are sometimes called fixed views because they cannot be altered or removed by the database administrator. |