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

来源:互联网 发布:滚动抽奖软件下载 编辑:程序博客网 时间:2024/06/10 07:22

转自: http://www.cnblogs.com/HondaHsu/archive/2009/08/14/1545914.html


select a.tablespace_name,a.bytes bytes_used,b.largest,round(((a.bytes - b.bytes)/a.bytes)*100,2) percent_used
from (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where 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 from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where 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 from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where 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 from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc

2 导入:
SQL> @/home/mzl/percent_used_tablespace.sql
SQL> l
  1  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 from dba_data_files group by tablespace_name) a,
  5  (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
  6  where a.tablespace_name=b.tablespace_name
  7* order by ((a.bytes-b.bytes)/a.bytes) desc
SQL> /



或者创建视图:
SQL>create view percent
SQL>as
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",
SQL>round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
SQL>from
SQL>(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
SQL>(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
SQL>where a.tablespace_name=b.tablespace_name
SQL>order by ((a.bytes-b.bytes)/a.bytes) desc;

SQL> select * from percent;



查看表空间的数据文件是否是自动扩展:
SQL> l
  1* select file_name,tablespace_name,autoextensible from dba_data_files
SQL> /

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                       NO

13 rows selected.


比如表空间PIONEER_INDX已经用了83.33%,数据文件不能自动扩展,可以修改成自动扩展,以免数据写满数据文件。
SQL> alter database
  2  datafile '/u01/disk2/pioneer_indx.dbf'  autoextend on;

Database altered.

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

FILE_NAME                                     TABLESPACE_NAME                AUT
--------------------------------------------- ------------------------------ ---
/u01/disk2/pioneer_indx.dbf                   PIONEER_INDX                   YES


或者给表空间多加一个自动扩展的数据文件,如果有多个硬盘,可以增加多个数据文件(这样多数据库系统的并发性比较好)
SQL> alter tablespace pioneer_indx
  2  add datafile size 30M;

Tablespace altered.

SQL> select file_name,tablespace_name,bytes/1024/1024 "MB"  from dba_data_files
  2  where tablespace_name='PIONEER_INDX';

FILE_NAME                                     TABLESPACE_NAME
--------------------------------------------- ------------------------------
        MB
----------
/u01/disk2/pioneer_indx.dbf                   PIONEER_INDX
         6

/u01/disk5/ORCL/datafile/o1_mf_pioneer__45dpy PIONEER_INDX
fty_.dbf
        30
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 脚被图钉扎了怎么办 电脑中毒了打不开软件怎么办 剑三程序不兼容怎么办 玩无主之地卡怎么办 平台老板跑路了怎么办 qq在苹果下载不了怎么办 下载速度快上传速度慢怎么办 苹果7开网页慢怎么办 为什么浏览器下载视频速度慢怎么办 机连WLAN网速慢怎么办 会声会影卸载后无法重新安装怎么办 电视空间不足无法卸载怎么办 堡垒之夜下载慢怎么办 手机网盘下载速度慢怎么办插件 笔记本电脑显示连接不可用怎么办 蓝魔手机充电慢怎么办 360f4手机充电慢怎么办 vivo卡了怎么办小窍门 白色衣服用84泡后变黄怎么办 用祛斑霜脱皮了怎么办 用祛斑霜脸一直蜕皮怎么办 吃热的就流鼻涕怎么办 键盘qaz失灵其他都没事怎么办 时时彩代理抓了怎么办 6p升级ios11卡顿怎么办 微信弄没了又换号了怎么办 快手账号异常请去激活怎么办 九游账号被转移怎么办 绝地求生刺激战场闪退怎么办 qq回执编号忘了怎么办 电脑开机要用户名和密码怎么办 电脑忘记用户名和密码怎么办 微信账号密码忘了怎么办 开发者账号密保忘记怎么办 华为账号忘记密保问题怎么办 fiyme账号忘记密保怎么办 id忘了密保问题怎么办 vivo账号密码忘记了怎么办 步步高账号密码忘了怎么办 步步高手机账号密码忘了怎么办 康佳电视通行证忘了怎么办