1 概述
说明:
1. 逻辑结构
(1) 对应关系:'一对多'
(2) 大小关系: 表空间 TableSpace >
段 Segment > 区 Extent > 数据块 Block
2. 物理结构
(1) '数据文件': '系统和用户数据',默认以 'DBF' 为扩展名
(2) '日志文件': '操作记录',默认以 'LOG' 为扩展名
(3) '控制文件': '控制信息',默认以 'CTL' 为扩展名
扩展:Oracle 体系结构详解(存储结构 + 内存结构 + 进程结构)
理解:类似公司架构(董事长 - 部门经理 - 小员工)
2 逻辑存储结构
2.1 表空间 tablespace
表空间分类 | 名称 | 描述 |
---|---|---|
系统表空间 | system | 数据字典 + 程序单元(包、存储过程、函数、触发器) |
辅助表空间 | sysaux | 除上以外的数据字典,用以辅助系统表空间 |
撤销表空间 | undo | dml 操作时的 旧数据 写入 undo 段 |
用户表空间 | users | 默认 |
临时表空间 | temp | 分组、排序、聚合等(操作完成后,自动释放) |
-- 查询表空间,权限由大至小
select * from dba_tablespaces;
select * from user_tablespaces;
2.2 段 segment
段类型 | 名称 | 描述 |
---|---|---|
表 | table | 段名 = 表名 |
表分区 | table partition | 段名 = 表名 and 分区名不为空 |
表子分区 | table subpartition | 段名 = 表名 and 分区名不为空且不同 |
索引 | index | 段名 = 索引名 |
索引分区 | index partition | 段名 = 索引名 and 分区名不为空 |
索引子分区 | index subpartition | 段名 = 索引名 and 分区名不为空且不同 |
聚簇 | cluster | |
lob 段 | lobsegment | 每个 lob 字段都会对应一个 lob 段,可分区 |
lob 分区 | lob partition | |
lob 子分区 | lob subpartition | |
lob 索引 | lobindex | |
回滚段 | rollback | 8i及以前,名称 system |
撤销段 | type2 undo | 9i及以后 |
嵌套表 | nested table |
-- 查询段,权限由大至小
select t.segment_name, t.* from dba_segments t;
select t.segment_name, t.* from user_segments t;
-- 查找 表
select t.table_name, t.* from dba_tab_comments t;
select t.table_name, t.* from all_tab_comments t;
select t.table_name, t.* from user_tab_comments t;
-- 查找 lob 字段
select * from dba_lobs;
select * from dba_lob_partitions;
select * from dba_lob_subpartitions;
2.3 区 extend
-- 查询 区 extend
-- 段空间使用完后,自动为该段分配一个新的 区(扩展)
select * from dba_extents;
select * from user_extents;
2.4 数据块 block
1. 数据块 和 操作系统块
(1) 数据块 : '最小的逻辑单元'
(2) 操作系统块: 读取或写入磁盘的最小单元('I/O')
(3) 数据快 和 操作系统快分离的意义:'屏蔽了不同操作系统的差异'
-- 也就是说,数据库在 Windows 或 Linux 等一样使用
2. 数据块的大小
(1) 数据库创建时设置,之后无法更改,除非重新创建数据库。
(2) 一般默认大小 '8kb'
show parameters db_block_size -- (8192/1024 = 8 kb)
3. 行数据格式(Row Data)
(1) 可通过伪列 rowid 查看,共计 18 位
select rowid, -- 18 位
-- 数据对象id(前 6 位)
dbms_rowid.rowid_object(rowid) object_id,
-- 相对文件id(3 位)
dbms_rowid.rowid_relative_fno(rowid) relative_fno,
-- 数据块id(6 位)
dbms_rowid.rowid_block_number(rowid) block_number,
-- 行id(后 3 位)
dbms_rowid.rowid_row_number(rowid) row_number
from scott.emp;
3 物理存储结构
1. 各文件对应视图查询
(1) '数据文件': select * from v$datafile;
(2) '日志文件': select * from v$logfile;
(3) '控制文件': select * from v$controlfile;
2. 其它文件
(1) 口令文件 Passwrod File:用于存放特权用户及口令文件,如:sys
(2) 跟踪文件 Trace File :用于存放后台进程和服务器进程的跟踪信息
(3) 警告文件 Alert File :存放错误信息
默认安装目录: