oracle计算容量的方式

//查看表和所属表空间

SELECT TABLE_NAME,TABLESPACE_NAME FROM USER_TABLES

------------------------------------------------------------------------------------------------------------------------------------

//查看表占用的大小,其中AAA为数据库块db_block_size的大小(一般为8192)

select owner,table_name,
NUM_ROWS,
BLOCKS*AAA/1024/1024 "Size M",
EMPTY_BLOCKS,
LAST_ANALYZED
from dba_tables
where table_name = 'CARBASE'

--------------------------------------------------------------------------------------------------------------------------------------

//查看表空间大小和剩余大小 根据dba_data_files和dba_free_space统计表空间大小和表空间剩余大小

1、统计增加表空见两种方式的数据文件大小总值,也就是统计表空间总大小。(数据文件有两种方式,一种是设置自增大小,一种是不设置自增大小)

WITH TABLESPACE_TOTAL AS
(
SELECT tablespace_name,sum(MAXBYTES) TOTAL FROM DBA_DATA_FILES T
WHERE T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND T.AUTOEXTENSIBLE='YES' group by tablespace_name
UNION ALL
SELECT tablespace_name,sum(bytes) TOTAL FROM DBA_DATA_FILES T
WHERE T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND T.AUTOEXTENSIBLE='NO' group by tablespace_name
)
SELECT TABLESPACE_NAME,SUM(TOTAL) TOTAL FROM TABLESPACE_TOTAL GROUP BY TABLESPACE_NAME

2、表空间已使用的大小(可以看出dba_free_space表是dba_data_files表的各个数据文件bytes列已经真正使用后剩余大小)

select tablespace_name,FILE_ID,bytes/1024/1024 from dba_free_space
where tablespace_name NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')

3、统计大小

SELECT A.TABLESPACE_NAME,B.TOTAL/1024/1024||'M',(B.TOTAL-A.USE)/1024/1024||'M' FREE FROM
(
select c.tablespace_name,(c.p_use-d.p_free) as use from
(
select tablespace_name,sum(bytes) as p_use from dba_data_files
where tablespace_name NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
group by tablespace_name
) C,
(
select tablespace_name,sum(bytes) as  p_free from dba_free_space
where tablespace_name NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
group by tablespace_name
) D
where C.tablespace_name=D.tablespace_name
) A ,
(
WITH TABLESPACE_TOTAL AS
(
SELECT tablespace_name,sum(MAXBYTES) TOTAL FROM DBA_DATA_FILES T
 WHERE T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND T.AUTOEXTENSIBLE='YES' group by tablespace_name
UNION ALL
SELECT tablespace_name,sum(bytes) TOTAL FROM DBA_DATA_FILES T
WHERE T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND T.AUTOEXTENSIBLE='NO' group by tablespace_name
)
SELECT TABLESPACE_NAME,SUM(TOTAL) TOTAL FROM TABLESPACE_TOTAL GROUP BY TABLESPACE_NAME
) B
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME

--------------------------------------------------------------------------------------------------------------------------------------

 

posted @ 2016-03-16 10:51  收点资料买框架  阅读(420)  评论(0编辑  收藏  举报