码迷,mamicode.com
首页 > 数据库 > 详细

[oracle]表空间情况查看、占用、扩容、使用情况、空间维护等操作

时间:2017-09-15 14:43:22      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:tables   rom   tail   database   超过   next   nts   自动   索引   

--查询表空间使用情况
SELECT Upper(F.TABLESPACE_NAME)         "表空间名",
       D.TOT_GROOTTE_MB                 "表空间大小(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
       To_char(Round(( D.TOT_GROOTTE_MB - F.TOTAL_BYTES ) / D.TOT_GROOTTE_MB * 100, 2), ‘990.99‘)
       || ‘%‘                           "使用比",
       F.TOTAL_BYTES                    "空闲空间(M)",
       F.MAX_BYTES                      "最大块(M)"
FROM   (SELECT TABLESPACE_NAME,
               Round(Sum(BYTES) / ( 1024 * 1024 ), 2) TOTAL_BYTES,
               Round(Max(BYTES) / ( 1024 * 1024 ), 2) MAX_BYTES
        FROM   SYS.DBA_FREE_SPACE
        GROUP  BY TABLESPACE_NAME) F,
       (SELECT DD.TABLESPACE_NAME,
               Round(Sum(DD.BYTES) / ( 1024 * 1024 ), 2) TOT_GROOTTE_MB
        FROM   SYS.DBA_DATA_FILES DD
        GROUP  BY DD.TABLESPACE_NAME) D
WHERE  D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER  BY 1;
-- 查看表空间对象占用情况
Select Segment_Name "段名",
       Segment_Type "段类型",
       TableSpace_Name "表空间",
       Sum(bytes) / 1024 / 1024 "空间占用(MB)"
  From User_Extents
 Group By Segment_Type, Segment_Name, TableSpace_Name
 order by Sum(bytes) / 1024 / 1024 desc;

--查询表空间的free space
select tablespace_name, count(*) AS extends,round(sum(bytes) / 1024 / 1024, 2) AS MB,sum(blocks) AS blocks from dba_free_space group BY tablespace_name;

--查询表空间的总容量
select tablespace_name, sum(bytes) / 1024 / 1024 as MB from dba_data_files group by tablespace_name;
--查询表空间使用率
SELECT total.tablespace_name,
       Round(total.MB, 2)           AS Total_MB,
       Round(total.MB - free.MB, 2) AS Used_MB,
       Round(( 1 - free.MB / total.MB ) * 100, 2)
       || ‘%‘                       AS Used_Pct
FROM   (SELECT tablespace_name,
               Sum(bytes) / 1024 / 1024 AS MB
        FROM   dba_free_space
        GROUP  BY tablespace_name) free,
       (SELECT tablespace_name,
               Sum(bytes) / 1024 / 1024 AS MB
        FROM   dba_data_files
        GROUP  BY tablespace_name) total
WHERE  free.tablespace_name = total.tablespace_name;
-- 查看表空间使用情况
select sum(bytes/1024/1024) sizeMB from dba_free_space z where z.tablespace_name=‘DATA6‘;
-- 查看索引表空间占用
select s.index_name,
       s.table_name,
       s.tablespace_name,
       s.initial_extent,
       s.next_extent
  from user_indexes s
 where s.index_name = ‘PK_LOG_INTER_CALLED_DETAIL‘;
-- 查看表空间文件
select file_name,tablespace_name,bytes/1024/1024 from dba_data_files where tablespace_name=‘USERS‘;
-- 查看表空间剩余
select sum(bytes/1024/1024) sizeMB from dba_free_space z where z.tablespace_name=‘USERS‘;
-- 修改表空间文件大小
alter database datafile ‘/home/oracle/oradata/easyweb/data3_01.dbf‘ resize 10000M MAXSIZE UNLIMITED;
alter database datafile ‘/home/oracle/oradata/easyweb/data6_01.dbf‘ AUTOEXTEND ON NEXT 200M MAXSIZE UNLIMITED;
-- 查看所有表空间文件
SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;
-- 设置表空间自动增加
ALTER DATABASE DATAFILE ‘/data/oradata/easyweb/users01.dbf‘ AUTOEXTEND ON; --打开自动增长
ALTER DATABASE DATAFILE ‘/data/oradata/easyweb/users01.dbf‘ AUTOEXTEND ON NEXT 200M ; --每次自动增长200m
ALTER DATABASE DATAFILE ‘/home/oracle/oradata/easyweb/users01.dbf‘ AUTOEXTEND ON NEXT 200M MAXSIZE 10000M; --每次自动增长200m,数据表最大不超过1G
--MAXSIZE UNLIMITED;

--一个表空间最大为32g,超过32g需要增加,例如:
alter tablespace ZSK ADD  datafile ‘/mc_data/oradata/zsk/zsk_01.dbf‘ SIZE 30G;

[oracle]表空间情况查看、占用、扩容、使用情况、空间维护等操作

标签:tables   rom   tail   database   超过   next   nts   自动   索引   

原文地址:http://www.cnblogs.com/shipixing/p/7526033.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!