1. 程式人生 > >oracle 11g ocp 筆記(5)-- oracle存儲結構

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

dia tro min 編號 contents all 重做日誌 absolut bit

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

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