oracle查询表空间占用情况,oracle查询表空间的空间占用情况

select a.tablespace_name,a.bytes bytes_used,b.largest,round(((a.bytes - b.bytes)/a.bytes)*100,2) percent_usedfrom (select tablespace_name,sum(bytes) bytes fromdba_data_files group by tablespace_name) a,

(select tablespace_name,sum(bytes) bytes,max(bytes) largest fromdba_free_space group by tablespace_name) bwhere a.tablespace_name=b.tablespace_name order by ((a.bytes - b.bytes) /a.bytes) desc

查询所有表空间的总容量、已经使用、剩余、已经使用的百分比!select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",

round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"

from(select tablespace_name,sum(bytes) bytes fromdba_data_files group by tablespace_name) a,

(select tablespace_name,sum(bytes) bytes,max(bytes) largest fromdba_free_space group by tablespace_name) bwhere a.tablespace_name=b.tablespace_name

order by ((a.bytes-b.bytes)/a.bytes) desc

一般来说可以把上面的复杂的查询语句放入一个文件中,需要时再调用,或者创建一个试图,需要时可以查询。1 写入文件:#vi /home/mzl/percent_used_tablespace.sql

内容:select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",

round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"

from(select tablespace_name,sum(bytes) bytes fromdba_data_files group by tablespace_name) a,

(select tablespace_name,sum(bytes) bytes,max(bytes) largest fromdba_free_space group by tablespace_name) bwhere a.tablespace_name=b.tablespace_name

order by ((a.bytes-b.bytes)/a.bytes) desc2导入:

SQL> @/home/mzl/percent_used_tablespace.sql

SQL>l1 select a.tablespace_name,a.bytes "Sum",a.bytes-b.bytes "used",b.bytes "free",2 round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"

3 from

4 (select tablespace_name,sum(bytes) bytes fromdba_data_files group by tablespace_name) a,5 (select tablespace_name,sum(bytes) bytes,max(bytes) largest fromdba_free_space group by tablespace_name) b6 where a.tablespace_name=b.tablespace_name7* order by ((a.bytes-b.bytes)/a.bytes) desc

SQL> /或者创建视图:

create view percentas

select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",

round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"

from(select tablespace_name,sum(bytes) bytes fromdba_data_files group by tablespace_name) a,

(select tablespace_name,sum(bytes) bytes,max(bytes) largest fromdba_free_space group by tablespace_name) bwhere a.tablespace_name=b.tablespace_name

order by ((a.bytes-b.bytes)/a.bytes) desc;

SQL> select * frompercent;

查看表空间的数据文件是否是自动扩展:

SQL> select file_name,tablespace_name,autoextensible fromdba_data_files

FILE_NAME TABLESPACE_NAME AUT--------------------------------------------- ------------------------------ ---

/u01/app/oracle/oradata/orcl/risenet.dbf RISENET/u01/app/oracle/oradata/orcl/perfstat.dbf PERFSTAT NO/u01/app/oracle/oradata/orcl/example01.dbf EXAMPLE YES/u01/disk1/users01.dbf USERS YES/u01/app/oracle/oradata/orcl/sysaux01.dbf SYSAUX YES/u01/app/oracle/oradata/orcl/undotbs01.dbf UNDOTBS1/u01/disk2/system01.dbf SYSTEM YES/u01/app/oracle/oradata/orcl/undotbs02.dbf UNDOTBS2 NO/u01/disk1/pioneer_data.dbf PIONEER_DATA YES/u01/disk2/pioneer_indx.dbf PIONEER_INDX NO/u01/disk3/pioneer_undo.dbf PIONEER_UNDO NO

FILE_NAME TABLESPACE_NAME AUT--------------------------------------------- ------------------------------ ---

/u01/app/oracle/oradata/orcl/paul01.dbf PAUL NO/u01/disk1/wenchuan.dbf WENCHUAN NO13rows selected.

比如表空间PIONEER_INDX已经用了83.33%,数据文件不能自动扩展,可以修改成自动扩展,以免数据写满数据文件。

SQL> alter database datafile '/u01/disk2/pioneer_indx.dbf'autoextend on;

Database altered.

SQL> select file_name,tablespace_name,autoextensible from dba_data_files where tablespace_name='PIONEER_INDX';

FILE_NAME TABLESPACE_NAME AUT--------------------------------------------- ------------------------------ ---

/u01/disk2/pioneer_indx.dbf PIONEER_INDX YES

或者给表空间多加一个自动扩展的数据文件,如果有多个硬盘,可以增加多个数据文件(这样多数据库系统的并发性比较好)

SQL>alter tablespace pioneer_indx add datafile size 30M;

Tablespace altered.

SQL> select file_name,tablespace_name,bytes/1024/1024 "MB"

fromdba_data_fileswhere tablespace_name='PIONEER_INDX';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值