oracle 10g数据文件的表空间简单扩展

本文讨论了如何监控并优化数据库表空间使用率,包括添加数据文件以提高存储效率,以及通过SQL查询获取关键指标如使用率、剩余空间等。通过实例展示了如何根据业务需求调整表空间大小,确保系统稳定运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

tablespace使用率已经大于我们的规定阀值(75%);
--简单查看tablespace的使用情况,此语句对添加后的数据文件,如果没有使用的话,是监控不出来的
SELECT D.TABLESPACE_NAME,
      SPACE "SUM_SPACE(MB)",
      BLOCKS SUM_BLOCKS,
      SPACE - NVL(FREE_SPACE, 0) "USED_SPACE(MB)",
      FREE_SPACE "FREE_SPACE(MB)",
      ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 2) "USED(%)",
      ROUND((NVL(FREE_SPACE, 0) / SPACE) * 100, 2) "FREE(%)"
  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(+)
 ORDER BY TABLESPACE_NAME;
--查看tablespace的使用情况,详细语句
select ts.tablespace_name,
       (case
         when size_info.max_size <= 0 then
          size_info.pct_used
         else
          round((1 - size_info.max_megs_available / size_info.max_size) * 100)
       end) pct_used_of_max
  from (select a.tablespace_name,
               round(a.bytes_alloc / 1024 / 1024) megs_alloc,
               round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free,
               round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
               round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) pct_free,
               100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) pct_used,
               round(a.maxbytes / 1048576) max_size,
               round((a.maxbytes - a.bytes_alloc + nvl(b.bytes_free, 0)) /
                     1048576) max_megs_available
          from (select f.tablespace_name,
                       sum(f.bytes) bytes_alloc,
                       sum(decode(f.autoextensible,
                                  'YES',
                                  f.maxbytes,
                                  'NO',
                                  f.bytes)) maxbytes
                  from dba_data_files f
                 group by tablespace_name) a,
               (select f.tablespace_name, sum(f.bytes) bytes_free
                  from dba_free_space f
                 group by tablespace_name) b
         where a.tablespace_name = b.tablespace_name(+)
        union all
        select h.tablespace_name,
               round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc,
               round(sum((h.bytes_free + h.bytes_used) -
                         nvl(p.bytes_used, 0)) / 1048576) megs_free,
               round(sum(nvl(p.bytes_used, 0)) / 1048576) megs_used,
               round((sum((h.bytes_free + h.bytes_used) -
                          nvl(p.bytes_used, 0)) /
                     sum(h.bytes_used + h.bytes_free)) * 100) pct_free,
               100 - round((sum((h.bytes_free + h.bytes_used) -
                                nvl(p.bytes_used, 0)) /
                           sum(h.bytes_used + h.bytes_free)) * 100) pct_used,
               round(sum(f.maxbytes) / 1048576) max_size,
               round(case
                       when sum(f.maxbytes) - sum(nvl(p.bytes_used, 0)) > 0 then
                        (sum(f.maxbytes) - sum(nvl(p.bytes_used, 0))) / 1048576
                       else
                        (sum(nvl(p.bytes_used, 0)) - sum(f.maxbytes)) / 1048576
                     end) max_megs_available
          from sys.v_$temp_space_header h,
               sys.v_$temp_extent_pool  p,
               dba_temp_files           f
         where p.file_id(+) = h.file_id
           and p.tablespace_name(+) = h.tablespace_name
           and f.file_id = h.file_id
           and f.tablespace_name = h.tablespace_name
         group by h.tablespace_name) size_info,
       sys.dba_tablespaces ts
 where ts.tablespace_name = size_info.tablespace_name
   and (case
         when size_info.max_size <= 0 then
          size_info.pct_used
         else
          round((1 - size_info.max_megs_available / size_info.max_size) * 100)
       end) > 60
 order by pct_used_of_max desc, size_info.max_megs_available desc;

--添加数据文件
--按需求我们smalltablespace所以maxisize最大不限不过最大就32GB,按需求是自动扩展,初始大小是1G,每次扩展一个2G;

alter tablespace TEST_11_2 add datafile'+DATADG/trsen/dbf_11_2_12.dbf' size 1024 m AUTOEXTENDON  next 1024 maxsize unlimited ;
alter tablespace TEST_10_2 add datafile'+DATADG/trsen/dbf_10_2_12.dbf' size 1024 m AUTOEXTEND ON next 1024maxsize unlimited;
alter tablespace TEST_10_3 add datafile'+DATADG/trsen/dbf_10_3_13.dbf' size 1024 m AUTOEXTEND ON next 1024maxsize unlimited;

--查看添加后表空间数据文件信息
select * from dba_data_files where tablespace_namein('TEST_11_2','TEST_10_2','TEST_10_3 ');
select * from dba_data_files where tablespace_nameIN('TEST_11_2','TEST_10_2','TEST_10_3 ');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值