Oracle database 表空間/段/區/塊

表空間

(一個或多個數據文件組成的 用來存儲對象)
根據表名查表空間
select table_name ,tablespace_name from user_tables where table_name=’DEPT’;
查詢表空間剩餘大小
select tablespace_name,sum(bytes)/1024/1024 from dba_free_space group by tablespace_name;
根據表空間查數據文件
select file_name ,tablespace_name from dba_data_files where tablespace_name=’USERS’;
查管理方式
select tablespace_name,contents,extent_management,segment_space_management from dba_tablespaces;
刪除表空間
drop tablespace 表空間名 including contents and datafiles;
級聯刪除
drop tablespace 表空間名 including contents cascade constraints;
設置自增長
alter database datafile 7 auntoextend on;


增量檢查點
show parameter fast_start_mttr_target; 多長時間恢復實例


臨時表空間

臨時表空間
select username,temporary_tablespace from dba_users where username =’SCOTT’;
臨時表空間用的數據文件
select file_name,tablespace_name from dba_temp_files;
創建臨時表空間
create temporary tablespace temp2 tempfile ‘/u01/data/orcl/temp02.dbf’ size 10m;
創建臨時表空間組
alter tablespace temp tablespace group tempgrp;
查看臨時表空間組
select * from dba_tablespace_groups;
修改用戶的臨時表空間爲臨時表空間組
alter user scott temporary tablespace tempgrp;
創建一個默認表空間名字爲a
create tablespace a datafile ‘/u01/data/orcl/a01.dbf’ size 10m;
切換表logging狀態 nologging 不寫redo
alter table 表名 nologging(logging);
查詢表的logging狀態
select table_name,logging from user_tables where table_name=’T1’;
設置數據文件自增長
alter database datafile ‘/u01/data/orcl/a01.dbf’ autoextend on next 1m maxsize 500m;
在表空間a添加數據文件
alter tablespace a add datafile ‘/u01/data/orcl/a02.dbf’ size 10m;
表空間不足時等待插入 默認時間2小時
alter session enable|disable resumable;

塊 (block) 最小讀寫單位 8K
區 (extent) 最小分配單位 初始區(8塊 64K)和後續區
段 (segment) 表空間按段管理對象 視圖沒有段

段(segment)

自動管理(ASSM) AUTO 5個位圖 (100% 75% 50% 25% 0%)
手動管理(MSSM) freelist 空閒列表可用塊 pctfree 保留百分比 pctused 使用百分比
建表時指定表空間後設置
pctfree pctused
查看錶的段管理方式
select table_name,pct_free,pct_used from user_tables;

區(extent)

查看區
select segment_name,file_id,extent_id,bytes from dba_extents;
手動添加t1表的區
alter table t1 allocate extent (datafile’/u01/data/orcl/a01.dbf’ size 5m);
回收未使用的區
alter table t1 deallocate unused;

塊(block)

show parameter 16k;
創建表空間時指定塊大小 blocksize 16k 爲16k
alter system set db_16k_cache_size =4m;


行遷移與行鏈接

分析表
analyze table t1 compute statistics for table;

select table_name,pct_free,pct_used,avg_row_len,chain_cnt from user_tables where table_name=’T1’;
可以解決行遷移 相當於重新插入
alter table t1 move;

當chain_cnt有值時 看avg_row_len 表示行的平均長度 如果avg_row_len>塊大小發生行鏈接 avg_row_len<塊大小 發生行遷移、調整塊大小可以解決行鏈接 重新插入數據可以解決行遷移

查看高水位線;
select num_rows,chain_cnt from user_tab_statistics where table_name=’T1’;
啓用行移動
alter table t6 enable row movement;
先壓縮 沒有鎖、
alter table t6 shrink space compact;
移動 有鎖
alter table t6 shrink space;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章