Space oracle query table space occupancy

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
by the Order ((a.bytes -b.bytes) / a.bytes) desc 


general can put the above complex query into a file, and then call when needed, or create a trying, you can query when needed. 
1   written to the file: #vi / Home / MZL / percent_used_tablespace.sql 
content: 
the 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> /



或者创建视图:
create view percent
as
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;

SQL> select * from percent;



查看表空间的数据文件是否是自动扩展:
SQL>  select file_name,tablespace_name,autoextensible from dba_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/YES PIONEER_DATA pioneer_data.dbf
 / u01 / Disk2 / pioneer_indx.dbf PIONEER_INDX NO
 / u01 / disk3 / pioneer_undo.dbf PIONEER_UNDO NO 

FILE_NAME TABLESPACE_NAME the AUT
 ---------------------- ----------------------- --------------------------- --- --- 
/ u01 / App / Oracle / oradata / ORCL / paul01.dbf PAUL NO
 / u01 / disk1 / wenchuan.dbf Wenchuan NO 

13 is rows Selected. 


such as tablespaces it has been used PIONEER_INDX 83. 33 is % data file not automatically extended, it can be modified to automatically expand, so no data is filled with data files. 

SQL> ALTER Database datafile ' /u01/disk2/pioneer_indx.dbf '   AUTOEXTEND ON; 

. Database Altered 

the SQL > SELECT file_name, tablespace_name, autoextensible from dba_data_files   WHERE tablespace_name = ' PIONEER_INDX ' ; 

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


or to add an extra table space automatic extension of data files, if you have multiple hard drives, you can increase the number of data files (so many concurrency database system is better) 
SQL > alter tablespace pioneer_indx add datafile size 30M;

Tablespace altered.

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

Guess you like

Origin www.cnblogs.com/vmsysjack/p/12150823.html