oracle 11g ocp 笔记(5)-- oracle存储结构

1、了解oracle表空间和数据文件。

oracle存储模型。表空间、段、区间、oracle块,数据文件、和操作系统块的对应关系。

select segment _type ,count(1) from dba_segments group by segent_type.查看类型。

    table 堆表

  index 索引

  type2undo 撤销段???????与rollback的区别呢??

      rollback  回滚段

  table partition  分区表

       index partition 分区索引

       lobsegment  lobindex lob partition  大对象类型

  cluster  聚集

  clusted table 聚集表

select tablespace_name,file_id,extent_id,block_id,block,butes from dba_extents;
    select tablespace_name,file_name,file_id from dba_data_files;

alter table XX allocate extend ( storage 'filename')

文件存储技术:

  本地文件系统上的文件 

  集群文件系统上的文件

  原始设备上的文件

  ASM上的文件

????????

ASM只能存储数据库文件。不能存储二进制文件。SPFILE的解决。

查询存储结构的视图
    控制文件的名称和大小
    select name,block_size*file_size_blks bytes from v$controlfile;
    联机重做日志文件成员的名称和大小
    select member,bytes from v$log join v$logfile using (group#);
    数据文件和临时文件的名称和大小
    select name,bytes from v$datafile;
    select name,bytes from v$tempfile;

2、创建和管理表空间

  (1).创建表空间
    create [smallfile|bigfile] tablespace tablespace_name
      datafile '/u01/app/oracle/oradata/SID/***.dbf'
      size 100M autoextend on next 10M maxsize 200M
      logging
      extent management local
      segment space management auto
      default nocompress;

dba_spaces  dba_datafiles  db_free_space

(2)更改表空间

   alter tablespace tablespaceoldname rename to tablespacenewname;          --重命名表空间
    alter tablespace tablespacename offline [normal|immediate|temporary];    --使表空间脱机
    alter tablespace tablespacename [read only|read write];                  --表空间标记只读和读写
    alter database datafile filename resize n[M|G|T];                        --重新调整表空间数据文件大小
    alter tablespace tablespacename add datafile datafilename size n[M|G|T]; --添加数据文件进表空间
    alter database datafile filename autoextend on next 100M maxsize 4G;     --修改表空间数据文件的自动扩展

(3).重命名表空间和数据文件
    alter tablespace tablespacename rename to newtablespacename;
    alter tablespace tablespacename offline;
    host rename xxxxx.dbf xxxxxxx.dbf
    alter database rename file 'oldfilename' to 'newfilename';
    alter tablespace tablespacename online;


    (4).删除表空间
    drop tablespace tablespacenmae [including contents [and datafiles]];


    使用OMF特性管理数据库文件的创建,设置以下参数
    db_create_file_dest                   --数据文件的默认位置
    db_create_online_log_dest_1           --联机重做日志的默认位置
    db_create_online_log_dest_2
    db_create_online_log_dest_3
    db_create_online_log_dest_4
    db_create_online_log_dest_5
    db_recovery_file_dest                 --快速恢复区默认位置、归档日志文件和备份文件的默认位置

3、管理表空间中的空间

将空间分给表空间、表空间中的空间分给段,将段中的空间分给行。

 sys.uet$ 表示空闲空间。  sys.free$表示剩余空间

extend的管理:基于字典的空间管理和本地空间管理(9i)

uniform size  一次分配的多少。

select  tablespace_name,extend_management from dba_tablespace查询管理方式。

exec dbms_space_admin.tablespace_migeagte_to_local('tablespacename')

管理segment。

自动段管理。9i引入,11g为默认。

其他

3.数据文件的大小限制:
    (1)smallfile表空间的数据文件:
    Rowid包括四部分组成: 对象号+相对文件号+块号+行号(32bit object# + 10bit rfile# + 22bit block# + 16 bit row#),10Bytes.
    select dbms_rowid.rowid_object(rowid) object_id,
           dbms_rowid.rowid_relative_fno(rowid) relative_fno,
           dbms_rowid.rowid_block_number(rowid) block_number,
           dbms_rowid.rowid_row_number(rowid) row_number,           
      from mms.usr_mstr
     where rownum < 10;


    每个文件都包括两个编号,一个是绝对文件编号file_id,另一个是相对文件编号relative_fno。
    select dbms_rowid.rowid_relative_fno(rowid) relative_fno,                     -- 相对文件编号(最大1024)
           dbms_rowid.rowid_to_absolute_fno(rowid,'MMS','USR_MSTR') absolute_fno  -- 绝对文件编号
      from mms.usr_mstr
     where rownum < 10;


    在smallfile表空间的数据文件中,Oracle利用22位进行块地址存储,22位最多只能代表2^22-1=4194303=4M个数据块,如果数据块大小为8k,则数据文件的理论大小上限为32G。如果最大数据块大小为32K,则数据文件的理论大小上限为128G。一个表空间只能有1023个数据文件。
    因此,数据文件大小和db_block_size有关,数据块大小与数据文件最大理论值的对应关系如下:
    2KB       8GB
    4KB      16GB
    8KB      32GB
    16KB     64GB
    32KB    128GB


    (2)bigfile表空间的数据文件
    在bigfile表空间的数据文件中,由于一个表空间只允许有一个数据文件,事情会有所不同。
    select dbms_rowid.rowid_object(rowid) object_id, 
           dbms_rowid.rowid_relative_fno(rowid,'BIGFILE') relative_fno,
           dbms_rowid.rowid_block_number(rowid) block_number,
           dbms_rowid.rowid_row_number(rowid) row_number
      from mms.usr_mstr
     where rownum < 10;


    bigfile表空间只能有一个数据文件,Rowid的文件号就没有意义了,直接就是1024。由于没有relative_fno的问题,这样rowid中就不需要保存relative_fno的最多1024的数值。这样就节省出10位二进制位给数据块定位,相同长度的rowid就可以进行32位二进制长度的数据块寻址。每个数据文件中,最多可以包含2^32-1=4G个数据块。如果数据块大小8K,则数据文件理论大小上限为32TB。如果数据块大小为32K,则数据文件理论大小上限为128TB。
    
*** 数据文件大小也与操作系统的限制有关。

 表空间的统计信息
    SELECT d.status "Status", 
           d.tablespace_name "Name", 
           d.contents "Type", 
           d.extent_management "Extent Management", 
           NVL(a.bytes / 1024 / 1024, 0) "Size (M)", 
           TO_CHAR(NVL(a.bytes - NVL(f.bytes, 0), 0)/1024/1024,'99999999.999') "Used (M)", 
           ROUND(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0),2) "Used (%)" 
      FROM sys.dba_tablespaces d, 
           (select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, 
           (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f 
     WHERE d.tablespace_name = a.tablespace_name(+) 
       AND d.tablespace_name = f.tablespace_name(+) 
       AND NOT (d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY') 
     UNION ALL
    SELECT d.status "Status", 
           d.tablespace_name "Name", 
           d.contents "Type", 
           d.extent_management "Extent Management", 
           NVL(a.bytes / 1024 / 1024, 0) "Size (M)", 
           TO_CHAR(NVL(t.bytes,0)/1024/1024,'99999999.999') "Used (M)", 
           ROUND(NVL(t.bytes / a.bytes * 100, 0),2) "Used (%)" 
      FROM sys.dba_tablespaces d, 
           (select tablespace_name, sum(bytes) bytes from dba_temp_files group by tablespace_name) a,
           (select tablespace_name, sum(bytes_cached) bytes from v$temp_extent_pool group by tablespace_name) t 
     WHERE d.tablespace_name = a.tablespace_name(+) 
       AND d.tablespace_name = t.tablespace_name(+) 
       AND d.extent_management like 'LOCAL' 
       AND d.contents like 'TEMPORARY'
     ORDER BY 2;


    select t.tablespace_name name, d.allocated, u.used, f.free, t.status, d.datafiles, contents, 
           t.extent_management extman, t.segment_space_management segman
      from dba_tablespaces t,
           (select tablespace_name, sum(bytes) allocated, count(file_id) datafiles from dba_data_files group by tablespace_name) d,
           (select tablespace_name, sum(bytes) free from dba_free_space group by tablespace_name) f,
           (select tablespace_name, sum(bytes) used from dba_segments group by tablespace_name) u
     where t.tablespace_name = d.tablespace_name(+)
       and t.tablespace_name = f.tablespace_name(+)
       and t.tablespace_name = u.tablespace_name(+);

参考网址:https://blog.csdn.net/gyming/article/details/43452133

猜你喜欢

转载自www.cnblogs.com/hezt1114/p/8973909.html