Oracle   发布时间:2022-05-17  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Oracle表空间数据库文件收缩案例解析大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我们经常会遇到数据库磁盘空间爆满的问题,或由于归档日志突增、或由于数据文件过多、大导致磁盘使用紧俏。这里主要说的场景是磁盘空间本身很大,但表空间对应的数据文件初始化的时候就直接顶满了磁盘空间,导致经常收到磁盘空间满的报警。

一、错误信息

告警内容如下:

【发现异常】地产客储系统数据库Oracle_192.168.xx.xx,192.168.xx.xx,数据库customer,连接错误,0 ORA-00257: archiver error. Connect internal only,until freed.

【发生时间】2018.07.04 09:12:21

二、错误原因

上述错误一看大致就知道是由于磁盘空间不足,导致归档无法完成所致,我们只需要清理足够的磁盘空间即可。但在磁盘清理的时候发现磁盘空间本身可清理的不多,被很多很大的数据文件占用,而实际使用的segment大小总共不足400G,磁盘空间本身1T,所以我们可以通过收缩数据文件的方式回收磁盘空间。

数据文件初始化方式:

1.我们创表空间一般有两种方式初始化其数据文件,即指定初始大小为32G(很大的值)或指定初始大小为100M(很小的值)然后通过自动扩展方式慢慢按需增长。

2.第一种初始数据文件方法坏处就是开始不管你用不用到那么大,都会占用这么大的磁盘空间(这种数据迁移的时候可以使用)。第二种初始化方法按需增长,比较好的监控实际使用磁盘空间,所以推荐初始值很小,使用自动扩展慢慢增长的方式。

三、处理步骤

1.查看磁盘空间大小

2.查看数据库表空间大小

div class="codecode">
sqlplus -S /nolog  heading on underline on;
column inst_num heading "Inst Num" new_value inst_num format 99999;
column inst_name heading "Instance" new_value inst_name format a12;
column db_name  heading "DB name"  new_value db_name  format a12;
column dbID   heading "DB ID"   new_value dbID   format 9999999999 just c;
prompt
prompt Current Instance
prompt ~~~~~~~~~~~~~~~~
SELEct d.dbID      dbID,d.name      db_name,i.instance_number inst_num,i.instance_name  inst_name
 from v\$database d,v\$instance i;
set term on FeedBACk off lines 130 pagesize 999 tab off trims on
column MB format 999,999,999 heading "@R_14_10586@l MB"
column free format 9,999 heading "Free MB"
column used format 99,999 heading "Used MB"
column Largest format 999,999 heading "LrgstMB"
column tablespace_name format a20 heading "tablespace"
column status format a3 truncated
column max_extents format 99999999999 heading "MaxExt"
col extent_management      for a1 trunc  head "M"
col alLOCATIOn_type       for a1 trunc  head "A"
col Ext_Size for a4 trunc head "Init"
column pfree format a3 trunc heading "%Fr"
break on report
compute sum of MB on report
compute sum of free on report
compute sum of used on report
SELEct 
 d.tablespace_name,decode(d.status,'ONliNE','olN','READ ONLY','R/O',d.status) status,d.extent_management,decode(d.alLOCATIOn_type,'USER','',d.alLOCATIOn_typE) alLOCATIOn_type,(case 
  when initial_extent < 1048576="" then="" lpad(round(initial_extent/1024,0),3)||'k'="" else="" lpad(round(initial_extent/1024/1024,3)||'m'="" end)="" ext_size,nvl="" (a.bytes="" 1024="" 1024,0)="" mb,nvl="" (f.bytes="" 1024="" 1024,0)="" free,(nvl="" (a.bytes="" 1024="" 1024,0)="" -="" nvl="" (f.bytes="" 1024="" 1024,0))="" used,nvl="" (l.large="" 1024="" 1024,0)="" largest,d.max_extents,lpad(round((f.bytes/a.bytes)*100,3)="" pfree,(case="" when="" round(f.bytes/a.bytes*100,0)="">= 20 then ' ' else '*' end) alrt
FROM sys.dba_tablespaces d,@R_607_9579@CT  tablespace_name,SUM(bytes) bytes
  FROM dba_data_files
  GROUP BY tablespace_name) a,SUM(bytes) bytes
  FROM dba_free_space
  GROUP BY tablespace_name) f,MAX(bytes) large
  FROM dba_free_space
  GROUP BY tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
 AND d.tablespace_name = f.tablespace_name(+)
 AND d.tablespace_name = l.tablespace_name(+)
 AND NOT (d.extent_management liKE 'LOCAL' AND d.contents liKE 'TEMPORARY')
union all
SELEct 
 d.tablespace_name,'UNIFORM','U','SYstem','A',0) - NVL (t.bytes / 1024 / 1024,0)) free,NVL (t.bytes / 1024 / 1024,0) used,LPAD(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),(case when nvl(round(((a.bytes-t.bytes)/NVL(a.bytes,100) >= 20 then ' ' else '*' end) alrt
FROM sys.dba_tablespaces d,SUM(bytes) bytes
  FROM dba_temp_files
  GROUP BY tablespace_name order by tablespace_name) a,SUM(bytes_used ) bytes
  FROM v\$temp_extent_pool
  GROUP BY tablespace_name) t,MAX(bytes_cached) large
  FROM v\$temp_extent_pool
  GROUP BY tablespace_name order by tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
 AND d.tablespace_name = t.TABLESPACE_NAME(+)
 AND d.tablespace_name = l.tablespace_name(+)
 AND d.extent_management liKE 'LOCAL'
 AND d.contents liKE 'TEMPORARY'
 ORDER by 1
/
prompt
exit
EOF

大佬总结

以上是大佬教程为你收集整理的Oracle表空间数据库文件收缩案例解析全部内容,希望文章能够帮你解决Oracle表空间数据库文件收缩案例解析所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:非常不错