初识Oracle数据字典

以下讲解内容来源于Oracle dba官方ppt

1.什么是数据字典?
数据字典是记录、验证和提供有关当前数据库信息的一些只读表和视图的集合。

在数据库创建期间,oracle服务器在数据文件中创建另外的对象结构:

1)数据字典表(静态数据字典)
2)动态性能表(动态数据字典)

2.数据字典表分类:
1)基表
    a.存储数据库的描述信息
    b.使用CREATE DATABASE命令创建
2)数据字典视图
    a.总结基表信息
    b.数据库创建完毕后运行catalog.sql脚本创建

3.数据字典视图包含以下3中静态视图

1)user_* 该视图存储了关于当前用户所拥有的对象的信息。(即所有在该用户模式下的对象)

2)all_*  该试图存储了当前用户能够访问的对象的信息。(与user_*相比,all_* 并不需要拥有该对象,只需要具有访问该对象的权限即可)

3)dba_*  该视图存储了数据库中所有对象的信息。(前提是当前用户具有访问这些数据库的权限,一般来说必须具有管理员权限)


4.数据字典都包含哪些个信息?
1)数据库逻辑和物理结构
2)对象定义和空间分配情况
3)实体约束
4)用户信息
5)角色信息
6)权限信息
7)审计信息

5.数据字典内容什么时间变化?
当一个DDL语句执行后,oracle服务器会更新相应数据字典内容。

6.动态性能表的来源?
  内存和控制文件

7.常用数据字典介绍:

1)dba_users 记录当前数据库所有用户信息:
SQL> desc dba_users
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 USERNAME                                  NOT NULL VARCHAR2(30)
 USER_ID                                   NOT NULL NUMBER
 PASSWORD                                           VARCHAR2(30)
 ACCOUNT_STATUS                            NOT NULL VARCHAR2(32)
 LOCK_DATE                                          DATE
 EXPIRY_DATE                                        DATE
 DEFAULT_TABLESPACE                        NOT NULL VARCHAR2(30)
 TEMPORARY_TABLESPACE                      NOT NULL VARCHAR2(30)
 CREATED                                   NOT NULL DATE
 PROFILE                                   NOT NULL VARCHAR2(30)
 INITIAL_RSRC_CONSUMER_GROUP                        VARCHAR2(30)
 EXTERNAL_NAME                                      VARCHAR2(4000)

2)user_tables 记录当前用户所属表信息
SQL> select table_name,tablespace_name,num_rows from user_tables;

TABLE_NAME                     TABLESPACE_NAME                  NUM_ROWS
------------------------------ ------------------------------ ----------
DEPT                           USERS                                   4
EMP                            USERS                                  14
BONUS                          USERS                                   0
SALGRADE                       USERS                                   5
DSQL_TEST                      USERS                                   0
TEST                           USERS                                   0 △

已选择6行。

SQL> analyze table test compute statistics;

表已分析。

SQL> select table_name,tablespace_name,num_rows from user_tables;

TABLE_NAME                     TABLESPACE_NAME                  NUM_ROWS
------------------------------ ------------------------------ ----------
DEPT                           USERS                                   4
EMP                            USERS                                  14
BONUS                          USERS                                   0
SALGRADE                       USERS                                   5
DSQL_TEST                      USERS                                   0
TEST                           USERS                                   3 △

已选择6行。

3)v$instance 记录当前实例信息

SQL> desc v$instance
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 INSTANCE_NUMBER                                    NUMBER
 INSTANCE_NAME                                      VARCHAR2(16)
 HOST_NAME                                          VARCHAR2(64)
 VERSION                                            VARCHAR2(17)
 STARTUP_TIME                                       DATE
 STATUS                                             VARCHAR2(12)
 PARALLEL                                           VARCHAR2(3)
 THREAD#                                            NUMBER
 ARCHIVER                                           VARCHAR2(7)
 LOG_SWITCH_WAIT                                    VARCHAR2(15)
 LOGINS                                             VARCHAR2(10)
 SHUTDOWN_PENDING                                   VARCHAR2(3)
 DATABASE_STATUS                                    VARCHAR2(17)
 INSTANCE_ROLE                                      VARCHAR2(18)
 ACTIVE_STATE                                       VARCHAR2(9)
 BLOCKED                                            VARCHAR2(3)

SQL> select instance_name, status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl             OPEN

4)v$datafile 记录数据文件信息
SQL> desc v$datafile
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 FILE#                                              NUMBER
 CREATION_CHANGE#                                   NUMBER
 CREATION_TIME                                      DATE
 TS#                                                NUMBER
 RFILE#                                             NUMBER
 STATUS                                             VARCHAR2(7)
 ENABLED                                            VARCHAR2(10)
 CHECKPOINT_CHANGE#                                 NUMBER
 CHECKPOINT_TIME                                    DATE
 UNRECOVERABLE_CHANGE#                              NUMBER
 UNRECOVERABLE_TIME                                 DATE
 LAST_CHANGE#                                       NUMBER
 LAST_TIME                                          DATE
 OFFLINE_CHANGE#                                    NUMBER
 ONLINE_CHANGE#                                     NUMBER
 ONLINE_TIME                                        DATE
 BYTES                                              NUMBER
 BLOCKS                                             NUMBER
 CREATE_BYTES                                       NUMBER
 BLOCK_SIZE                                         NUMBER
 NAME                                               VARCHAR2(513)
 PLUGGED_IN                                         NUMBER
 BLOCK1_OFFSET                                      NUMBER
 AUX_NAME                                           VARCHAR2(513)
 FIRST_NONLOGGED_SCN                                NUMBER
 FIRST_NONLOGGED_TIME                               DATE

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
E:\ORADATA\ORCL\SYSTEM01.DBF
E:\ORADATA\ORCL\UNDOTBS01.DBF
E:\ORADATA\ORCL\SYSAUX01.DBF
E:\ORADATA\ORCL\USERS01.DBF
E:\ORADATA\ORCL\EXAMPLE01.DBF
E:\ORADATA\NEANDS3.DBF
E:\ORADATA\LPORTAL4.DBF
E:\ORADATA\NEANDS.DBF
E:\ORADATA\NEANDS3_IDX.DBF
E:\ORADATA\NEALPORTAL4.DBF
E:\ORADATA\ULOG.DBF

相关推荐