重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1214|回复: 0
打印 上一主题 下一主题

[Oracle] 数据库实际数据增长量

[复制链接]
跳转到指定楼层
楼主
发表于 2022-7-28 09:20:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
应用场景:最近遇到客户想知道数据库最近一年以来实际数据的增长量,当时只统计了数据文件的增长的情况,但作为DBA都很清楚,通过查看数据文件的增长情况是不够严谨的, 但当时笔者并没有确认到更合适的sql语句. 所以通过以下测试来验证解决这个问题.
以下语句适用于12C
SELECTa.snap_id,
       a.con_id,
       e.name pdbname,
       c.tablespace_name ts_name,
       to_char(to_date(a.rtime, 'mm/dd/yyyyhh24:mi:ss'),
               'yyyy-mm-dd hh24:mi') rtime,
       round(a.tablespace_size * c.block_size / 1024 / 1024, 2) ts_size_mb,
       round(a.tablespace_usedsize * c.block_size/ 1024 / 1024, 2) ts_used_mb,
       round((a.tablespace_size -a.tablespace_usedsize) * c.block_size / 1024 / 1024,
             2) ts_free_mb,
       round(a.tablespace_usedsize /a.tablespace_size * 100, 2) pct_used
  FROM cdb_hist_tbspc_space_usage a,
       (SELECT tablespace_id,
               nb.con_id,
               substr(rtime, 1, 10) rtime,
               max(snap_id) snap_id
          FROM dba_hist_tbspc_space_usage nb
         group by tablespace_id, nb.con_id, substr(rtime, 1, 10)) b,
       cdb_tablespaces c,
       v$tablespace d,
       V$CONTAINERS e
where a.snap_id = b.snap_id
   and a.tablespace_id = b.tablespace_id
   and a.con_id = b.con_id
   and a.con_id = c.con_id
   and a.con_id = d.con_id
   and a.con_id = e.con_id
   and a.tablespace_id = d.TS#
   and d.NAME = c.tablespace_name
   and to_date(a.rtime, 'mm/dd/yyyyhh24:mi:ss') >= sysdate - 30
order by a.CON_ID,
          a.tablespace_id,
          to_date(a.rtime, 'mm/dd/yyyyhh24:mi:ss') desc;
笔者使用的数据库为oracle 19.14,表testcdb环境下sys用户新建的测试表,表空间为system,将其增加到4049m.
SQL> select bytes/1024/1024 fromuser_segments where segment_name='TEST';
BYTES/1024/1024
---------------
          4049
通过以上查询语句在pl sql中执行,可以看到TS_USED_MB1002.94m增加到5051.88m,数据在整数位吻合.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-4-27 13:15 , Processed in 0.107586 second(s), 23 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表