oracle 高水位线回收,回收高水位线
這里簡單地講述回收表的高水位,從表對應的段包含的塊數的變化,間接地表現出高水位線
對表記錄檢索的影響。在這個表高水位回收的測試中,也順便驗證了表中的索引在回收高水位的過程中
并沒有發生失效。還有就是在高水位回收前,需要配置表的行移動功能,不然就不能正常進行高水位的回收。
--創建測試表:
suxing@PROD> create table emp tablespace users as select * from hr.employees where 1=0;
Table created.
--給測試表創建索引:
suxing@PROD> create index idx_emp_salary on emp(salary) tablespace users;
Index created.
--查看索引的狀態:
suxing@PROD>select TABLE_OWNER,TABLE_NAME,INDEX_NAME,INDEX_TYPE,STATUS,INCLUDE_COLUMN
2 ?from user_indexes
3 ?where table_name ='EMP';
TABLE_OWNER ? ? ? ? ? ? ? ? ? ?TABLE_NAME ? ? ? ? ? ? ? ? ? ? INDEX_NAME ? ? ? ? ? ? ? ? ? ? INDEX_TYPE ? ? ? ? ? ? ? ? ?STATUS ? INCLUDE_COLUMN
------------------------------ ------------------------------ ------------------------------ --------------------------- -------- --------------
SUXING ? ? ? ? ? ? ? ? ? ? ? ? EMP ? ? ? ? ? ? ? ? ? ? ? ? ? ?IDX_EMP_SALARY ? ? ? ? ? ? ? ? NORMAL ? ? ? ? ? ? ? ? ? ? ?VALID
--插入大量數據記錄:
begin
for i in 1..500 loop
insert into emp select * from hr.employees;
end loop;
commit;
end;
/
--查看數據:
suxing@PROD>select count(*) from emp;
COUNT(*)
----------
53500
#一般表中的數據記錄多,測試效果才明顯。
--查看索引狀態:
suxing@PROD>select INDEX_NAME,STATUS from user_indexes where INDEX_NAME=upper('idx_emp_salary');
INDEX_NAME ? ? ? ? ? ? ? ? ? ? STATUS
------------------------------ --------
IDX_EMP_SALARY ? ? ? ? ? ? ? ? VALID
--查看表的信息:
SELECT num_rows, blocks, empty_blocks as empty, avg_space, chain_cnt, avg_row_len
FROM user_tables where table_name = 'EMP';
suxing@PROD>SELECT num_rows, blocks, empty_blocks as empty, avg_space, chain_cnt, avg_row_len
FROM user_tables where table_name = 'EMP';
NUM_ROWS ? ? BLOCKS ? ? ?EMPTY ?AVG_SPACE ?CHAIN_CNT AVG_ROW_LEN
---------- ---------- ---------- ---------- ---------- -----------
--收集表的統計信息:
suxing@PROD>exec dbms_stats.gather_table_stats(user,'EMP');
PL/SQL procedure successfully completed.
--或者:
analyze table emp compute statistics for table for all columns for all indexes;
#可以通過多種方法對表進行表分析。
suxing@PROD>SELECT num_rows, blocks, empty_blocks as empty, avg_space, chain_cnt, avg_row_len
2 ? ? FROM user_tables where table_name = 'EMP';
--查看表emp的基本信息:
NUM_ROWS ? ? BLOCKS ? ? ?EMPTY ?AVG_SPACE ?CHAIN_CNT AVG_ROW_LEN
---------- ---------- ---------- ---------- ---------- -----------
53500 ? ? ? ?622 ? ? ? ? 18 ? ? ? 1074 ? ? ? ? ?0 ? ? ? ? ?71
suxing@PROD>select segment_name,tablespace_name,bytes,blocks
2 ?from user_segments
3 ?where segment_name='EMP';
SEGMENT_NAME ? ? ? ? TABLESPACE_NAME ? ? ? ? ? ? ? ? ? ? BYTES ? ? BLOCKS
-------------------- ------------------------------ ---------- ----------
EMP ? ? ? ? ? ? ? ? ?USERS ? ? ? ? ? ? ? ? ? ? ? ? ? ? 5242880 ? ? ? ?640
--查看表的執行計劃的統計信息:
suxing@PROD>set autot trace stat
suxing@PROD>select count(*) from emp;
Statistics
----------------------------------------------------------
0 ?recursive calls
0 ?db block gets
569 ?consistent gets
0 ?physical reads
0 ?redo size
527 ?bytes sent via SQL*Net to client
523 ?bytes received via SQL*Net from client
2 ?SQL*Net roundtrips to/from client
0 ?sorts (memory)
0 ?sorts (disk)
1 ?rows processed
#也可以從查詢SQL的執行計劃中去判斷回收高水位對表檢索的影響。
--刪除大部分記錄:
suxing@PROD>delete emp where rownum<=50000;
50000 rows deleted.
Statistics
----------------------------------------------------------
16 ?recursive calls
155833 ?db block gets
546 ?consistent gets
0 ?physical reads
27218000 ?redo size
840 ?bytes sent via SQL*Net to client
786 ?bytes received via SQL*Net from client
3 ?SQL*Net roundtrips to/from client
1 ?sorts (memory)
0 ?sorts (disk)
50000 ?rows processed
suxing@PROD>commit;
Commit complete.
--刪除數據記錄后再次收集表的統計信息:
suxing@PROD>exec dbms_stats.gather_table_stats(user,'EMP');
PL/SQL procedure successfully completed.
--再次查看emp表的基本信息:
suxing@PROD>SELECT num_rows, blocks, empty_blocks as empty, avg_space, chain_cnt, avg_row_len
2 ? ? FROM user_tables where table_name = 'EMP';
NUM_ROWS ? ? BLOCKS ? ? ?EMPTY ?AVG_SPACE ?CHAIN_CNT AVG_ROW_LEN
---------- ---------- ---------- ---------- ---------- -----------
3500 ? ? ? ?622 ? ? ? ? ?0 ? ? ? ? ?0 ? ? ? ? ?0 ? ? ? ? ?69
suxing@PROD>select segment_name,tablespace_name,bytes,blocks
2 ?from user_segments
3 ?where segment_name='EMP';
SEGMENT_NAME ? ? ? ? TABLESPACE_NAME ? ? ? ? ? ? ? ? ? ? BYTES ? ? BLOCKS
-------------------- ------------------------------ ---------- ----------
EMP ? ? ? ? ? ? ? ? ?USERS ? ? ? ? ? ? ? ? ? ? ? ? ? ? 5242880 ? ? ? ?640
--嘗試直接shrink表回收高水位:
suxing@PROD>alter table emp shrink space;
alter table emp shrink space
*
ERROR at line 1:
ORA-10636: ROW MOVEMENT is not enabled
#發現配置不足。
--啟動行移動:
suxing@PROD>alter table emp enable row movement;
Table altered.
#開啟行移動。
suxing@PROD>alter table emp shrink space;
Table altered.
--查看索引的狀態:
suxing@PROD>select INDEX_NAME,STATUS from user_indexes where INDEX_NAME=upper('idx_emp_salary');
INDEX_NAME ? ? ? ? ? ? ? ? ? ? STATUS
------------------------------ --------
IDX_EMP_SALARY ? ? ? ? ? ? ? ? VALID
#索引沒有失效。
--查看表的基本信息:
suxing@PROD>SELECT num_rows, blocks, empty_blocks as empty, avg_space, chain_cnt, avg_row_len
2 ? ? FROM user_tables where table_name = 'EMP';
NUM_ROWS ? ? BLOCKS ? ? ?EMPTY ?AVG_SPACE ?CHAIN_CNT AVG_ROW_LEN
---------- ---------- ---------- ---------- ---------- -----------
3500 ? ? ? ?622 ? ? ? ? ?0 ? ? ? ? ?0 ? ? ? ? ?0 ? ? ? ? ?69
suxing@PROD>select segment_name,tablespace_name,bytes,blocks
2 ? ?from user_segments
3 ? ?where segment_name='EMP';
SEGMENT_NAME ? ? ? ? TABLESPACE_NAME ? ? ? ? ? ? ? ? ? ? BYTES ? ? BLOCKS
-------------------- ------------------------------ ---------- ----------
EMP ? ? ? ? ? ? ? ? ?USERS ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?393216 ? ? ? ? 48
#表包含的數據塊數發現了明顯的變化。
小結:
1,alter table shrink space compact cascade;對大表或大索引操作會產生大量日志
2,alter table shrink space;--加上compact選項僅重新整理segment 空間,并壓縮表的記錄在以后進行release空間.但并不調整hwm及釋放空間.為了釋放空間.你必須再發布alter table shrink space
--compact用于把一個長操作分割為兩個較短的操作
--須開啟行移動
--cascade會級聯對其依賴對象(比如上面的索引)進行壓緊操作
3,它的一些限制條件:
在集群表,long列的表不能采用shrink 操作
在基于函數索引或位圖聯接索引不支持shrink操作
就是你指定了cascade選項,也不能shrink 索引組織表的映射表
壓縮表不能用shrink操作
構建了on commit物化視圖的主表,在shrink操作后,rowid實化視圖必須重建
4,alter table shrink space;--僅可對automatic segment management tablespace方式的table,index_orginized table or overflow segment,index,partition,lob segment,mv,mv log
--壓縮segment,調整hwm,并馬上釋放空間
總結
以上是生活随笔為你收集整理的oracle 高水位线回收,回收高水位线的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php修改网页打印纸张 份数,打印机上复
- 下一篇: log4jdbc oracle,通过we