Object Count of schema and tablespace
set pagesize 180
col OWNER for a25
break on Tablespace on Owner
column Objects format A20
select Tablespace_Name,Owner,COUNT(*)||' tables' Objects
from DBA_TABLES
group by Tablespace_Name,Owner
union
select Tablespace_Name, Owner, COUNT(*)||' indexes' Objects
from DBA_INDEXES
group by Tablespace_Name, Owner;
Physical Size of the Oracle database (Multi-Tenant)
select con_id, name, open_mode, total_size/1024/1024/1024 "PDB_SIZE_GB" from v$pdbs;
Physical Size of the Oracle Database (Logfile,Tempfile,datafile)
col "Database Size" format a20
col "Free space" format a20
col "Used space" format a20
select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size"
, round(sum(used.bytes) / 1024 / 1024 / 1024 ) -
round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space"
, round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space"
from (select bytes
from v$datafile
union all
select bytes
from v$tempfile
union all
select bytes
from v$log) used
, (select sum(bytes) as p
from dba_free_space) free
group by free.p
/
select
"Reserved_Space(GB)", "Reserved_Space(GB)" - "Free_Space(GB)" "Used_Space(GB)",
"Free_Space(GB)"
from(
select
(select sum(bytes/(1014*1024*1024)) from dba_data_files) "Reserved_Space(GB)",
(select sum(bytes/(1024*1024*1024)) from dba_free_space) "Free_Space(GB)"
from dual
);
Logical Size (Space utilise by the data in the database)
select sum(bytes)/1024/1024/1024 "Size in GB" from dba_segments;
Tablespace Utilisation
Set lines 180 pages 100
Col CONTAINER for a20
col TABLESPACE for a30
with CONT as (select con_id, name from v$containers)
select decode(c.con_id,0,'Database',c.name) CONTAINER,
a.tablespace_name "Tablespace",
round(a.bytes_alloc / 1024 / 1024 / 1024) "Size_GB",
round(maxbytes/1024/1024/1024) "MaxSize_GB",
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024 / 1024) "Used_GB",
round(nvl(b.bytes_free, 0) / 1024 / 1024 / 1024) "Free_GB",
round(maxbytes/1024/1024/1024-(a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024 / 1024) "FreeMaxSize_GB",
100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100,2) "%Used",
round(100*(a.bytes_alloc - nvl(b.bytes_free, 0))/maxbytes,2) "%Used_MaxSize"
from ( select con_id,
tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible, 'YES',f.maxbytes,'NO', f.bytes)) maxbytes
from cdb_data_files f
group by con_id, tablespace_name
) a,
( select ts.con_id,
ts.name tablespace_name,
sum(fs.blocks) * ts.blocksize bytes_free
from CDB_LMT_FREE_SPACE fs,
containers(sys.ts$) ts
where ts.ts# = fs.tablespace_id
and ts.con_id=fs.con_id
group by ts.con_id,ts.name, ts.blocksize
) b,
cont c
where a.tablespace_name = b.tablespace_name (+)
and a.con_id=b.con_id
and a.con_id=c.con_id
---and a.tablespace_name like '%SYSAUX%'
--and a.tablespace_name in ('UNDOTBS1')
order by "%Used_MaxSize" asc;
Schema Size
set linesize 150
set pagesize 5000
col owner for a15
col segment_name for a30
col segment_type for a20
col TABLESPACE_NAME for a30
clear breaks
clear computes
compute sum of SIZE_IN_GB on report
break on report
select OWNER,sum(bytes)/1024/1024/1000 "SIZE_IN_GB" from dba_segments group by owner order by owner;
Tables inside specific Schema with size_in_mb
COLUMN TABLE_NAME FORMAT A32
COLUMN OBJECT_NAME FORMAT A32
COLUMN OWNER FORMAT A10
SELECT
owner,
table_name,
TRUNC(sum(bytes)/1024/1024) MB,
ROUND( ratio_to_report( sum(bytes) ) over () * 100) Percent
FROM
(SELECT segment_name table_name, owner, bytes
FROM dba_segments
WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')
UNION ALL
SELECT i.table_name, i.owner, s.bytes
FROM dba_indexes i, dba_segments s
WHERE s.segment_name = i.index_name
AND s.owner = i.owner
AND s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.segment_name
AND s.owner = l.owner
AND s.segment_type IN ('LOBSEGMENT', 'LOB PARTITION')
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.index_name
AND s.owner = l.owner
AND s.segment_type = 'LOBINDEX')
WHERE owner in UPPER('&owner')
GROUP BY table_name, owner
HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */
ORDER BY SUM(bytes) desc;