oracle 高水位线回收,回收高水位线
這里簡(jiǎn)單地講述回收表的高水位,從表對(duì)應(yīng)的段包含的塊數(shù)的變化,間接地表現(xiàn)出高水位線
對(duì)表記錄檢索的影響。在這個(gè)表高水位回收的測(cè)試中,也順便驗(yàn)證了表中的索引在回收高水位的過(guò)程中
并沒(méi)有發(fā)生失效。還有就是在高水位回收前,需要配置表的行移動(dòng)功能,不然就不能正常進(jìn)行高水位的回收。
--創(chuàng)建測(cè)試表:
suxing@PROD> create table emp tablespace users as select * from hr.employees where 1=0;
Table created.
--給測(cè)試表創(chuàng)建索引:
suxing@PROD> create index idx_emp_salary on emp(salary) tablespace users;
Index created.
--查看索引的狀態(tài):
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
--插入大量數(shù)據(jù)記錄:
begin
for i in 1..500 loop
insert into emp select * from hr.employees;
end loop;
commit;
end;
/
--查看數(shù)據(jù):
suxing@PROD>select count(*) from emp;
COUNT(*)
----------
53500
#一般表中的數(shù)據(jù)記錄多,測(cè)試效果才明顯。
--查看索引狀態(tài):
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
---------- ---------- ---------- ---------- ---------- -----------
--收集表的統(tǒng)計(jì)信息:
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;
#可以通過(guò)多種方法對(duì)表進(jìn)行表分析。
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
--查看表的執(zhí)行計(jì)劃的統(tǒng)計(jì)信息:
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的執(zhí)行計(jì)劃中去判斷回收高水位對(duì)表檢索的影響。
--刪除大部分記錄:
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.
--刪除數(shù)據(jù)記錄后再次收集表的統(tǒng)計(jì)信息:
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
#發(fā)現(xiàn)配置不足。
--啟動(dòng)行移動(dòng):
suxing@PROD>alter table emp enable row movement;
Table altered.
#開(kāi)啟行移動(dòng)。
suxing@PROD>alter table emp shrink space;
Table altered.
--查看索引的狀態(tài):
suxing@PROD>select INDEX_NAME,STATUS from user_indexes where INDEX_NAME=upper('idx_emp_salary');
INDEX_NAME ? ? ? ? ? ? ? ? ? ? STATUS
------------------------------ --------
IDX_EMP_SALARY ? ? ? ? ? ? ? ? VALID
#索引沒(méi)有失效。
--查看表的基本信息:
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
#表包含的數(shù)據(jù)塊數(shù)發(fā)現(xiàn)了明顯的變化。
小結(jié):
1,alter table shrink space compact cascade;對(duì)大表或大索引操作會(huì)產(chǎn)生大量日志
2,alter table shrink space;--加上compact選項(xiàng)僅重新整理segment 空間,并壓縮表的記錄在以后進(jìn)行release空間.但并不調(diào)整hwm及釋放空間.為了釋放空間.你必須再發(fā)布alter table shrink space
--compact用于把一個(gè)長(zhǎng)操作分割為兩個(gè)較短的操作
--須開(kāi)啟行移動(dòng)
--cascade會(huì)級(jí)聯(lián)對(duì)其依賴對(duì)象(比如上面的索引)進(jìn)行壓緊操作
3,它的一些限制條件:
在集群表,long列的表不能采用shrink 操作
在基于函數(shù)索引或位圖聯(lián)接索引不支持shrink操作
就是你指定了cascade選項(xiàng),也不能shrink 索引組織表的映射表
壓縮表不能用shrink操作
構(gòu)建了on commit物化視圖的主表,在shrink操作后,rowid實(shí)化視圖必須重建
4,alter table shrink space;--僅可對(duì)automatic segment management tablespace方式的table,index_orginized table or overflow segment,index,partition,lob segment,mv,mv log
--壓縮segment,調(diào)整hwm,并馬上釋放空間
總結(jié)
以上是生活随笔為你收集整理的oracle 高水位线回收,回收高水位线的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php修改网页打印纸张 份数,打印机上复
- 下一篇: php 阻塞消息队列,linux 消息队