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

# Determine used and free space in a tablespace

## Use this script to determine total size, used space, free space and percentage of used and free space in all tablespaces.

This small Oracle script can be executed as a script file from the SQL*Plus prompt and reports the total size, used space, free space and percentage of used and free space in all the tablespaces in a database. Very useful for DBAs! The user executing this script should have the select privilege on the dba_free_space and dba_data_files views. The script has been tested on Oracle 8i enterprise and standard editions.

``` /* TOTAL, FREE AND USED SPACE IN TABLESPACES */ SET LINESIZE 100 COLUMN TABLESPACE FORMAT A15 select t.tablespace, t.totalspace as " Totalspace(MB)", round((t.totalspace-fs.freespace),2) as "Used Space(MB)", fs.freespace as "Freespace(MB)", round(((t.totalspace-fs.freespace)/t.totalspace)*100,2) as "% Used", round((fs.freespace/t.totalspace)*100,2) as "% Free" from (select round(sum(d.bytes)/(1024*1024)) as totalspace, d.tablespace_name tablespace from dba_data_files d group by d.tablespace_name) t, (select round(sum(f.bytes)/(1024*1024)) as freespace, f.tablespace_name tablespace from dba_free_space f group by f.tablespace_name) fs where t.tablespace=fs.tablespace order by t.tablespace;
```

Paul S. writes: I find it frustrating to find a freespace tip that does not take into account the fact that if tablespace has no freespace then it in not listed in the table. The simple solution is to place an outer join in the where clause, as use nvl like so:

``` 1> /* TOTAL, FREE AND USED SPACE IN TABLESPACES */ 2> SET LINESIZE 100 3> COLUMN TABLESPACE FORMAT A15 4> select t.tablespace, t.totalspace as " Totalspace(MB)", 5> round((t.totalspace-nvl(fs.freespace,0)),2) as "Used Space(MB)", 6> nvl(fs.freespace,0) as "Freespace(MB)", 7> round(((t.totalspace-nvl(fs.freespace,0))/t.totalspace)*100,2) as "%Used", 8> round((nvl(fs.freespace,0)/t.totalspace)*100,2) as "% Free" 9> from 10> (select round(sum(d.bytes)/(1024*1024)) as totalspace,d.tablespace_name tablespace 11> from dba_data_files d 12> group by d.tablespace_name) t, 13> (select round(sum(f.bytes)/(1024*1024)) as freespace,f.tablespace_name tablespace 14> from dba_free_space f 15> group by f.tablespace_name) fs 16> where t.tablespace=fs.tablespace (+) 17> order by t.tablespace;
```

Note changes on lines 5, 6, 7, 8, & 16.

• More tips: Hundreds of free Oracle tips and scripts.
• Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
• Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
• Best Web Links: Oracle tips, tutorials, and scripts from around the Web.

## SearchDataManagement

• ### Pandemic triggered data security movement to DBaaS

Database-as-a-service technology has aided enterprises tasked with keeping data secure with IT professionals working from home ...

• ### Who belongs on a high-performance data governance team?

Putting together a high-quality data governance team can be a challenge. Explore the necessary team members and best practices ...

• ### Soda launches cloud service to improve data observability

Data quality vendor Soda has had a busy 2021, building out new services and raising funding to help organizations identify and ...

• ### 15 data science tools to consider using in 2021

Numerous tools are available for data science applications. Read about 15, including their features, capabilities and uses, to ...

• ### Insightsoftware acquisition of Izenda targets embedded BI

ERP vendor Insightsoftware acquired embedded analytics specialist Izenda on April 15, marking its second purchase of an embedded ...

• ### Data scientist shortage leaves organizations uncertain

Despite their desire to use data science in their decision-making process, some organizations can't find qualified data ...

## SearchSAP

• ### S/4HANA Cloud SaaS ERP: Buying team overview

SAP's multi-tenant SaaS ERP, S/4HANA Cloud, is a viable choice for companies that need ease in their infrastructure management. ...

• ### SAP forms financial services partnership with Dediq

SAP and financial industry investment firm Dediq are forming a new business unit to develop applications that help banks and ...

• ### Unpatched applications threaten SAP security

Cyberattacks are a significant threat to unpatched, unprotected SAP applications, according to a new threat intelligence report ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Incorporate diversity and inclusion in technology design

DEI in technology is about more than creating a diverse workplace. We talked to a few DEI professionals about how teams build ...

• ### Microsoft previews OpenJDK distro to the delight of devs

In a move meant to attract more Java developers to its Azure cloud and further support the Java community, Microsoft launched a ...

• ### Supreme Court ruling on Java APIs eases developer worries

Now that the Supreme Court has ruled for Google over Oracle in their high-stakes copyright battle over Java APIs, developers can ...

## SearchDataCenter

• ### Programmable processor technology for next-gen data centers

The right processing technology can benefit your data center. Learn about advancements in CPU technologies, recent vendor ...

• ### Data processing units accelerate infrastructure performance

DPUs often run on networking packets to move information in the data center, instead of supporting processing workflows. Get an ...

• ### New Intel Ice Lake processors boost performance, security

Intel launches third-generation Xeon Scalable processors that bolster security, accelerate common data center workloads by 46% on...

## SearchContentManagement

• ### OpenText releases Cloud Editions content services updates

OpenText CE 21.2 includes federated document compliance that extends to Microsoft Office 365, along with a revamped content ...

As the pandemic disrupts paper workflows, Adobe courts small business users with simple webforms, digital signatures and payments...

• ### Know when to use a headless CMS and when it's not worth it

Headless CMSes aren't a silver bullet for every circumstance. Evaluate three solid use cases for a headless CMS and three ...

## SearchHRSoftware

• ### Face mask detection a newcomer to employee surveillance

Face mask detection has emerged as another form of employee surveillance technology, and its adoption may be helped indirectly by...

• ### 20 diversity and inclusion tools to power your DEI program

Diversity and inclusion tools shouldn't replace strategy, but these tools can help companies in multiple ways, from tracking ...

• ### DEI tools arrive at critical time for HR

Employers are being held accountable for meeting diversity, equity and inclusion goals, especially executives. HR vendors are ...

Close