2013年4月27日 星期六

10:38

1oracle 存储架构:

1)  database  ------------tablespace-------------segment(对象) ------------extent----------data block

tablespace------------  datafiles ----------------------------------data block

2oralce segment(段对象) 的类型

1) table segment ---------建立table时,表有记在存储数据时,记录在写入数据块时候,是 随机的无序的,访问采用全表扫描。

2) partition table--------对大的table(>2G) 进行分区,减少资源竞争,提高访问速度。

3) cluster(簇) -------------------用于优化表与表的连接查询(用于表与表之间主外键连接查询,加快读取速度)

4) index-------------------提高表的访问速度

5) index organized table(IOT) -------------用于以主键方式建立索引的表,将表中的数据和索引表的数据放在一起 提高访问速度。

 3、存储空间分配:以extent 为最小单位(extent data block 组成)

 data block

oracle 10g 标准块:8k,支持2~32k

有block header 、free space 、data 组成

数据块并发访问:由数据块的事务槽来分配

initrans :初始化事务槽的个数(1·255) ,表默认1,index 默认为2;

maxtrans: 最大的事务槽个数 (默认255)

pctfree:预留给update 操作的空间,free space 大于pctfree 可以insert,小于,不允许insert

 、数据块的free space 管理

1) 手动:在数据字典上建立free list

2) 自动:在本地管理的表空间,通过bitmap来管理data block 的free space(oracle 10g 默认,除了临时、undo表空间)

SYS @ prod >select tablespace_name,contents ,extent_management  “ext_man”,segment_space_management “seg_man”   from dba_tablespaces;

 

TABLESPACE_NAME            CONTENTS       EXT_MAN      SEG_MAN

--------------------------------------- ---------- ----------------------------------------

SYSTEM                               PERMANENT         LOCAL      MANUAL

UNDOTBS1                               UNDO               LOCAL      MANUAL

SYSAUX                               PERMANENT          LOCAL      AUTO

TEMP                                  TEMPORARY           LOCAL      MANUAL

USERS                                 PERMANENT          LOCAL      AUTO

TEST                                    PERMANENT          LOCAL      AUTO

6、建立对象的存储信息:

SQL> create table test (id int)  tablespace users;

SQL> insert into test values (1) ;

SQL> insert into test values (2) ;

SQL> insert into test values (3) ;

SQL> commit;

SYS@ prod>desc  user_segments;

Name                                                              Null?    Type

----------------------------------------------------------------- -------- --------------------------------------------

SEGMENT_NAME                                                               VARCHAR2(81)

PARTITION_NAME                                                             VARCHAR2(30)

SEGMENT_TYPE                                                               VARCHAR2(18)

TABLESPACE_NAME                                                            VARCHAR2(30)

BYTES                                                                      NUMBER

BLOCKS                                                                     NUMBER

EXTENTS                                                                    NUMBER

INITIAL_EXTENT                                                             NUMBER

NEXT_EXTENT                                                                NUMBER

MIN_EXTENTS                                                                NUMBER

MAX_EXTENTS                                                                NUMBER

PCT_INCREASE                                                               NUMBER

FREELISTS                                                                  NUMBER

FREELIST_GROUPS                                                            NUMBER

BUFFER_POOL                                                                VARCHAR2(7)

SYS@ prod>select SEGMENT_NAME,SEGMENT_TYPE ,TABLESPACE_NAME,bytes/1024/1024,BLOCKS,extents ,initial_extent/1024/1024 from user_segments  where        segment_name='TEST';

SEGMENT_NAME    SEGMENT_TYPE       TABLESPACE     BYTES/1024/1024     BLOCKS    EXTENTS    INITIAL_EXTENT/1024/1024

--------------- ------------------ ---------- --------------- ---------- ---------- -------------------------- -------------------------- ------------------------

TEST                         TABLE                      USERS                      .0625                       8                1                        .0625

SQL> select  TABLESPACE_NAME ,INITIAL_EXTENT/1024/1024 ,NEXT_EXTENT/1024/1024, EXTENT_MANAGEMENT from dba_tablespaces     where TABLESPACE_NAME='USERS';

TABLESPACE_NAME        INITIAL_EXTENT/1024/1024         NEXT_EXTENT/1024/1024       EXTENT_MANAGEME

------------------------------------------------------------------------------------------------------------------------------------------

USERS                             .0625                                                                                                   LOCAL

-----------建立对象如果没有指定存储参数,则继承tablespace 的存储参数,test表分配了一个区,大小为4m

SQL> select segment_name,segment_type,TABLESPACE_NAME,EXTENT_ID,bytes/1024/1024,blocks from user_extents  where segment_name='TEST';

SEGMENT_NAME         SEGMENT_TYPE       TABLESPACE_NAME                 EXTENT_ID     BYTES/1024/1024     BLOCKS

-------------------- ------------------ ------------------------------ ---------- --------------- --------------------- --------------------- ----------

TEST                                        TABLE                            USERS                                      0                              4                        512

--------------EXTENT_ID 为extent的id号,从0 开始

SQL> select table_name, TABLESPACE_NAME ,PCT_FREE,INI_TRANS ,MAX_TRANS,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from user_tables   where table_name='TEST';

TABLE_NAME                     TABLESPACE_NAME          PCT_FREE      INI_TRANS     MAX_TRANS   NUM_ROWS     BLOCKS EMPTY_BLOCKS

------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------

TEST                                   USERS                                    10               1                          255

SQL> analyze table test compute statistics;

Table analyzed.

----------对test 表进行分析,oracle通过分析的信息来建立计划进行优化

SQL> select table_name, TABLESPACE_NAME ,PCT_FREE,INI_TRANS ,MAX_TRANS,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from user_tables

where table_name='TEST';

TABLE_NAME                     TABLESPACE_NAME            PCT_FREE       INI_TRANS     MAX_TRANS     NUM_ROWS      BLOCKS      EMPTY_BLOCKS

------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------------- ---------- ------------

TEST                                          USERS                                   10                1                          255                       3                           54                458

---------------blocks 代表已经使用过的块,empty_blocks 代表从未使用过的块

HWM :High water Market 高水位线,在segment用来区分已经使用的块和从未使用的块(在做全表扫描时,会一直扫描到HWM)

SQL> begin

for i in 4..100000 loop

insert into test values (i) ;

end loop;

end;

/

SQL> analyze table test compute statistics;

Table analyzed.

SQL> select table_name, TABLESPACE_NAME ,PCT_FREE,INI_TRANS ,MAX_TRANS,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from user_tables

where table_name='TEST';

TABLE_NAME       TABLESPACE_NAME        PCT_FREE     INI_TRANS  MAX_TRANS   NUM_ROWS     BLOCKS      EMPTY_BLOCKS

------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ---------------------- ---------------------- ------------

TEST                              USERS                                  10                 1                   255                   100000                182             330

建立autotrace ,跟踪sql语句

SQL> conn /as sysdba

Connected.

SQL> @?/rdbms/admin/catplan.sql;

创建PLUSTRACE 角色

SQL>    conn /as sysdba

SQL>   @ ?/sqlplus/admin/plustrce.sql

SQL>   grant plustrace to public

源文档 <http://www.itpub.net/forum.php?mod=viewthread&tid=1747729>

set autotrace on 打开自动跟踪

set autotrace off 关闭自动跟踪

set autotrace traceonly 只显示trace 信息,不显示对象的记录信息

------------对test 做全表扫描

SQL> set autotrace traceonly;

SQL> select * from test;

Execution Plan

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU) | Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      |   100K|   390K|    49  (15) | 00:00:01 |

|   1 |  TABLE ACCESS FULL| TEST |   100K|   390K|    49  (15) | 00:00:01 |

--------------------------------------------------------------------------

Statistics

----------------------------------------------------------

1  recursive calls

0  db block gets

6851  consistent gets

0  physical reads

0  redo size

1855907  bytes sent via SQL*Net to client

73710  bytes received via SQL*Net from client

6668  SQL*Net roundtrips to/from client

0  sorts (memory)

0  sorts (disk)

100000  rows processed

SQL> delete from test;

delete from test

*

ERROR at line 1:

ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDO_TBS01'

---------undo 表空间太小,不能 auto extend

SQL> /

FILE_NAME                                             FILE_ID TABLESPACE_NAME

-------------------------------------------------- ---------- ------------------------------

/u01/app/oracle/oradata/lx02/system01.dbf                   1 SYSTEM

/u01/app/oracle/oradata/lx02/lx02.dbf                      11 LX02

/u01/app/oracle/oradata/lx02/OLTP01.DBF                     7 OLTP

/u01/app/oracle/oradata/lx02/indx01.dbf                     6 INDX

/u01/app/oracle/oradata/lx02/example01.dbf                  5 EXAMPLE

/u01/app/oracle/oradata/lx02/user01.dbf                     4 USERS

/u01/app/oracle/oradata/lx02/sysaux01.dbf                   3 SYSAUX

/u01/app/oracle/oradata/lx02/rtbs01.dbf                     2 RTBS

/u01/app/oracle/oradata/lx02/test01.dbf                     8 TEST

/u01/app/oracle/oradata/tbs16k01.dbf                        9 TBS_16K

/u01/app/oracle/oradata/lx02/lx01.dbf                      10 LX01

/u01/app/oracle/oradata/lx02/undotbs01.dbf                 12 UNDO_TBS01

/u01/app/oracle/oradata/lx02/test02.dbf                    13 TEST

/u01/app/oracle/oradata/bigtbs01.dbf                       14 BIG_TBS

SQL> alter database datafile 12 autoextend on next 10m maxsize 500m;

Database altered.

-----------undo tablespace自动扩展

SQL> delete from test;

100000 rows deleted.

SQL> set autotrace off

SQL>  select table_name, TABLESPACE_NAME ,PCT_FREE,INI_TRANS ,MAX_TRANS,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from user_tables

where table_name='TEST';

TABLE_NAME                     TABLESPACE_NAME                  PCT_FREE  INI_TRANS  MAX_TRANS   NUM_ROWS     BLOCKS      EMPTY_BLOCKS

------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------- ---------- ---------- ------------- ----------

TEST                                                 USERS                                      10                 1                   255                    0                           182             330

----------delete       删除数据    不会重置高水位       没有释放占用的数据块

               Truncate  删除数据   并且重置高水位        释放占用的数据块】

SQL> insert into test values (1) ;

SQL> insert into test values (2) ;

SQL> commit;

SQL> set autotrace on;

SQL> select * from test;

ID

----------

1

2

Execution Plan

----------------------------------------------------------

Execution Plan

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU) | Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      |     2 |    26 |     2   (0) | 00:00:01 |

|   1 |  TABLE ACCESS FULL| TEST |     2 |    26 |     2   (0) | 00:00:01 |

--------------------------------------------------------------------------

Note

-----

- dynamic sampling used for this statement

Statistics

----------------------------------------------------------

28  recursive calls

0  db block gets

10  consistent gets

0  physical reads

0  redo size

451  bytes sent via SQL*Net to client

385  bytes received via SQL*Net from client

2  SQL*Net roundtrips to/from client

0  sorts (memory)

0  sorts (disk)

2  rows processed

---------delete 不释放已经使用的块,所以两行记录在做全表扫描的时候也要访问所有已经使用过的块(扫描到HWM)

SQL> set autotrace off

SQL> truncate table test;

Table truncated.

SQL> analyze table test compute statistics;

SQL>  select table_name, TABLESPACE_NAME ,PCT_FREE,INI_TRANS ,MAX_TRANS,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from user_tables

where table_name='TEST';

TABLE_NAME                     TABLESPACE_NAME                  PCT_FREE  INI_TRANS  MAX_TRANS   NUM_ROWS     BLOCKS    EMPTY_BLOCKS

------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------ ---------- ---------- ---------- ------------

TEST                                           USERS                                          10                1                    255                       0                       0                   512

SQL> insert into test values (1) ;

SQL> insert into test values (2) ;

SQL> commit;

SQL> analyze table test compute statistics;

Table analyzed.

SQL> select table_name, TABLESPACE_NAME ,PCT_FREE,INI_TRANS ,MAX_TRANS,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from user_tables

where table_name='TEST';

TABLE_NAME                     TABLESPACE_NAME                  PCT_FREE  INI_TRANS  MAX_TRANS   NUM_ROWS     BLOCKS    EMPTY_BLOCKS

------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------------- ---------- ---------- ------------

TEST                                               USERS                                      10                 1                   255                       2                      54               458

SQL> set autotrace on

SQL> select * from test;

ID

----------

1

2

Execution Plan

----------------------------------------------------------

Plan hash value: 1357081020

--------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU) | Time     |

--------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      |     2 |     4 |     2   (0) | 00:00:01 |

|   1 |  TABLE ACCESS FULL| TEST |     2 |     4 |     2   (0) | 00:00:01 |

--------------------------------------------------------------------------

Statistics

----------------------------------------------------------

1  recursive calls

0  db block gets

4  consistent gets

0  physical reads

0  redo size

451  bytes sent via SQL*Net to client

385  bytes received via SQL*Net from client

2  SQL*Net roundtrips to/from client

0  sorts (memory)

0  sorts (disk)

2  rows processed

------------【truncate操作会释放 该对象的存储空间的高水位线】

SQL> create table t01 (id int)

    pctfree 20 pctused 40 initrans 3

   storage( initial 128k next 1m pctincrease 50) ;

Table created.

SQL> select table_name,TABLESPACE_NAME,PCT_FREE,PCT_USED ,INI_TRANS,INITIAL_EXTENT/1024,NEXT_EXTENT/1024/1024,PCT_INCREASE from user_tables

where table_name='T01';

TABLE_NAME                     TABLESPACE_NAME                  PCT_FREE   PCT_USED  INI_TRANS     INITIAL_EXTENT/1024      NEXT_EXTENT/1024/1024 PCT_INCREASE

------------------------------ ------------------------------ ---------- ---------- ---------- ------------------- --------------------- --------------------------------- -----------------T01                                                 USERS                                      20                     3                 128                     4                                            0

---------在local 管理的表空间上,存储参数设置意义不大

SQL> select owner, SEGMENT_NAME,TABLESPACE_NAME, BYTES   from dba_segments

where owner='SCOTT';

OWNER                          SEGMENT_NAME         TABLESPACE_NAME                     BYTES

------------------------------ -------------------- ------------------------------ ----------

SCOTT                                   DEPT                                 USERS                             4194304

SCOTT                               PK_DEPT                               USERS                             4194304

SCOTT                          EMP                  USERS                             4194304

SCOTT                          PK_EMP               USERS                             4194304

SCOTT                          BONUS                USERS                             4194304

SCOTT                          SALGRADE             USERS                             4194304

SCOTT                          TEST                 USERS                             4194304

SCOTT                          T01                  USERS                             4194304

8 rows selected.

delete       删除数据    不会重置高水位   不会释放占用的数据块                        Truncate  删除数据   并且重置高水位  释放占用的数据块】

Execution Plan                                                                                                                                                   Execution Plan

----------------------------------------------------------                                                                                       ----------------------------------------------------------

Plan hash value: 1357081020                                                                                                                         Plan hash value: 1357081020

--------------------------------------------------------------------------                                          --------------------------------------------------------------------------

| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |                        | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------                                         --------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |      |     1 |    13 |    43   (3)| 00:00:01 |                              |   0 | SELECT STATEMENT  |      |     1 |    13 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS FULL| TEST |     1 |    13 |    43   (3)| 00:00:01 |                           |   1 |  TABLE ACCESS FULL| TEST |     1 |    13 |     2   (0)| 00:00:01 |

--------------------------------------------------------------------------                                       --------------------------------------------------------------------------

Execution Plan                                                                                                                                     Execution Plan

----------------------------------------------------------                                                               ----------------------------------------------------------

Plan hash value: 1357081020                                                                                                  Plan hash value: 1357081020

Statistics                                                                                                                                           Statistics

----------------------------------------------------------                                                                ----------------------------------------------------------

1 recursive calls                                                                                                                             1  recursive calls

0  db block gets                                                                                                                     0  db block gets

185  consistent gets                                                                                                               22  consistent gets

0  physical reads                                                                                                                    0  physical reads

0  redo size                                                                                                                             0  redo size

451  bytes sent via SQL*Net to client                                                                                 451  bytes sent via SQL*Net to client

384  bytes received via SQL*Net from client                                                                    384  bytes received via SQL*Net from client

2  SQL*Net roundtrips to/from client                                                                              2  SQL*Net roundtrips to/from client

0  sorts (memory)                                                                                                                 0  sorts (memory)

0  sorts (disk)                                                                                                                         0  sorts (disk)

2  rows processed                                                                                                                2  rows processed

Oracle11g温习-第十章:存储架构的更多相关文章

  1. Oracle11g温习-第二十章:数据装载 sql loader

    2013年4月27日 星期六 10:53  1. sql loader :将外部数据(比如文本型)数据导入oracle database.(用于数据导入.不同类型数据库数据迁移) 2.sqlloade ...

  2. infoq 微信后台存储架构

    infoq 上微信后台存储架构 视频很是值得认真一听,大概内容摘要如下: 主要内容:同城分布式强一致,园区级容灾KV存储系统 - sync 序列号发生器      移动互联网场景下,频繁掉线重连,使用 ...

  3. 云方案,依托H3C彩虹云存储架构,结合UIA统一认证系统,实现了用户数据的集中存储和管理

    客户的声音 资料云项目在迷你云基础上二次开发,通过使用云存储技术及文件秒传技术,对文件进行统一存储与管理,以达到节约文件管理成本.存储成本目的:通过有效的文件版本控制机制,以达到风险管控的目的:通过多 ...

  4. 现代IM系统中消息推送和存储架构的实现

    现代IM系统中消息推送和存储架构的实现-云栖社区-阿里云 https://yq.aliyun.com/articles/253242

  5. 腾讯刘金明:腾讯云 EB 级对象存储架构深度剖析及实践

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 演讲者:刘金明 腾讯云存储业务中心副总监 背景:5月23-24日,以"焕启"为主题的腾讯"云+未来" ...

  6. 014_HDFS存储架构、架构可靠性分析、副本放置策略、各组件之间的关系

    1.HDFS存储架构

  7. MAS多媒体的整个存储架构是怎样的?

    MAS多媒体的整个存储架构是怎样的?

  8. 【转帖】IBM发布全新闪存解决方案,助企业存储架构做减法

    IBM发布全新闪存解决方案,助企业存储架构做减法 http://stor-age.zhiding.cn/stor-age/2020/0227/3124851.shtml 感觉 配图弄错了 FlashS ...

  9. 从零开始入门 K8s | Kubernetes 存储架构及插件使用

    本文整理自<CNCF x Alibaba 云原生技术公开课>第 21 讲. 导读:容器存储是 Kubernetes 系统中提供数据持久化的基础组件,是实现有状态服务的重要保证.Kubern ...

随机推荐

  1. monit

    Monit 是一个用来监测系统状态的工具,不但可以用来监视进程.服务.文件.目录.文件系统,还可以在服务 down 掉的时候自动重启服务或者当某个进程占用过多的资源的时候自动停掉进程,并且支持 Ema ...

  2. noip2015 day1

    不解释,很简单,直接按照题目的方法构造就行了 Code #include<iostream> #include<cstdio> #include<cctype> # ...

  3. 第一个html文件

    1.新建记事本文件,后缀改为.html 2.添加: <html>  <head>  <title>jude`s first web</title>  & ...

  4. python2.7+pyqt4 +eric4安装配置

    eric4安装与汉化一直没找到合适python的IDE工具,直到遇到了eric4这款开源软件.然而在使用过程中发现输出的中文字符竟然是乱码,修修改改配置总算正常显示了,何不干脆把软件界面也汉化下. 一 ...

  5. U盘+GRUB2引导PE或linux镜像

    利用U盘制作启动盘,引导WinPE.Linux安装的文章多如牛毛,与他们相比本文的特点有: 1.用且仅用grbu2做引导.不使用grub4dos,不是使用msdos mbr转到活动分区,到ntldr, ...

  6. HDU 4819 Mosaic (二维线段树&区间最值)题解

    思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...

  7. Sql 最简单的Sqlserver连接

    string name = txtUserName.Text.Trim();//移除用户名前部和后部的空格 string pwd = txtUserPwd.Text.Trim();//移除密码前部和后 ...

  8. hdoj-2086-A1=?

    题目:A1=? 代码(作者:Fistice): #include<cstdio> #include<cmath> #include<cstring> #includ ...

  9. C#类头部声明样式

    /******************************************************************** * * 使本项目源码前请仔细阅读以下协议内容,如果你同意以下 ...

  10. Java中的RTTI

    RTTI可以帮助我们在运行时识别对象和类的信息. 一般传统的RTTI有三种实现方式: 1. 向上转型或向下转型(upcasting and downcasting),在java中,向下转型(父类转成子 ...