-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtablespace_non-temp_compare_total_size.sql
105 lines (97 loc) · 3.61 KB
/
tablespace_non-temp_compare_total_size.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
REM
REM Script: tablespace_non-temp_compare_total_size.sql
REM Author: Quanwen Zhao
REM Dated: Nov 05, 2019
REM
REM Purpose:
REM This SQL script usually uses to compare the difference about total size (using more than one INLINE VIEW) of
REM all of the non-temp tablespaces on Oracle Database.
REM
SET LINESIZE 1000
SET PAGESIZE 1000
COLUMN ts_name FORMAT a25
COLUMN total_mb FORMAT 999,999,999.99
PROMPT =====
PROMPT bytes
PROMPT =====
SELECT ddf.ts_name
, ddf.total_mb
, dt.total_mb
, ddf.total_mb - dt.total_mb
FROM
( SELECT tablespace_name AS ts_name
, SUM(bytes)/1024/1024 AS total_mb
FROM dba_data_files
GROUP BY tablespace_name
) ddf,
(
SELECT ds.tablespace_name AS ts_name
, (ds.used_mb + dfs.free_mb) AS total_mb
FROM
( SELECT tablespace_name
, SUM(bytes)/1024/1024 AS used_mb
FROM dba_segments
GROUP BY tablespace_name
) ds,
( SELECT tablespace_name
, SUM(bytes)/1024/1024 AS free_mb
FROM dba_free_space
GROUP BY tablespace_name
) dfs
WHERE ds.tablespace_name = dfs.tablespace_name
) dt
WHERE ddf.ts_name = dt.ts_name
ORDER BY 1,4
;
-- TS_NAME TOTAL_MB TOTAL_MB DDF.TOTAL_MB-DT.TOTAL_MB
-- ------------------------- --------------- --------------- ------------------------
-- SYSAUX 107,898.00 107,894.38 3.625
-- SYSTEM 139,196.00 139,191.00 5
-- WWW_XXXXXXXXXXX 638,538.00 644,617.06 -6079.0625
-- WWW_YYYYYYYYYYY 4,096.00 4,105.00 -9
-- UNDOTBS1 25,845.00 25,844.00 1
-- USERS 2,758.00 2,757.00 1
--
-- 6 rows selected.
PROMPT ==========
PROMPT user_bytes
PROMPT ==========
SELECT ddf.ts_name
, ddf.total_mb
, dt.total_mb
, ddf.total_mb - dt.total_mb
FROM
( SELECT tablespace_name AS ts_name
, SUM(user_bytes)/1024/1024 AS total_mb
FROM dba_data_files
GROUP BY tablespace_name
) ddf,
(
SELECT ds.tablespace_name AS ts_name
, (ds.used_mb + dfs.free_mb) AS total_mb
FROM
( SELECT tablespace_name
, SUM(bytes)/1024/1024 AS used_mb
FROM dba_segments
GROUP BY tablespace_name
) ds,
( SELECT tablespace_name
, SUM(bytes)/1024/1024 AS free_mb
FROM dba_free_space
GROUP BY tablespace_name
) dfs
WHERE ds.tablespace_name = dfs.tablespace_name
) dt
WHERE ddf.ts_name = dt.ts_name
ORDER BY 1,4
;
-- TS_NAME TOTAL_MB TOTAL_MB DDF.TOTAL_MB-DT.TOTAL_MB
-- ------------------------- --------------- --------------- ------------------------
-- SYSAUX 107,893.00 107,894.38 -1.375
-- SYSTEM 139,191.00 139,191.00 0
-- WWW_XXXXXXXXXXX 638,518.00 644,617.06 -6099.0625
-- WWW_YYYYYYYYYYY 4,095.00 4,105.00 -10
-- UNDOTBS1 25,844.00 25,844.00 0
-- USERS 2,757.00 2,757.00 0
--
-- 6 rows selected.