自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

超詳細的Oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

開發(fā) 前端
生產(chǎn)環(huán)境中,經(jīng)常會遇到表由于數(shù)據(jù)不斷插入,導(dǎo)致空間越來越大,由于前期配置問題,沒有做分區(qū)或者其他優(yōu)化,而且生產(chǎn)數(shù)據(jù)實時向表插入。要刪除歷史數(shù)據(jù)來釋放空間。

[[274251]]

概述

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

1、定位存在碎片的對象

使用如下腳本,檢查需要進行碎片整理的對象:

  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

超詳細的oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

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

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

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

  1. select owner,table_name,last_analyzed from dba_tables Where owner='<OWNER>' AND table_name='<TABLE_NAME>'

超詳細的oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

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

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

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

超詳細的oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

3、表碎片整理

3.1 打開行移動

  1. alter table <TABLE_NAME> enable row movement ; 

3.2 進行表收縮

  1. alter table <TABLE_NAME> shrink space cascade ; 

3.3 失效對象編譯

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

運行如下腳本,重新編譯失效對象。

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

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

運行如下腳本,確認對象空間是否已經(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)控數(shù)據(jù)庫會話,是否存在異常等待事件:

  1. select inst_id ,sid,serial#,sql_id,event,machine,module,program,seconds_in_wait from gv$session ; 
  2. --看會話在做什么操作 
  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); 

超詳細的oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

超詳細的oracle數(shù)據(jù)庫表碎片整理規(guī)范,值得收藏

 

責(zé)任編輯:華軒 來源: 今日頭條
相關(guān)推薦

2011-05-19 13:25:12

Oracle數(shù)據(jù)庫碎片

2019-09-10 07:58:01

字符集MySQL數(shù)據(jù)庫

2019-08-21 09:24:59

Oracle規(guī)范進程

2019-08-20 22:06:32

Oracle數(shù)據(jù)庫索引

2019-07-17 07:07:54

MySQL數(shù)據(jù)庫索引

2019-08-05 09:19:45

PG事務(wù)隔離級別數(shù)據(jù)庫

2019-10-12 00:39:23

MySQL數(shù)據(jù)庫Oracle

2019-11-05 14:20:02

Oracle分組函數(shù)數(shù)據(jù)庫

2023-02-28 00:01:53

MySQL數(shù)據(jù)庫工具

2019-08-13 11:53:01

腳本語言AWKBash

2010-04-12 15:53:09

Oracle

2011-04-12 15:00:48

Oracle碎片

2022-03-24 20:44:53

數(shù)據(jù)庫索引SQL

2019-04-02 10:36:17

數(shù)據(jù)庫MySQL優(yōu)化方法

2019-07-31 08:03:45

Oracle數(shù)據(jù)庫巡檢腳本

2011-03-21 13:21:23

數(shù)據(jù)庫開發(fā)規(guī)范

2011-05-26 13:29:30

ORACLE數(shù)據(jù)庫升級

2019-08-01 07:31:51

數(shù)據(jù)庫主機日志

2020-10-26 10:20:20

數(shù)據(jù)庫索引MySQL

2018-12-12 19:10:01

Oracle數(shù)據(jù)庫自動備份
點贊
收藏

51CTO技術(shù)棧公眾號