Oracle数据库体系结构简介.ppt

Preview:

Citation preview

Oracle 数据库体系结构介绍

Jametong@ dba童家旺

主题列表• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

如何构建客户端连接• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

Oracle 如何执行 Select 语句• 程序如何连接 Oracle

• 基本连接结构图• Oracle如何执行 Select语句

– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

• 客户端提交 SQL• SQL 解析

• 验证 SQL 语句的语法• 通过数据字典验证表与字段的定义 • 取得相应对象的锁 , 确保解析过程 中对象不会发生变更• 检查相应对象的访问权限• 决定最佳的执行计划• 将其保存到 SQL 共享池

• SQL 执行• 数据提取

优化—降低提交到 Oracle 的 SQL数

• 程序如何连接 Oracle• 基本连接结构图

• Oracle 如何执行 Select 语句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

• 客户端提交 SQL

1.使用 Oracle 11g 引入的 Client Result Cache 来提高其性能2.使用 MemCached 来缓存结果集( 推荐 )

优化—正式解析前• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

•SQL 解析• 验证 SQL 语句的语法

1.通过使用客户端的 Statement Cache 来缓存解析后的游标2.通过使用绑定变量来降低解析次数3.通过使用 Oracle 内部Session_cached_cursors 来缓存客户端的游标

优化 - 语义检查阶段• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

• 通过数据字典验证表与字段的定义 • 取得相应对象的锁 , 确保解析过程 中对象不会发生变更• 检查相应对象的访问权限

1.使用 Dictionary Cache 来缓存这部分信息 , 以提高查询的效率

优化 - 生成执行计划阶段• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

• 决定最佳的执行计划

1. 使用 Dictionary Cache 来缓存对象统计信息 , 以提高查询的效率

2. 通过使用绑定变量来降低解析次数

3. 缓存解析后的执行计划4. 使用 SQL Profiles/SPM/Hint 来

指定如何生成执行计划

优化 - 提取阶段• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle 如何执行 DML 语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

数据提取

1.由 Server Process 读取数据块进入 Buffer Cache.2.再将符合条件的记录返回给客户端程序

Oracle 如何执行 DML 语句• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle如何执行 DML语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

执行 DML 的基本步骤• 程序如何连接 Oracle

• 基本连接结构图• Oracle 如何执行 Select 语

句– 客户端提交 SQL– 解析

• 语法检查• 语义检查• 生成执行计划

– 执行– 提取

• Oracle如何执行 DML语句– 分配事务槽– 更新数据

– 更新 Undo– 更新数据块– 写日志– 写数据块

• 先按照基本的 SQL 执行步骤执行

• 事务开始 , 分配事务槽• 更新数据

• 生成 Undo 块的Redo 信息

• 更新 Undo 数据块• 生成数据块的 Undo

信息• 更新数据块

• 在满足 LGWR 相关条件的情况下 Flush Redo Buffer

LGWR Flush 的相关条件1.When the Redo log buffer is 1/3 filled. 2. 1MB Data in the log buffer3.When the timeout occurs (for every 3

seconds) 4.Before the DBWR writes the dirty blocks to

the database files (DBFs). 5.When a transaction commits. 6.Checkpoint

DBWR 写数据文件的相关条件• The Number of dirty buffers reaches to a

threshold value. • When a process scans a specified number of

blocks when scanning for the free buffers and can't find any.

• When timeout occurs (for every 3 seconds). • When a checkpoint occurs.

CKPT 的分类• Full Checkpoint• Thread Checkpoint• File Checkpoint• Object checkpoint• Parallel Query Checkpoint• Incremental Checkpoint• Log Switch Checkpoint

Full Checkpoint• Writes block images to the database for all dirty buffers from

all instances• Statistics updated:

– DBWR checkpoints– DBWR checkpoint buffers written– DBWR thread checkpoint buffers written

• Caused by:– Alter system checkpoint [global]– Alter database begin backup– Alter database close– Shutdown

• Controlfile and datafile headers are updated– CHECKPOINT_CHANGE#

Incremental Checkpoint

• Writes the contents of some dirty buffers to the• database from CKPT-Q• Block images written in SCN order• Checkpoint RBA updated in SGA• Statistics updated:

– DBWR checkpoint buffers written

• Controlfile is updated every 3 seconds by CKPT– Checkpoint progress record

其他 checkpoint 类型介绍• File Checkpoint

– Alter tablespace XXX offline– Alter tablespace XXX begin backup– Alter tablespace XXX read only

• Parallel Query Checkpoint– Parallel Query– Parallel Query component of PDML or PDDL

• Object “Checkpoint”– Drop table XXX– Drop table XXX purge– Truncate table XXX– Drop index XXX

Smon Jobs

在 Instance Recovery 的时候• 回滚任何未回滚的事务• 释放任何未释放的锁

• 在字典管理表空间的情况下 , 合并相邻的空闲空间

• 释放系统内的临时对象 (ctas/create index/index rebuild/index rebuild online)

Pmon Jobs

• Rolling back the disconnected user process's transactions.

• Releasing any locks those are acquired by the disconnected user process.

• Freeing all the resources used by the disconnected user process