Oracle Drop Partition & MView Rsync & Index確認
Drop Partition & MView Rsync & Index確認
標籤: Oracle
步驟:
一、確認要刪的Table Partition是否為Mview rsync資料
二、確認db大小,可以知道刪除多少資料
三、Report Mview jobs stop
四、Drop Partition(MES & Report)
五、使用Complete更新Mview物件
六、啟用Mview job
七、確認index狀態
八、確認刪除的大小
0.架構說明:
Oracle DB:10.2.0.4
資料來源:MESDB
Mview 抓取資料Server:ReportDB
1.確認Table Partition是否為Mview rsync Data
MESDB Partition(dba_mview_logs):
select * from dba_mview_logs where master in ('FWAMTCOMPTRACKHISTORY','FWEQPSUBEQPHISTORY','FWEXTDATALINKCOMPDATAHISTORY','FWEXTDATALINKHISTORY','FWMHSTRANSFERCOMMAND');
2.確認資料量大小(dba_segments)
select SUM(BYTES/1024/1024/1024) from dba_segments where owner='C5PROD' AND SEGMENT_NAME='FWEQPSUBEQPHISTORY';
共3.4G資料
3.Stop MView job,一定要用user的帳號進入(dba_jobs)
Report DB:
select 'exec dbms_job.broken(' || job || ',true);'
from dba_jobs where Log_user = 'STGC5'
'EXECDBMS_JOB.BROKEN('||JOB||',TRUE);'
exec dbms_job.broken(59,true);
exec dbms_job.broken(60,true);
…
停掉之後,還需要去確認是否有停掉。
關閉之後,job會劃×,如job 83,Broken會顯示yes,Running顯示no
當天在做的時候,job的broken是yes,runing顯示yes,一直關不掉,只好刪掉之後再重建了。
若是整台主機DB都可以停止,可以把job_queue_processes設為0,這樣背景執行的job就不會再跑起來了。
先確認一下目前的job_queue_processes:
SQL> show parameter job
NAME TYPE VALUE
------------------------------------ -----------
job_queue_processes integer 80
SQL>alter system set job_queue_processes=0 scope=both;
正在運行的Job不受影響,因為它在運行前就獲得了ora_jXXX進程。
修改後的參數只對:修改完成之後,要執行的Job有影響,因為之後的Job在執行前要獲得Job的調度進程.
由於我們這裏設置job_queue_processes=0,所以之後不會再有Job執行。
確認JOB是否還有在執行
select job from dba_jobs_running;
4.Drop MESDB partition(DBA_TAB_PARTITIONS)
先測試一下刪除一個Partition table
SELECT 'alter table '||table_owner||'.'||table_name||' drop partition ' ||PARTITION_NAME||';' FROM DBA_TAB_PARTITIONS
WHERE TABLE_OWNER='C5PROD' AND (PARTITION_NAME LIKE ('%2011%') OR
PARTITION_NAME LIKE ('%2012Q1%') OR PARTITION_NAME LIKE ('%2012Q2%') ) AND TABLE_NAME='FWEQPSUBEQPHISTORY';
alter table C5PROD.FWEQPSUBEQPHISTORY drop partition ESHI_2011Q2;
alter table C5PROD.FWEQPSUBEQPHISTORY drop partition ESHI_2011Q3;
…
5.使用complete更新MVIEW物件(all_mviews)
SELECT 'exec dbms_mview.refresh(''' ||OWNER||'.'||MVIEW_NAME|| ''',''C'',atomic=>false);' from all_mviews where owner='STGC5';
exec dbms_mview.refresh('STGC5.FWEQPSUBEQPHISTORY','C', atomic_refresh =>false);
exec dbms_mview.refresh('STGC5.FWAMTCOMPTRACKHISTORY','C', atomic_refresh =>false);
exec dbms_mview.refresh('STGC5.FWEXTDATALINKCOMPDATAHISTORY','C', atomic_refresh =>false);
exec dbms_mview.refresh('STGC5.FWEXTDATALINKHISTORY','C', atomic_refresh =>false);
exec dbms_mview.refresh('STGC5.FWMHSTRANSFERCOMMAND','C', atomic_refresh =>false);
6. 啟用MVIEW JOB(dba_jobs),確認一下Report AP
select 'exec dbms_job.broken(' || job || ',false);'
from dba_jobs where Log_user = 'STGC5'
'EXECDBMS_JOB.BROKEN('||JOB||',FALSE);'
exec dbms_job.broken(59,false);
exec dbms_job.broken(60,false);
…
若是整台主機DB都可以停止,可以把job_queue_processes設為0,這樣背景執行的job就不會再跑起來了。
SQL>alter system set job_queue_processes=80 scope=both;
7.確認index狀態(dba_part_indexes):
select owner,index_name,table_name,partitioning_type,locality from dba_part_indexes where owner='C5PROD';
若是local index,刪除partition table會一併刪除index,若是global index,需要做rebuild(查看locality這一個欄位)
確認index是否失效(dba_indexes):
SELECT owner,index_name,index_type,table_owner,table_name,table_type,tablespace_name,status,global_stats,join_index FROM DBA_INDEXES WHERE OWNER='C5PROD' AND( STATUS ='INVALID' OR STATUS='UNUSABLE');
Status:invalid or unusable代表的是index失效
Status:n/a,代表的是Partition index
若是Partition index,需要從user_ind_partitions做rebuild:
select 'alter index ' ||index_name||' rebuild partition '|| partition_name||' tablespace '|| tablespace_name||';' from user_ind_partitions where status = upper('UNUSABLE')
alter index IDX_GROUP_HIST_7F1A rebuild partition GROUP_HIST_7F1A_Q3 tablespace STGC5_TRG_IDX;
若是table index,直接做rebuild動作即可(可以從user_indexes來串SQL)
select index_name,index_type,tablespace_name,table_type,status
from user_indexes
where status='UNUSABLE'
alter index PKFWEXTDATALINKHISTORY rebuild;
八、最後再統計一下Purge大小(dba_segments)
花最久的時間是Mview refresh的時間,40.58G花了2個多小時。
select SUM(BYTES/1024/1024/1024) from dba_segments where owner='C5PROD' AND SEGMENT_NAME='FWEQPSUBEQPHISTORY';