怎么察看Oracle 数据库表空间的使用情况

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么察看Oracle 数据库表空间的使用情况相关的知识,希望对你有一定的参考价值。

查看的方法和详细的操作步骤如下:

1、首先,因为oracle在Linux系统下运行,所以必须连接到Linux系统,如下图所示,然后进入下一步。

2、其次,完成上述步骤后,连接成功,进入Oracle控制台。
 输入命令“sqlplus / as sysdba”,如下图所示,然后进入下一步。

3、接着,完成上述步骤后,在sql命令行上,输入以下代码,如下图所示,然后进入下一步。

4、最后,完成上述步骤后,就可以查看相应的结果了,如下图所示。这样,问题就解决了。

参考技术A oracle 数据库里查看表空间使用状况;
oracle表空间的事情状况要经常查看,一般空闲比例过低的时候就应该考虑增大表看空间了。查看方法如下SQL:

方法一:

select dbf.tablespace_name,
dbf.totalspace "总量(M)",
dbf.totalblocks as 总块数,
dfs.freespace "剩余总量(M)",
dfs.freeblocks "剩余块数",
(dfs.freespace / dbf.totalspace) * 100 "空闲比例"
from (select t.tablespace_name,
sum(t.bytes) / 1024 / 1024 totalspace,
sum(t.blocks) totalblocks
from dba_data_files t
group by t.tablespace_name) dbf,
(select tt.tablespace_name,
sum(tt.bytes) / 1024 / 1024 freespace,
sum(tt.blocks) freeblocks
from dba_free_space tt
group by tt.tablespace_name) dfs
where trim(dbf.tablespace_name) = trim(dfs.tablespace_name)

方法二:

SELECT Total.name "Tablespace Name",
Free_space, (total_space-Free_space) Used_space, total_space
FROM
(select tablespace_name, sum(bytes/1024/1024) Free_Space
from sys.dba_free_space
group by tablespace_name
) Free,
(select b.name, sum(bytes/1024/1024) TOTAL_SPACE
from sys.v_$datafile a, sys.v_$tablespace B
where a.ts# = b.ts#
group by b.name
) Total
WHERE Free.Tablespace_name = Total.name

当发现有的表空间不够的错误时,处理如下:
1:找出该表空间对应的数据文件及路径

select * from dba_data_files t
where t.tablespace_name = 'ARD'

2:增大数据文件

alter database datafile '全路径的数据文件名称' resize ***M

3:增加数据文件

alter tablespace 表空间名称

add datafile '全路径的数据文件名称' ***M

注解:表空间尽量让free百分比保持在10%以上,如果低于10%就增加datafile或者resizedatafile,一般数据文件不要超过2G
参考技术B //查看表空间剩余空间(M)
select tablespace_name,sum(bytes)/1024/1024 free_space
from dba_free_space
group by tablespace_name;
//详细查看表空间使用状况,包括总大小,使用空间,使用率,剩余空间
select t.*
from (SELECT D.TABLESPACE_NAME,
SPACE "SUM_SPACE(M)",
BLOCKS SUM_BLOCKS,
SPACE - NVL(FREE_SPACE, 0) "USED_SPACE(M)",
ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 2) "USED_RATE(%)",
FREE_SPACE "FREE_SPACE(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,
SUM(BLOCKS) BLOCKS
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
UNION ALL --if have tempfile
SELECT D.TABLESPACE_NAME,
SPACE "SUM_SPACE(M)",
BLOCKS SUM_BLOCKS,
USED_SPACE "USED_SPACE(M)",
ROUND(NVL(USED_SPACE, 0) / SPACE * 100, 2) "USED_RATE(%)",
SPACE - USED_SPACE "FREE_SPACE(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,
SUM(BLOCKS) BLOCKS
FROM DBA_TEMP_FILES
GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE,
ROUND(SUM(BLOCKS * 8192) / (1024 * 1024), 2) USED_SPACE
FROM V$SORT_USAGE
GROUP BY TABLESPACE) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE(+)) t
order by "USED_RATE(%)" desc;
SELECT tablespace_name, sum ( blocks ) as free_blk , trunc ( sum ( bytes ) / (1024*1024) ) as free_m, max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks
FROM dba_free_space
GROUP BY tablespace_name;
参考技术C

    查询表空间剩余容量

    select tablespace_name,sum(bytes)/1024/1024  from dba_free_space group by tablespace_name;

    查询表空间总大小

    select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;

参考技术D 系统管理员登陆:
select a.tablespace_name,total,free,total-free used from
( select tablespace_name,sum(bytes)/1024/1024/1024 total from dba_data_files
group by tablespace_name) a,
( select tablespace_name,sum(bytes)/1024/1024/1024 free from dba_free_space
group by tablespace_name) b
where a.tablespace_name=b.tablespace_name;

如何查询oracle表空间使用情况

    查询表空间剩余容量

    select tablespace_name,sum(bytes)/1024/1024  from dba_free_space group by tablespace_name;

    查询表空间总大小

    select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;

参考技术A //查看表空间剩余空间(M)
select tablespace_name,sum(bytes)/1024/1024 free_space
from dba_free_space
group by tablespace_name;
//详细查看表空间使用状况,包括总大小,使用空间,使用率,剩余空间
select t.*
from (SELECT D.TABLESPACE_NAME,
SPACE "SUM_SPACE(M)",
BLOCKS SUM_BLOCKS,
SPACE - NVL(FREE_SPACE, 0) "USED_SPACE(M)",
ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 2) "USED_RATE(%)",
FREE_SPACE "FREE_SPACE(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,
SUM(BLOCKS) BLOCKS
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
UNION ALL --if have tempfile
SELECT D.TABLESPACE_NAME,
SPACE "SUM_SPACE(M)",
BLOCKS SUM_BLOCKS,
USED_SPACE "USED_SPACE(M)",
ROUND(NVL(USED_SPACE, 0) / SPACE * 100, 2) "USED_RATE(%)",
SPACE - USED_SPACE "FREE_SPACE(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,
SUM(BLOCKS) BLOCKS
FROM DBA_TEMP_FILES
GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE,
ROUND(SUM(BLOCKS * 8192) / (1024 * 1024), 2) USED_SPACE
FROM V$SORT_USAGE
GROUP BY TABLESPACE) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE(+)) t
order by "USED_RATE(%)" desc;
SELECT tablespace_name, sum ( blocks ) as free_blk , trunc ( sum ( bytes ) / (1024*1024) ) as free_m, max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks
FROM dba_free_space
GROUP BY tablespace_name;

以上是关于怎么察看Oracle 数据库表空间的使用情况的主要内容,如果未能解决你的问题,请参考以下文章

如何查询oracle表空间使用情况

oracle数据库创建自动增长的表空间语句怎么写?

oracle怎么查看表空间里都有哪些表

oracle数据库创建自动增长的表空间语句怎么写?

oracle查看索引表空间的使用情况

如何查看oracle中某个用户占用表空间大小情况