oracle 11g ocp 筆記(5)-- oracle儲存結構

來源:互聯網
上載者:User

標籤:create   HERE   bind   dna   type   host   重做日誌   建立   行號   

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(+);

 

 

 

參考網址:43452133

oracle 11g ocp 筆記(5)-- oracle儲存結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.