

Determining the sizes of Oracle database tables and indexes
source link: https://www.tuicool.com/articles/hit/3QZVnue
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

For one of our projects we store large amounts of timeseries data in an Oracle database. Sometimes we want to get an overview of how big the tables and related indexes are. Some database client tools like Toad for Oracle can show this information directly in their user interface, but if you use other tools like the SQuirreL SQL Client or JetBrains DataGrip you have to gather this information yourself via SQL queries.
DBA_SEGMENTS and DBA_INDEXES
For Oracle databases this meta information is available via the DBA_SEGMENTS and DBA_INDEXES tables. To query the sizes of several tables in MB use the following query:
SELECT segment_name, segment_type, bytes/1024/1024 MB FROM dba_segments WHERE segment_type = 'TABLE' AND segment_name IN ('TABLE_NAME_1', 'TABLE_NAME_2');
This SQL query returns the sizes of TABLE_NAME_1 and TABLE_NAME_2.
If you want to see the sizes of all the indexes that are associated with a table or a set of tables you can use the following query:
SELECT idx.table_name, idx.index_name, SUM(bytes)/1024/1024 MB FROM dba_segments seg, dba_indexes idx WHERE idx.table_owner = 'SCHEMA_NAME' AND idx.table_name IN ('TABLE_NAME_1', 'TABLE_NAME_2') AND idx.owner = seg.owner AND idx.index_name = seg.segment_name GROUP BY idx.index_name, idx.table_name;
Of course, you have to replace SCHEMA_NAME , and TABLE_NAME_x with the names in your database.
Unfortunately, access to this kind of meta information is different for each database system, and the queries above only work for Oracle databases.
Recommend
-
13
Postgres Indexes for ActiveRecord Join Tables in Rails Apps Updated Jun 23, 2020 3 comments 9 minute read ...
-
7
Oracle 19c Automatic Indexing: CBO Incorrectly Using Auto Indexes Part II ( Sleepwalk) September 21, 2020 Posted by Richard Foote in 19c,
-
9
Oracle 19c Automatic Indexing: CBO Incorrectly Using Auto Indexes Part I (Neighborhood Threat) September 18, 2020 Posted by Richard Foote in 1...
-
22
Oracle 19c Automatic Indexing: DDL Statements With Auto Indexes (No Control) September 1, 2020 Posted by Richard Foote in 19c,
-
10
Oracle 19c Automatic Indexing: Dropping Automatic Indexes Part II (New Angels of Promise) August 25, 2020 Posted by Richard Foote in 19c,...
-
10
Oracle 19c Automatic Indexing: Function-Based Indexes? Part II (If You Can See Me) February 5, 2021 Posted by Richard Foote in 19c,
-
6
Determining Sample Sizes for Monte Carlo Integration on JSTORThis site uses cookies to provide you with a better experience. For information on our cookie policy, please visit this page. By...
-
9
Oracle 19c Automatic Indexing: Invisible/Valid Automatic Indexes (Bowie Rare) August 31, 2021 Posted by Richard Foote in 19c,
-
9
"Tmp_table_sizes: 0" in extended slow query log while temp tables are presentDetailsDescription ...
-
7
Defining a character set for a column For Oracle database tables advertisements I am running following query in SQL*Plus
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK