日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
超詳細(xì)的Oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

概述

生產(chǎn)環(huán)境中,經(jīng)常會(huì)遇到表由于數(shù)據(jù)不斷插入,導(dǎo)致空間越來越大,由于前期配置問題,沒有做分區(qū)或者其他優(yōu)化,而且生產(chǎn)數(shù)據(jù)實(shí)時(shí)向表插入。要?jiǎng)h除歷史數(shù)據(jù)來釋放空間。所以DBA一般都需要定期去對(duì)Oracle表碎片做整理,簡單整理表碎片整理流程如下:

1、定位存在碎片的對(duì)象

使用如下腳本,檢查需要進(jìn)行碎片整理的對(duì)象:

 
 
 
 
  1. --all tables(partition_tables + non_partition_tables ) 
  2. select a.owner, 
  3.  a.table_name, 
  4.  a.num_rows, 
  5.  a.avg_row_len, 
  6.  round(a.avg_row_len * a.num_rows / 1024 / 1024, 2) real_bytes_MB, 
  7.  round(b.seg_bytes_mb, 2) seg_bytes_mb, 
  8.  decode(a.num_rows, 
  9.  0, 
  10.  100, 
  11.  (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / 
  12.  b.seg_bytes_mb, 
  13.  2)) * 100) || '%' frag_percent 
  14.  from dba_tables a, 
  15.  (select owner, segment_name, sum(bytes / 1024 / 1024) seg_bytes_mb 
  16.  from dba_segments 
  17.  group by owner, segment_name) b 
  18.  where a.table_name = b.segment_name 
  19.  and a.owner = b.owner 
  20.  and a.owner not in 
  21.  ('SYS', 'SYSTEM', 'OUTLN', 'DMSYS', 'TSMSYS', 'DBSNMP', 'WMSYS', 
  22.  'EXFSYS', 'CTXSYS', 'XDB', 'OLAPSYS', 'ORDSYS', 'MDSYS', 'SYSMAN') 
  23.  and decode(a.num_rows, 
  24.  0, 
  25.  100, 
  26.  (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / 
  27.  b.seg_bytes_mb, 
  28.  2)) * 100) > 30 
  29.  order by b.seg_bytes_mb desc; 

2、統(tǒng)計(jì)信息檢查

2.1 統(tǒng)計(jì)信息檢查

查看統(tǒng)計(jì)信息收集日期,確保碎片查詢結(jié)果準(zhǔn)確:

 
 
 
 
  1. select owner,table_name,last_analyzed from dba_tables Where owner='' AND table_name=''; 

2.2 統(tǒng)計(jì)信息收集

如果統(tǒng)計(jì)信息過舊,則重新收集統(tǒng)計(jì)信息:

 
 
 
 
  1. exec dbms_stats.gather_table_stats(ownname=>'', tabname =>''); 

3、表碎片整理

3.1 打開行移動(dòng)

 
 
 
 
  1. alter table  enable row movement ; 

3.2 進(jìn)行表收縮

 
 
 
 
  1. alter table  shrink space cascade ; 

3.3 失效對(duì)象編譯

語句可能會(huì)造成引用表 的對(duì)象(如存儲(chǔ)過程、包、視圖等)變?yōu)闊o效。

運(yùn)行如下腳本,重新編譯失效對(duì)象。

 
 
 
 
  1. @?/rdbms/admin/utlrp.sql 

4、對(duì)象收縮后的結(jié)果檢查

運(yùn)行如下腳本,確認(rèn)對(duì)象空間是否已經(jīng)完成收縮。

 
 
 
 
  1. --all tables(partition_tables + non_partition_tables ) 
  2. select a.owner, 
  3.  a.table_name, 
  4.  a.num_rows, 
  5.  a.avg_row_len, 
  6.  round(a.avg_row_len * a.num_rows / 1024 / 1024, 2) real_bytes_MB, 
  7.  round(b.seg_bytes_mb, 2) seg_bytes_mb, 
  8.  decode(a.num_rows, 
  9.  0, 
  10.  100, 
  11.  (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / 
  12.  b.seg_bytes_mb, 
  13.  2)) * 100) || '%' frag_percent 
  14.  from dba_tables a, 
  15.  (select owner, segment_name, sum(bytes / 1024 / 1024) seg_bytes_mb 
  16.  from dba_segments 
  17.  group by owner, segment_name) b 
  18.  where a.table_name = b.segment_name 
  19.  and a.owner = b.owner 
  20.  and a.owner not in 
  21.  ('SYS', 'SYSTEM', 'OUTLN', 'DMSYS', 'TSMSYS', 'DBSNMP', 'WMSYS', 
  22.  'EXFSYS', 'CTXSYS', 'XDB', 'OLAPSYS', 'ORDSYS', 'MDSYS', 'SYSMAN') 
  23.  and decode(a.num_rows, 
  24.  0, 
  25.  100, 
  26.  (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / 
  27.  b.seg_bytes_mb, 
  28.  2)) * 100) > 30 
  29.  order by b.seg_bytes_mb desc; 

5、性能監(jiān)控

監(jiān)控?cái)?shù)據(jù)庫會(huì)話,是否存在異常等待事件:

 
 
 
 
  1. select inst_id ,sid,serial#,sql_id,event,machine,module,program,seconds_in_wait from gv$session ; 
  2. --看會(huì)話在做什么操作 
  3. select sid, sql_text 
  4.  from v$session a, v$sql b 
  5.  where sid in(85,160) 
  6.  and(b.sql_id = a.sql_id or b.sql_id = a.prev_sql_id); 

本文題目:超詳細(xì)的Oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏
本文路徑:http://m.5511xx.com/article/cdcjosi.html