Basic oracle for developer&beginner
Upcoming SlideShare
Loading in...5
×
 

Basic oracle for developer&beginner

on

  • 3,482 views

 

Statistics

Views

Total Views
3,482
Views on SlideShare
1,299
Embed Views
2,183

Actions

Likes
0
Downloads
69
Comments
0

6 Embeds 2,183

http://www.oracledatabase12g.com 1949
http://www.askmaclean.com 221
http://translate.googleusercontent.com 10
http://xianguo.com 1
http://zhuaxia.com 1
http://www.zhuaxia.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Basic oracle for developer&beginner Basic oracle for developer&beginner Presentation Transcript

  • www.oracledatabase12g.com 刘相兵 (Maclean Liu) [email_address] Basic Oracle For Developer & Beginner
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com About Me
    • Email:liu.maclean@gmail.com
    • Blog:www.oracledatabase12g.com
    • Oracle Certified Database Administrator Master 10g and 11g
    • Over 6 years experience with Oracle DBA technology
    • Over 7 years experience with Linux technology
    • Member Independent Oracle Users Group
    • Member All China Users Group
    • Presents for advanced Oracle topics: RAC, DataGuard, Performance Tuning and Oracle Internal.
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
    • 了解 Oracle 数据库的基本组成和工作原理
    • 最基本的日常管理命令
    • 如何与 DBA 交流
    • 合理设计数据库应用程序
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Oracle?
    • Ed Oates
    • Bob Miner
    • Bruce Scott
    • Larry Ellison
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Oracle?
    • Oracle
    • 首字母大写的” Oracle” 代表” Oracle Corp”(NASDAQ:ORCL) ,表示甲骨文有限公司。甲骨文公司是世界上第三大的的信息管理软件及服务供应商,成立于 1977 年,总部位于美国加州 Redwood shore 。
    • ORACLE
    • 全部大写的” ORACLE” 代表” ORACLE SERVER” ,表示甲骨文数据库服务器。甲骨文数据库是世界上第一个 RDBMS 关系型数据库管理系统软件, RDBMS 的全称是 Relationship Database Management System 。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Oracle?
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Instance
    • 一组后台进程以及系统全局共享区域 (SGA) 构成了实例 Instance
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Background Process
    • 不同的后台进程完成不同的任务
      • ps -ef|grep ora_|grep G10R2
      • oracle 16365 1 0 Jun22 ? 00:00:25 ora_pmon_G10R2
      • oracle 16369 1 0 Jun22 ? 00:00:06 ora_mman_G10R2
      • oracle 16371 1 0 Jun22 ? 00:00:08 ora_dbw0_G10R2
      • oracle 16373 1 0 Jun22 ? 00:00:07 ora_lgwr_G10R2
      • oracle 16375 1 0 Jun22 ? 00:00:50 ora_ckpt_G10R2
      • oracle 16377 1 0 Jun22 ? 00:00:05 ora_smon_G10R2
      • oracle 16379 1 0 Jun22 ? 00:00:00 ora_reco_G10R2
      • oracle 16381 1 0 Jun22 ? 00:01:15 ora_cjq0_G10R2
      • oracle 16383 1 0 Jun22 ? 00:00:09 ora_mmon_G10R2
      • oracle 16385 1 0 Jun22 ? 00:00:05 ora_mmnl_G10R2
      • oracle 16395 1 0 Jun22 ? 00:00:02 ora_arc0_G10R2
      • oracle 16397 1 0 Jun22 ? 00:00:02 ora_qmnc_G10R2
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Background Process
    • Pmon – Process monitor process
    • Smon – System Monitor process
    • Dbwr – Database Writer process
    • Ckpt – Checkpoint process
    • Lgwr – Log writer process
    • Reco – Distributed Transaction recovery process
    • Cjq0 – Check job queue process
    • Mmon – Memory Monitor process for AWR
    • Mmnl – assists MMON process for ASH
    • Qmnc – Used for Streams or Advanced Queue
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Oracle Memory Structure
    • SGA – System Global Area or Shared Global Area
      • 由多个 Pool 组成,如 Shared,Buffer,Streams,Large;
      • 一般来说 SGA 在实例启动时一次性分配,其大小在 10g 自动内存管理中由 SGA_TARGET 控制,在 11g 中默认由 MEMORY_TARGET 参数控制
    • PGA – Program Global Area
      • PGA 程序全局区随需分配,可被回收再用。 PGA 的大小在 10g 中由 PGA_AGGREGATE_TARGET 控制,在 11g 中默认由 MEMORY_TARGET 参数控制
    • Software Code Area
      • 软件代码区存放 Oracle2 进制正文 (TEXT) 镜像,镜像共享使用。一般占用 150MB 左右
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s SGA
    • SGA- System Global Area, 包括 :
      • Shared Pool 共享池
      • DB Buffer Cache 数据库缓冲池
      • Large Pool 大池
      • Java Pool
      • Streams Pool 流池
      • Redo Log Buffer 日志缓冲区
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s SGA
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Database
    • 由多种数据库文件组成:
      • 控制文件 Control files
      • 数据文件 Data Files
      • 临时文件 Temp Files
      • 密码文件 Password Files
      • 参数文件 Server Parameter File SPFILE or Pfile
      • 在线日志文件 Online Redo Logs
      • 归档日志文件 Archived Redo Logs
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Database
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • Basic Unit of database
    • Oracle 数据库的基本单元 :
      • Tablespace
      • DataFiles
      • Segment
      • Extents
      • Blocks
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
      • What’s Tablespace
    • 表空间是逻辑概念,各种对象都存放在表空间上 。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Tablespace?
    • Tablespace( 表空间 )
      • 根据用途分成几种 :
        • Permenent Tablespace 存放数据
        • Undo Tablespace 存放回滚数据
        • Temporary Tablespae 存放临时数据
      • 著名的表空间 :
        • SYSTEM 系统表空间,存放数据字典
        • SYSAUX 系统辅助表空间,存放 AWR 等信息
        • TEMP 默认临时表空间
        • Users 默认的用户表空间
        • Example 安装 Sample schema 的表空间
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
        • Monitoring Tablespace?
    • Tablespace report Script:
    • http://www.oracledatabase12g.com/archives/script-tablespace-report.html
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
        • 10g/11g Auto Advisor
    • DBA_OUTSTANDING_ALERTS
    • DBA_ADVISOR_FINDINGS
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Tablespace - Datafiles
    • 表空间物理上由一个或多个数据文件组成 。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s datafile?
    • Datafile( 数据文件 )
      • 以裸设备、文件、 ASM 三种形式存在
      • 可以设为自动扩展, 8k 的 smallfile 单个数据文件最大为 32G
      • 以 2 进制格式存放, editor 无法编辑,但可以使用 strings 命令来查看
      • 本地管理区间下数据文件由文件头、区间位图和数据区域组成
      • 当发生完全检查点时,数据文件头会被更新
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • Monitoring datafile?
    Datafile Report Script: http://www.oracledatabase12g.com/archives/script-datafile-report.html
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Extent?
    • Extents 区间由多个数据块组成,一个 Extent 总是属于一个表空间的一个数据文件
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Extent?
    • Extents( 区间 )
      • 由数据块组成
      • Segment 以 Extent 为单位分配空间
      • 9i 以后采用本地管理的区间 -Extent Management Local
      • Extents 的大小可以手动或自动指定
        • Uniform size 1M – 统一使用 1M 的 Extent, 对于数据仓库可以使用 64M/128M 大小的 Extent
        • Autoallocate – Oracle 自动分配 Extent 的大小
      • DBA_EXTENTS 视图反应了区间使用状况
      • DBA_FREE_SPACE 视图反应了空闲区间的使用状况
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Oracle Block?
    • 数据块是 Oracle 的最小存储单位,一般为 8K 。实际的数据是存储在数据块中。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Oracle Block
    • Blocks
      • 标准块大小 (standard block size) 在数据库创建时决定,无法修改
      • 可以针对表空间指定非标准大小的数据块,如 4k,16k 。但要求设置 db_nk_cache_size 非默认缓冲池
      • 4k 适合易引发热点的单节点或 RAC OLTP 环境
      • 8k 适合于普通或 mixed 的环境
      • 16k 适合数据仓库 Data Warehouse 环境
      • 影响 Block 存储的参数有 inittrans 、 maxtrans 、 pctfree 、 pctused(MSSM) 、 compress 等。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • What’s Segment
    • 一张非分区表拥有一个对应的 segment ,一棵非分区索引也对应有一个 segment ,一张分区表有许多 segment 。一个 segment 总是位于某个表空间,但可能物理分布在多个数据文件上。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
        • Segment-Extents-Blocks
    • 多个数据块组成了区间,多个区间组成了 segment 。
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
        • Oracle Physical Structure
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Tune your Application
    • 开发人员应当了解数据库
    • 避免做哪些事?
    • 应该做哪些事?
    • 大一统的 SQL 理论
    • CBO 与 RBO
    • 索引的好处与坏处
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Know Your Database
    Many people still take the attitude that developers should be shielded from the database, they cannot take the time to get trained in the database ‐ basically, they should not have to know anything about the database. Why? Well, more than once I’ve heard ?... but Oracle is the most scalable database in the world, my people don’t have to learn about it, it’ll just do that?. It is true; Oracle is the most scalable database in the world. However, I can write bad code that does not scale in Oracle easier then I can write good, scalable code in Oracle. --Tom Ktye
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • DBA vs Developer
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • Design Table Structure
    • 表上的列总数不应超过 150 个,过多的字段会造成链式行等不良效应
    • 如果不能严格遵守范式,至少不要使用表达式列;使用 view 或者 virtual column 代替表达式列
    • 为表设计 spare 列,一劳永逸
    • 没有主键,也没有 Unique 索引?
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
        • Do not column expression
    • A bad table strucutre
    • TAX_RATE ALWAYS 0.1,Pre_tax=funtion(salary), aft_tax=function(salary)
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
        • Do not column expression
    • Column expression cost: more CPU ,physical IO, disk space
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
    • 未雨绸缪,一劳永逸
    • 为二次开发打好基础
    • 减少今后的维护窗口
    • 利用 varchar 数据类型,一般为 varchar2(1000)
    • 减少因添加列造成链式行的可能性
    • Spare column 总数一般为表上列总数的 30%-50%
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
    • Oracle 公司自身的开发风格 :
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com Utilize dbms_application_info package
    • 为应用程序设置模块名,迅速定位性能问题
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • Uniform SQL?
    • 大一统的 SQL 语言,使用工具生成的可以跨数据库运行的 SQL 语句
      • 优点:
      • 易于移植
      • 加速开发
      • 缺点:
      • 开发只占整个应用生命周期的 10%
      • 当应用足够复杂时移植其实是不可行的
      • 无法充分利用数据库的特性
      • 难以修改语句,不灵活
      • 已经被证实无法实现可收缩的应用,特别不适合于大型 OLTP 和 RAC 系统
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • CBO vs RBO
    • RBO : Rule Based Optimizer
      • 在 10g 中被彻底废弃 , 针对分区表等高级对象无法利用 RBO 优化器
      • 基于简单规则的优化器,不适应于日益复杂的数据结构和应用
      • 任何 SQL 新特性将不会被加入到 RBO 中
      • 除去兼容考虑,已经没有任何理由在新系统中采用 RBO 了。老的应用程序应当尽早考虑升级到 CBO ,到 Oracle 12g 中 RBO 很可能彻底消失。
      • 难以调试,不灵活
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • RBO Rules
    • RBO 的规则 :
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • Foolish RBO
    • “ 愚蠢”的 RBO:
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • CBO vs RBO
    • CBO: Cost Based Optimized
    • 基于成本计算的优化器
    • 支持大量 SQL 特性,包括分区表、散列链接、谓词前置等等。
    • CBO 依赖于数据库统计信息,从 10g 开始工作日 22:00 开始统计任务 Gather_stats_job, 统计是有选择的
    • CBO 易于调试定制,灵活便利
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • CBO Problems
    • CBO 的问题在于:
      • 统计信息不准确或过时
      • 不了解硬件的性能特征
      • 不了解当前的工作负载
      • 建立成本模型所作的某些假设不合适
      • 代码中存在 bug
    • 以上均可能造成 CBO 下执行计划讹误
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
            • Perfect Indexes
    • 为哪些列创建索引?
      • 经常充当限制条件的列 :Where COL1=constant
      • 表连接中使用到的列 :FROM TAB1,TAB2 whereTAB1.COL1=TAB2.COL
      • SELECT 字句所选出的列 :SELECT COL1,COL2….
    • 那些列不要索引
      • 经常被更新的列
      • 包含有大量 NULL 值的列
      • 数据分布不均匀的列,列倾斜
      • DISTINCT VALUE NUMBER 很少的列建议创建位图索引
        • Yes or No
        • Ture or False
        • Male or Female
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
      • SQL Tuning Tool dbms_xplan
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com SQL Tuning Tool SQL Developer
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • SQL Tuning Advisor
  • www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com www.oracledatabase12g.com
          • SQL Tuning Advisor