bbsoft2002 发表于 2011-12-22 08:54

查看Oracle数据库表空间大小,是否需要增加表空间的数据文件

<DIV>
<P><A href="http://space.itpub.net/12778571/viewspace-582695">http://space.itpub.net/12778571/viewspace-582695</A></P>
<P>/*<BR>*时间:2009-04-01<BR>*环境:AIX5.3&nbsp;&nbsp; Oracle10g10.2.0.1.0<BR>*标题:查看<A href="javascript:;" target=_self><U><STRONG><FONT color=#0000ff>Oracle</FONT></STRONG></U></A>数据库表空间大小,是否需要增加表空间的数据文件<BR>*/</P>
<P>&nbsp;&nbsp; 在<A href="javascript:;" target=_self><U><STRONG><FONT color=#0000ff>数据库</FONT></STRONG></U></A><A href="javascript:;" target=_self><U><STRONG><FONT color=#0000ff>管理</FONT></STRONG></U></A>中,磁盘空间不足是DBA都会遇到的问题,问题比较常见。</P>
<P><STRONG>--1查看表空间已经使用的百分比</STRONG><BR>select&nbsp;&nbsp; a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024&nbsp;&nbsp; "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"<BR>from<BR>(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)&nbsp; &nbsp;a,<BR>(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name)&nbsp;&nbsp; b<BR>where&nbsp;&nbsp; a.tablespace_name=b.tablespace_name<BR>order&nbsp; &nbsp;by&nbsp; &nbsp;((a.bytes-b.bytes)/a.bytes)&nbsp;&nbsp; desc</P>
<P>“Sum MB”表示表空间所有的数据文件总共在操作系统占用磁盘空间的大小<BR>比如:test表空间有2个数据文件,datafile1为300MB,datafile2为400MB,那么test表空间的“Sum MB”就是700MB<BR>“userd MB”表示表空间已经使用了多少<BR>“free MB”表示表空间剩余多少<BR>“percent_user”表示已经使用的百分比</P>
<P><STRONG>--2比如从1中查看到MLOG_NORM_SPACE表空间已使用百分比达到90%以上</STRONG>,可以查看该表空间总共有几个数据文件,每个数据文件是否自动扩展,可以自动扩展的最大值。<BR>select&nbsp; &nbsp;file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB"&nbsp; &nbsp;from&nbsp;&nbsp; dba_data_files<BR>&nbsp; where tablespace_name='MLOG_NORM_SPACE';</P>
<P><STRONG>--3比如MLOG_NORM_SPACE表空间</STRONG>目前的大小为19GB,但最大每个数据文件只能为20GB,数据文件快要写满,可以增加表空间的数据文件<BR>用操作系统UNIX、Linux中的df&nbsp;&nbsp; -g命令(查看下可以使用的磁盘空间大小)<BR>获取创建表空间的语句:<BR>select&nbsp;&nbsp; dbms_metadata.get_ddl('TABLESPACE','MLOG_NORM_SPACE')&nbsp; &nbsp;from&nbsp;&nbsp; dual;</P>
<P><BR><STRONG>--4确认磁盘空间足够,增加一个数据文件<BR></STRONG>alter&nbsp;&nbsp; tablespace&nbsp; &nbsp;MLOG_NORM_SPACE<BR>add&nbsp;&nbsp; datafile&nbsp;&nbsp; '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'<BR>size&nbsp; &nbsp;10M&nbsp; &nbsp;autoextend&nbsp;&nbsp; on&nbsp; &nbsp;maxsize&nbsp; &nbsp;20G</P>
<P><BR><STRONG>--5验证已经增加的数据文件</STRONG><BR>select&nbsp;&nbsp; file_name,file_id,tablespace_name&nbsp; &nbsp;from&nbsp;&nbsp; dba_data_files<BR>where&nbsp;&nbsp; tablespace_name='MLOG_NORM_SPACE'</P>
<P><STRONG>--6如果删除表空间数据文件,</STRONG>如下:<BR>alter&nbsp; &nbsp;tablespace&nbsp; &nbsp;MLOG_NORM_SPACE<BR>drop&nbsp;&nbsp; &nbsp;datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'</P><BR></DIV>
页: [1]
查看完整版本: 查看Oracle数据库表空间大小,是否需要增加表空间的数据文件