如何查看表空间使用情况 下载本文

内容发布更新时间 : 2024/5/12 18:43:56星期一 下面是文章的全部内容请认真阅读。

如何查看表空间使用情况

2009-07-25 16:03

select e.tablespace_name 表空间,round(e.总空间,0) \总空间(MB)\剩余空间,0) \剩余空间(MB)\剩余空间/e.总空间*100,0) 剩余空间百分比 from

(select tablespace_name,sum(bytes)/1024/1024 总空间 from dba_data_files group by tablespace_name) e,

(select tablespace_name,sum(bytes)/1024/1024 剩余空间 from dba_free_space group by tablespace_name) f

where e.tablespace_name=f.tablespace_name order by 剩余空间百分比

1. 查看所有表空间大小 Sql代码

1. select tablespace_name,sum(bytes)/1024/1024 from dba_data_files

2. roup by tablespace_name;

2. 未使用的表空间大小 Sql代码

1. select tablespace_name,sum(bytes)/1024/1024 from dba_free_space

2. group by tablespace_name; 3. 所以使用空间可以这样计算 Sql代码

1. select a.tablespace_name,total,free,total-free used from 2. ( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files

3. group by tablespace_name) a,

4. ( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space

5. group by tablespace_name) b

6. where a.tablespace_name=b.tablespace_name; 4. 还有在命令行情况下如何将结果放到一个文件里。 Sql代码

1. SQL> spool out.txt

2. SQL> select * from v$database; 3. SQL> spool off 5.查询所有的表空间 Sql代码

1. select tablespace_name from dba_tablespaces 6.查看表空间中分布的用户信息 Sql代码

1. select tablespace_name, owner,sum(bytes) from dba_segments 2. group by tablespace_name, owner

查看Oracle数据库表空间大小,是否需要增加表空间的数据文件 在数据库管理中,磁盘空间不足是DBA都会遇到的问题,问题比较常见。 1 查看表空间已经使用的百分比 Sql代码

1. select a.tablespace_name,a.bytes/1024/1024 \MB\,(a.bytes-b.bytes)/1024/1024 \MB\,b.bytes/1024/1024 \

MB\,round(((a.bytes-b.bytes)/a.bytes)*100,2) \ 2. from

3. (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,

4. (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b 5. where a.tablespace_name=b.tablespace_name

6. order by ((a.bytes-b.bytes)/a.bytes) desc “Sum MB”表示表空间所有的数据文件总共在操作系统占用磁盘空间的大小 比如:test表空间有2个数据文件,datafile1为300MB,datafile2为400MB,那么test表空间的“Sum MB”就是700MB “userd MB”表示表空间已经使用了多少 “free MB”表示表空间剩余多少

“percent_user”表示已经使用的百分比

2 比如从1中查看到MLOG_NORM_SPACE表空间已使用百分比达到90%以上,可以查看该表空间总共有几个数

据文件,每个数据文件是否自动扩展,可以自动扩展的最大值。 Sql代码

1. select file_name,tablespace_name,bytes/1024/1024 \MB\,maxbytes/1024/1024 \

MB\ from dba_data_files

2. where tablespace_name='MLOG_NORM_SPACE'; 2.1 查看 xxx 表空间是否为自动扩展 Sql代码

1. select

file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files order by file_id desc; 3 比如MLOG_NORM_SPACE表空间目前的大小为19GB,但最大每个数据文件只能为20GB,数据文件快要写满,可以增加表空间的数据文件 用操作系统UNIX、Linux中的df -g命令(查看下可以使用的磁盘空间大小) 获取创建表空间的语句: Sql代码

1. select dbms_metadata.get_ddl('TABLESPACE','MLOG_NORM_SPACE') from dual;

--4确认磁盘空间足够,增加一个数据文件 Sql代码

1. alter tablespace MLOG_NORM_SPACE

2. add datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'

3. size 10M autoextend on maxsize 20G --5验证已经增加的数据文件 Sql代码