top of page

QUERY TO GET SIZE OF ALL TABLES IN AN ORACLE DATABASE SCHEMA

Updated: Feb 9, 2020

As a DBA sometimes you need to know how what’s taking space in an Oracle database, or how large is the table you’re working on, here’s a script which answers these questions. It shows the size of all the database objects large than 10 Mb in a particular database schema.

The following columns are returned:

Owner schema.Object name and type (TABLE, INDEX, etc.).Name of the table this object is associated with. E.g. indexes are associated with their parent tables. Database space occupied by the object in megabytes.Tablespace where an object is stored.The number of extents allocated for the object.Size of the initial extent in bytes.Total database size occupied by the parent table. E.g. for indexes it will be the size of the parent * table plus sizes of all the indexes on that table.

DEFINE schema_name = ‘RAJEEV’ ;

(Ex:- Here Rajeev is my schema name you can use your schema which you want to check size)

Query

SELECT * FROM ( SELECT owner, object_name, object_type, table_name, ROUND(bytes)/1024/1024 AS MB, tablespace_name, extents, initial_extent, ROUND(Sum(bytes/1024/1024) OVER (PARTITION BY table_name)) AS total_table_MB FROM ( — Tables SELECT owner, segment_name AS object_name, ‘TABLE’ AS object_type, segment_name AS table_name, bytes, tablespace_name, extents, initial_extent FROM dba_segments WHERE segment_type IN (‘TABLE’, ‘TABLE PARTITION’, ‘TABLE SUBPARTITION’) UNION ALL — Indexes SELECT i.owner, i.index_name AS object_name, ‘INDEX’ AS object_type, i.table_name, s.bytes, s.tablespace_name, s.extents, s.initial_extent 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’) — LOB Segments UNION ALL SELECT l.owner, l.column_name AS object_name, ‘LOB_COLUMN’ AS object_type, l.table_name, s.bytes, s.tablespace_name, s.extents, s.initial_extent FROM dba_lobs l, dba_segments s WHERE s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type = ‘LOBSEGMENT’ — LOB Indexes UNION ALL SELECT l.owner, l.column_name AS object_name, ‘LOB_INDEX’ AS object_type, l.table_name, s.bytes, s.tablespace_name, s.extents, s.initial_extent 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(‘&schema_name’) ) WHERE total_table_MB > 10 ORDER BY total_table_MB DESC, MB DESC /

Join our Telegram group to get free session information and new opportunity.

If interested to learn free join the group


Upcoming Session for Oracle 19c New Features on Saturday 12th October 2019 @7:30 PM IST

1,036 views0 comments

Recent Posts

See All

How to Connect MySQL Without Root Password.

Many times, I got the question from my colleague or training participants, how to login MySQL if I forgot the password. I have explained the process in many times to them but thought to write this sce

Step by Step Oracle 21c Installation on Linux

Oracle Database 21c is the first Oracle database release with CDB-only architecture. Oracle 20c was announced only CDB architecture but it was not release for on premises. Only for Cloud. That's why i

bottom of page