Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Determining table size

I'd like to know the size occupied by each table and its details, such as the size of the index for each table,...

the size allocated, and the free space for each table of my database in Oracle.

The "size" of a table can mean many things. I'll cover the many ways that people use to determine the size of an object.

To see how much space is allocated for an object, issue the following query:

```SELECT block,bytes FROM dba_segments
WHERE owner='SCOTT' and segment_name='EMP';
```

In all of these examples, I'll use the SCOTT.EMP table, but you can easily rewrite these examples for your specific needs.

If you calculate statistics on the table, then you can use the average row length and the total number of rows as an estimate of the total space used.

```ANALYZE TABLE scott.emp COMPUTE STATISTICS;
SELECT avg_row_len,num_rows,avg_row_len*num_rows
AS used_space FROM all_tables WHERE owner='SCOTT' and table_name='EMP';
```

You can use similar queries for indexes.

The DBMS_SPACE package can compute how much space is being used, particularly the SPACE_USAGE procedure of this package. For instance, to see the space used by one of your tables, you might used code like the following in SQL*Plus:

```variable unf number;   --unformatted blocks
variable unfb number;  --unformatted bytes
variable fs1 number;   --number of blocks with 0-25% free space
variable fs1b number;  --number of bytes with 0-25% free space
variable fs2 number;   --number of blocks with 25-50% free space
variable fs2b number;  --number of bytes with 25-50% free space
variable fs3 number;   --number of blocks with 50-75% free space
variable fs3b number;  --number of bytes with 25-50% free space
variable fs4 number;   --number of blocks with 75-100% free space
variable fs4b number;  --number of bytes with 25-50% free space variable full number;
--number of full blocks variable fullb number;
--number of full bytes

begin
dbms_space.space_usage('SCOTT','EMP','TABLE',
:unf, :unfb, :fs1, :fs1b, :fs2, :fs2b,
:fs3, :fs3b, :fs4, :fs4b,
:full, :fullb); end; / print unf ; print unfb ; print fs4 ; print fs4b; print fs3 ; print fs3b; print fs2 ; print fs2b; print fs1 ; print fs1b; print full; print fullb;
```

I've put comment besides the variable names to show their meaning.

It is important to note that the SPACE_USAGE procedure details the space used below the table's High Water Mark. Blocks above the HWM are not analyzed in this process.

The DBMS_SPACE.UNUSED_SPACE can be used to determine how space is not being used in the segment. An example of this procedure can be seen below:

```variable totalblk number;
--number of total blocks variable totalbyt number;
--number of total bytes variable unusedblk number;
--number of unused blocks variable unusedbyt number;
--number of unused bytes variable lastextentfile number;
--last used extent file id variable lastextentblk number;
--last used exent block number variable lastusedblk number;
--last used block

begin
dbms_space.unused_space('SCOTT','EMP','TABLE',
:totalblk, :totalbyt,
:unusedblk, :unusedbyt,
:lastextentfile, :lastextentblk,
:lastusedblk);
end;
/

print totalblk;
print totalbyt;
print unusedblk;
print unusedbyt;
print lastextentfile;
print lastextentblk;
print lastusedblk;
```

By taking the total number of blocks and subtracting the unused blocks, you can get a good idea of how many blocks are being used. If you want to know the usage of those blocks, you'll have the use the SPACE_USAGE procedure discussed above.

This was last published in October 2004

## Content

Find more PRO+ content and other member only offers, here.

#### Have a question for an expert?

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### How AI and IoT will influence data management in 2018

AI and IoT will alter the data management landscape in 2018, according to analyst James Kobielus. AI will need regular updates, ...

• ### Apache Hadoop 3.0 goes GA, adds hooks for cloud and GPUs

Is this the post-Hadoop era? Not in the eyes of Hadoop 3.0 backers, who see the latest update to the big data framework ...

• ### Expert: For BI, you must know the data integration process

Understanding the data integration process is central to self-service BI and data architecture design, consultant Rick Sherman ...

• ### Infographic: The evolution of the chief data officer role

The CDO role, which has never been rigidly defined, is undergoing a face-lift as emerging technologies present new opportunities ...

• ### Predictive analytics projects can bolster business decisions

Blind faith in predictive models can result in flawed business decisions. Analytics teams need to manage predictive processes ...

• ### How predictive analytics techniques and processes work

Predictive analytics is no longer confined to data scientists and other highly skilled analysts. But other users need to ...

## SearchSAP

• ### SAP S/4HANA Cloud and indirect access will dominate 2018

Industry experts say SAP S/4HANA Cloud migrations, Leonardo and Cloud Platform are the technology issues for SAP in 2018; on the ...

When a Dutch energy grid provider needed to develop new business apps on top of SAP ERP, it turned to the Mendix RAD platform to ...

• ### SAP's Timo Elliott on enterprise chatbot AI technology

The SAP global innovation evangelist expects AI to affect businesses in three ways: human-computer interaction, automation of ...

## SearchSQLServer

• ### Meltdown and Spectre fixes eyed for SQL Server performance issues

Microsoft has responded to the Spectre and Meltdown chip vulnerabilities with patches and other fixes. But IT teams need to sort ...

• ### Five SQL Server maintenance steps you should take -- ASAP

Putting off SQL Server administration tasks can lead to database problems. Enact these often-neglected maintenance items to help ...

• ### Microsoft Cosmos DB takes Azure databases to a higher level

Azure Cosmos DB brings a new element to the database lineup of Microsoft's cloud platform, offering multiple data models and a ...

## TheServerSide.com

• ### Spring creator Rod Johnson releases API for implementing DevOps

Find out about Rod Johnson's latest project, which promises to simplify the process of implementing DevOps and streamlining the ...

• ### What Java developers need to know about TypeScript syntax

For Java developers transitioning into JavaScript frameworks, like React and Angular, this TypeScript tutorial on syntax will ...

• ### AWS Cloud9 IDE threatens Microsoft developer base

With its Cloud9 IDE, AWS challenges Microsoft where it matters most -- with the developer community, where Microsoft has ...

## SearchDataCenter

• ### Three requirements for a hybrid cloud computing deployment

As the hybrid cloud computing approach gains steam, organizations will need to pay close attention to cross-cloud connectivity ...

• ### Five debunked myths about SSD issues

Solid-state drives are mature now, and the technology has eclipsed hard disk drives with superior performance, manageability and ...

• ### Future data center trends hinge on the edge, cloud and staffing

Edge computing, colocation, cloud and IT staffing issues lead the way as industry analysts make their predictions for the future ...

## SearchContentManagement

• ### Agile content management leads to iterative value

An Agile approach to enterprise content management enables companies to continually improve ECM systems and add value steadily ...

• ### Intelligent information management the next wave for ECM

In a 2018 upgrade, M-Files allows users to search for content in multiple repositories, while also being able to automatically ...

• ### SharePoint integration and implementation best practices

Here are some expert advice and tips, as well common definitions, to help make your SharePoint integration and implementation a ...

## SearchFinancialApplications

• ### Finance IT case study: Reporting secrets of Derek Rose

CEO Sacha Rose says specialist reporting tools have saved the company thousands by avoiding unnecessary mistakes.

• ### WestJet turns to gamification to help its Oracle ERP users soar

WestJet's initial gamification project focuses on expense reporting.

• ### The Transformation of HR is Underway

HR is being transformed while we watch.

Close