view plain
copy to clipboard
print?
alter
table table_name move tablespace tbs_name;
select
'alter index '||index_name||' rebuild;' sql_text
from user_index ui
where ui.table_name='&tab_name';
alter table table_name move tablespace tbs_name;
select 'alter index '||index_name||' rebuild;' sql_text
from user_index ui
where ui.table_name='&tab_name';
2.以ctas建立備份表,將源表truncate,然後回寫:
view plain
copy to clipboard
print?
create
table bak_table_name as
select * from table_name;
truncate
table table_name;
insert
into table_name select * from bak_table_name;
commit;
create table bak_table_name as select * from table_name;
truncate table table_name;
insert into table_name select * from bak_table_name;
commit;
3.方法1、2對於小表比較適合,如果對上g的表進行操作,可能就比較麻煩了。建議進行exp/imp操作。
4.對於oracle 10g可以採用alter table shrink space;
view plain
copy to clipboard
print?
alter
table table_name enable row movement;
alter
table table_name shring space;
alter table table_name enable row movement;
alter table table_name shring space;
用alter table move降低高水位:
dw@dw>create table yy as2 select *
3 from dba_tables dt;
dw@dw>
dw@dw>analyze table yy compute statistics;
dw@dw>
dw@dw>
dw@dw>select ue.bytes,ue.blocks
2 from user_extents ue
3 where ue.segment_name='yy';
bytes blocks
---------- ----------
65536 8
65536 8
65536 8
65536 8
65536 8
65536 8
65536 8
65536 8
dw@dw>
dw@dw>select t.table_name,t.blocks from user_tables t
2 where t.table_name='yy';
table_name blocks
------------------------------ ----------
yy 60
dw@dw>
dw@dw>delete yy
2 where rownum <
3 (select count(1)-10 from yy);
dw@dw>analyze table yy compute statistics;
dw@dw>
dw@dw>select ue.bytes,ue.blocks
2 from user_extents ue
3 where ue.segment_name='yy';
bytes blocks
---------- ----------
65536 8
65536 8
65536 8
65536 8
65536 8
65536 8
65536 8
65536 8
dw@dw>
dw@dw>select t.table_name,t.blocks from user_tables t
2 where t.table_name='yy';
table_name blocks
------------------------------ ----------
yy 60
dw@dw>
dw@dw>alter table yy move;
dw@dw>
dw@dw>
dw@dw>analyze table yy compute statistics;
dw@dw>
dw@dw>
dw@dw>select ue.bytes,ue.blocks
2 from user_extents ue
3 where ue.segment_name='yy';
bytes blocks
---------- ----------
65536 8
dw@dw>
dw@dw>select t.table_name,t.blocks from user_tables t
2 where t.table_name='yy';
table_name blocks
------------------------------ ----------
yy 4
Oracle收縮表空間,降低高水位
oracle冗餘表空間收縮 應用背景 某些情況下,由於前期設計上沒有考慮全面,導致表空間預建太大,遠遠超出實際使用大小。於是,就出現了收縮表空間這樣的需求,即將這個表空間的占用空間進行收縮。1.開啟 set serveroutput on select tablespace name,block s...
oracle高水位降低法
1.什麼是高水位?high water mark 簡稱 hwm 所有的oracle段 segments,在此,為了理解方便,建議把segment作為表的乙個同義詞 都有乙個在段內存放資料的上線,那麼我們把這個上線成為 high water mark 或 hwm.hwm是乙個標記,用來說明已經有多少沒...
SHRINK SEGMENT降低高水位
oracle 10g 語法 alter tableshrink space compact cascade alter tableshrink space compcat 收縮表,但會保持 high water mark 這怎麼理解?相當於沒回縮?相當於把塊中資料打結實了。沒有變動hwm alter...