表空间每日增长量统计
11g
SELECT a.snap_id,
c.tablespace_name ts_name,
TO_CHAR (TO_DATE (a.rtime, 'mm/dd/yyyy hh24:mi:ss'),
'yyyy-mm-dd hh24:mi')
rtime,
ROUND (a.tablespace_size * c.block_size / 1024 / 1024 / 1024, 2)
ts_size_gb,
ROUND (a.tablespace_usedsize * c.block_size / 1024 / 1024 / 1024, 2)
ts_used_gb,
ROUND (
(a.tablespace_size - a.tablespace_usedsize)
* c.block_size
/ 1024
/ 1024
/ 1024,
2)
ts_free_gb,
ROUND (a.tablespace_usedsize / a.tablespace_size * 100, 2) pct_used
FROM dba_hist_tbspc_space_usage a,
( SELECT tablespace_id,
SUBSTR (rtime, 1, 10) rtime,
MAX (snap_id) snap_id
FROM dba_hist_tbspc_space_usage nb
GROUP BY tablespace_id, SUBSTR (rtime, 1, 10)) b,
dba_tablespaces c,
v$tablespace d
WHERE a.snap_id = b.snap_id
AND a.tablespace_id = b.tablespace_id
AND a.tablespace_id = d.TS#
AND d.NAME = c.tablespace_name
AND TO_DATE (a.rtime, 'mm/dd/yyyy hh24:mi:ss') >= SYSDATE - 30
ORDER BY a.tablespace_id, TO_DATE (a.rtime, 'mm/dd/yyyy hh24:mi:ss') DESC;
12c
SELECT a.snap_id,
a.con_id,
e.name pdbname,
c.tablespace_name ts_name,
TO_CHAR (TO_DATE (a.rtime, 'mm/dd/yyyy hh24:mi:ss'),
'yyyy-mm-dd hh24:mi')
rtime,
ROUND (a.tablespace_size * c.block_size / 1024 / 1024 / 1024, 2)
ts_size_gb,
ROUND (a.tablespace_usedsize * c.block_size / 1024 / 1024 / 1024, 2)
ts_used_gb,
ROUND (
(a.tablespace_size - a.tablespace_usedsize)
* c.block_size
/ 1024
/ 1024
/ 1024,
2)
ts_free_gb,
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/yyyy hh24:mi:ss') >= SYSDATE - 30
ORDER BY a.CON_ID,
a.tablespace_id,
TO_DATE (a.rtime, 'mm/dd/yyyy hh24:mi:ss') DESC;
11g某一个表空间增长量
SELECT u.snap_id,
TO_CHAR (s.begin_interval_time, 'yyyy-mm-dd hh24') begin_time,
TO_CHAR (s.end_interval_time, 'yyyy-mm-dd hh24') end_time,
t.name,
ROUND (u.tablespace_size * ts.block_size / 1024 / 1024 / 1024, 2)
ts_size_gb,
ROUND (u.tablespace_usedsize * ts.block_size / 1024 / 1024 / 1024, 2)
ts_used_gb,
ROUND (
(u.tablespace_size - u.tablespace_usedsize)
* ts.block_size
/ 1024
/ 1024
/ 1024,
2)
ts_free_gb,
ROUND (u.tablespace_usedsize / u.tablespace_size * 100, 2) pct_used
FROM dba_hist_tbspc_space_usage u,
v$tablespace t,
dba_hist_snapshot s,
dba_tablespaces ts
WHERE u.tablespace_id = t.ts#
AND u.snap_id = s.snap_id
AND t.name = ts.tablespace_name
AND s.instance_number = 1
AND t.name = 'SYSTEM'
AND s.end_interval_time > SYSDATE - 7
ORDER BY snap_id DESC;
数据库每日增长量统计
根据表空间计算
WITH tmp
AS ( SELECT rtime,
SUM (tablespace_usedsize_gb) tablespace_usedsize_gb,
SUM (tablespace_size_gb) tablespace_size_gb
FROM (SELECT rtime,
e.tablespace_id,
(e.tablespace_usedsize)
* (f.block_size)
/ 1024
/ 1024
/ 1024
tablespace_usedsize_gb,
(e.tablespace_size)
* (f.block_size)
/ 1024
/ 1024
/ 1024
tablespace_size_gb
FROM dba_hist_tbspc_space_usage e,
dba_tablespaces f,
v$tablespace g
WHERE e.tablespace_id = g.TS#
AND f.tablespace_name = g.NAME
AND f.contents NOT IN ('TEMPORARY', 'UNDO'))
GROUP BY rtime)
SELECT tmp.rtime,
tablespace_usedsize_gb,
tablespace_size_gb,
(tablespace_usedsize_gb
- LAG (tablespace_usedsize_gb, 1, NULL) OVER (ORDER BY tmp.rtime))
AS DIFF_GB
FROM tmp,
( SELECT MAX (rtime) rtime
FROM tmp
GROUP BY SUBSTR (rtime, 1, 10)) t2
WHERE t2.rtime = tmp.rtime;
WITH tmp
AS ( SELECT MIN (rtime) rtime,
SUM (tablespace_usedsize_gb) tablespace_usedsize_gb,
SUM (tablespace_size_gb) tablespace_size_gb
FROM (SELECT rtime,
e.tablespace_id,
(e.tablespace_usedsize)
* (f.block_size)
/ 1024
/ 1024
/ 1024
tablespace_usedsize_gb,
(e.tablespace_size)
* (f.block_size)
/ 1024
/ 1024
/ 1024
tablespace_size_gb
FROM dba_hist_tbspc_space_usage e,
dba_tablespaces f,
v$tablespace g
WHERE e.tablespace_id = g.TS#
AND f.tablespace_name = g.NAME)
GROUP BY rtime)
SELECT tmp.rtime,
tablespace_usedsize_gb,
tablespace_size_gb,
(tablespace_usedsize_gb
- LAG (tablespace_usedsize_gb, 1, NULL) OVER (ORDER BY tmp.rtime))
AS DIFF_KB
FROM tmp,
( SELECT MIN (rtime) rtime
FROM tmp
GROUP BY SUBSTR (rtime, 1, 10)) t2
WHERE t2.rtime = tmp.rtime
参考:DB宝Oracle查询表空间或数据库的增长量
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现