您好,登錄后才能下訂單哦!
又是一年雙11,雙十一對(duì)從事電商的it人員來說是一場(chǎng)噩夢(mèng),這個(gè)只是前奏,下面說重點(diǎn):
表碎片整理,首先收集那些表需要做碎片整理:
1.1根據(jù)統(tǒng)計(jì)信息檢查表碎片:
SELECT table_name,
ROUND ( (blocks 8), 2) "高水位空間 k",
ROUND ( (num_rows avg_row_len / 1024), 2) "真實(shí)使用空間 k",
ROUND ( (blocks 10 / 100) 8, 2) "預(yù)留空間(pctfree) k",
ROUND ( ( blocks 8 - (num_rows avg_row_len / 1024) - blocks 8 10 / 100), 2) "浪費(fèi)空間 k"
FROM user_tables
WHERE temporary = 'N'
ORDER BY 5 DESC;
1.2. 是和業(yè)務(wù)開發(fā)人員溝通那些主要的業(yè)務(wù)表做了大量的delete、update操作,確定要整理的表范圍。
2.1.下面是碎片整理步驟:
alter table app_info enable row movement; --打開行移動(dòng)
alter table app_info shrink space cascade; --壓縮表及相關(guān)數(shù)據(jù)段并下調(diào)HWM (此步驟會(huì)影響業(yè)務(wù))
alter table app_info shrink space compact; --只壓縮不下調(diào)HWM
alter table app_info shrink space ; --下調(diào)HWM (此步驟會(huì)影響業(yè)務(wù))
alter table app_info disable row movement; --關(guān)閉行移動(dòng)
其中alter table app_info shrink space compact; alter table app_info shrink space ; 兩個(gè)步驟等于alter table app_info shrink space cascade; 操作
注意:
IOT索引組織表、用rowid創(chuàng)建的物化視圖的基表、帶有函數(shù)索引的表、SECUREFILE 大對(duì)象、壓縮表不能使用Shrink 操作。
3.1 整理完碎片后最好重新收集統(tǒng)計(jì)信息:
begin
dbms_stats.gather_table_stats(ownname => 'chunqiu',tabname => 'app_info',cascade => true);
end;
4.1下面為寫在plsql語句塊中的參考,為下面腳本準(zhǔn)備:
begin
EXECUTE IMMEDIATE 'alter table app_info shrink space ';
EXECUTE IMMEDIATE 'alter table app_info disable row movement ';
end;
5.1如果表很多怎么辦?,特備是最后的下調(diào)高水位線基本上都需要在晚上業(yè)務(wù)低峰期操作,甚至有的會(huì)申請(qǐng)掛免戰(zhàn)牌,下面寫個(gè)腳本批量處理加上定時(shí)任務(wù),可以讓dba們節(jié)約時(shí)間好好休息下:
create table T_TABALE
(
table_name VARCHAR2(200) not null,
compact_status NUMBER default 0 not null,
shrink_status NUMBER default 0 not null
);
alter table T_TABALE add constraint PK_T_TABALE primary key (TABLE_NAME);
把要整理的表名字插入到該表。
5.1.先開啟row movement:
BEGIN
FOR i IN (select table_name from T_TABALE ) LOOP
EXECUTE IMMEDIATE 'alter table ' || i.table_name ||' enable row movement ' ;
END LOOP;
END;
5.2.整理碎片:
BEGIN
FOR i IN (select table_name from T_TABALE where compact_status = 0 ) LOOP
begin
EXECUTE IMMEDIATE 'alter table ' || i.table_name ||' shrink space compact ' ;
update T_TABALE set status = 1 where table_name = i.table_name ;
commit;
EXCEPTION WHEN OTHERS THEN null;
END;
END LOOP;
END;
5.3.降低高水位,步驟最好結(jié)合定時(shí)任務(wù)放在晚上執(zhí)行:
這個(gè)可以寫個(gè)定時(shí)任務(wù),晚上執(zhí)行
BEGIN
FOR i IN (select table_name from T_TABALE where compact_status = 0 ) LOOP
begin
EXECUTE IMMEDIATE 'alter table ' || i.table_name ||' shrink space ' ;
update T_TABALE set shrink_status = 1 where table_name = i.table_name ;
commit;
EXCEPTION WHEN OTHERS THEN null;
END;
END LOOP;
END;
5.5 關(guān)閉row movement:
BEGIN
FOR i IN (select table_name from T_TABALE ) LOOP
BEGIN
EXECUTE IMMEDIATE 'alter table ' || i.table_name ||' disable row movement ' ;
END LOOP;
END;
6.1 最后別忘了收集下統(tǒng)計(jì)信息,收集統(tǒng)計(jì)信息的批量腳本自己實(shí)現(xiàn)吧。
突然想起來了,供參考:
BEGIN
FOR i IN (select blocks*8/1024/1024 ,table_name from dba_tables where table_name in(select table_name from pacs.T_TABALE where status = 11 ) order by 1 ) LOOP
begin
EXECUTE IMMEDIATE 'begin dbms_stats.gather_table_stats(ownname =>' || '''pacs'''|| ', tabname => ''' || i.table_name || '''' || ' ,cascade => true) ; end; ' ;
update pacs.T_TABALE set status = 12 where table_name = i.table_name ;
commit;
-- EXCEPTION WHEN OTHERS THEN null;
END;
END LOOP;
END;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。