從10g開始,oracle開始提供Shrink的命令,假如我們的表空間中支持自動段空間管理 (ASSM),就可以使用這個特性縮小段,即降低HWM。
segment shrink分爲兩個階段:
1、數據重組(compact):通過一系列insert、delete操作,將數據儘量排列在段的前面。在這個過程中需要在表上加RX鎖,即只在需要移動的行上加鎖。由於涉及到rowid的改變,需要enable row movement.同時要disable基於rowid的trigger.這一過程對業務影響比較小。
2、HWM調整:第二階段是調整HWM位置,釋放空閒數據塊。此過程需要在表上加X鎖,會造成表上的所有DML語句阻塞。在業務特別繁忙的系統上可能造成比較大的影響。
shrink space語句兩個階段都執行。
shrink space compact只執行第一個階段。
如果系統業務比較繁忙,可以先執行shrink space compact重組數據,然後在業務不忙的時候再執行shrink space降低HWM釋放空閒數據塊。
shrink必須開啓行遷移功能。
alter table table_name enable row movement ;
注意:alter table XXX enable row movement語句會造成引用表XXX的對象(如存儲過程、包、視圖等)變爲無效。執行完成後,最好執行一下utlrp.sql來編譯無效的對象。
語法:
alter table <table_name> shrink space [ <null> | compact | cascade ];
alter table <table_name> shrink space compcat;
收縮表,相當於把塊中數據打結實了,但會保持 high water mark;
alter table <tablespace_name> shrink space;
收縮表,降低 high water mark;
alter table <tablespace_name> shrink space cascade;
收縮表,降低 high water mark,並且相關索引也要收縮一下下。
alter index idxname shrink space;
回縮索引
1:普通表
Sql腳本,改腳本會生成相應的語句
select’alter table ‘||table_name||’ enable row movement;’||chr(10)||’alter table ‘||table_name||’ shrink space;’||chr(10)from user_tables;
select’alter index ‘||index_name||’ shrink space;’||chr(10)from user_indexes;
2:分區表的處理
進行shrink space時 發生ORA-10631錯誤.shrink space有一些限制.
在表上建有函數索引(包括全文索引)會失敗。
Sql腳本,改腳本會生成相應的語句
select ‘alter table ‘||table_name||’ enable row movement;’||chr(10)||’alter table ‘||table_name||’ shrink space;’||chr(10) from user_tables where ;
select ‘alter index ‘||index_name||’ shrink space;’||chr(10) from user_indexes where uniqueness=’NONUNIQUE’ ;
select ‘alter table ‘||segment_name||’ modify subpartition ‘||partition_name||’ shrink space;’||chr(10) from user_segments where segment_type=’TABLE SUBPARTITION’ ‘;
另外,對於頻繁操作的表可以緩存到內存中
oracle的db_buffer_pool由三部分組成:
buffer_pool_defualt
buffer_pool_keep
buffer_pool_recycle
如果要把表釘死在內存中,也就是把表釘在keep區。
相關的命令爲:
alter table ….. storage(buffer_pool keep);
這句命令把表示表如果緩存的話是緩存在keep區。
可以通過語句:
select table_name from dba_tables where buffer_pool=’KEEP’;查詢到改表是放在keep區中的。
但是不意味着表已經被緩存了。
下面的語句把表緩存:
alter table …. cache;
可以通過
select table_name from dba_ tables where rtrim(cache)=’Y’
查詢到該表已經被緩存了。
加入到keep區的表不是說不能被移出內存,不過是比較不容易移出內存。
也可以手工來移出內存,命令如下:
alter table … nocache;
oracle Shrink命令
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Latest Pass Exam With Avaya 31860X Exam Dumps(2022)
declanriver34125
2022-06-20 20:37:57
Databricks Certified Professional Data Scientist Exam Dumps-Easiest Preparation Method(2022)
declanriver34125
2022-06-20 20:23:31
Salesforce Sales Cloud Consultant Practice Test - Best Preparation Material
declanriver34125
2022-06-18 19:23:01
Salesforce Certified Administrator Practice Test - Effective Tips To Pass
declanriver34125
2022-06-18 19:07:55
NBA Finals Game 6 live Free
jeffreycklima
2022-06-17 03:19:12
sdghjkghjgfjhfg
jeffreycklima
2022-06-12 06:25:41
GCP-GC-REP Exam Questions Help You to Score Higher in Your Genesys Exam
jamesconnorx7
2022-06-11 20:09:00
Blood Boost Formula (2022 Update) Customer Complaints & Health Risks?
triciusti
2022-06-10 20:26:25
FWEGESR WAGESR
tahad17me
2022-06-06 15:45:12
Cost-Effective Backup Approach to Promote Backup as a Service Market
reportsfuture24
2022-05-02 17:43:41
Dissertation Writing Services UK
henryrosie890
2022-05-02 16:40:42
Global Probe Card Market segmented By Type (Cantilever Probe Card, MEMS Probe Card, and Vertical Pro
syedsimranskyquest
2022-04-29 00:21:50
Global Hard Seltzer Market Study
manti.manna.skyquestt
2022-04-27 16:17:23