View tablespace usage in Oracle

Source: Internet
Author: User

Before writing a program, you need to implement the function of querying the tablespace usage in the database. Although you do not know the significance of doing it, you have to do the project requirements.

I wrote one and can only find permanent tablespaces. I don't know how to query temp tablespaces. Today I went online to find them and supplemented the SQL statements completely. In fact, I used them to find existing resources and add them to my favorites.

 

Select *
From (select a. tablespace_name tablespacename,
Nvl (A. Bytes/1024/1024, 0) totalsize,
Nvl (B. largest/1024/1024, 0) freesize,
Nvl (A. bytes-B. bytes)/1024/1024, 0) usedsize,
Round (nvl (A. bytes-B. bytes)/A. bytes * 100, 0), 2) usedpercent
From (select tablespace_name, sum (bytes) bytes
From dba_data_files
Group by tablespace_name),
(Select tablespace_name, sum (bytes) bytes, max (bytes) largest
From dba_free_space
Group by tablespace_name) B
Where a. tablespace_name = B. tablespace_name
Order by A. tablespace_name)

Union

Select D. tablespace_name tablespacename,
Nvl (A. Bytes/1024/1024, 0) totalsize,
Nvl (A. Bytes/1024/1024, 0)-nvl (T. bytes, 0)/1024/1024 freesize,
Nvl (T. bytes, 0)/1024/1024 usedsize,
Round (nvl (T. Bytes/a. bytes * 100, 0), 2) usedpercent
From SYS. dba_tablespaces D,
(Select tablespace_name, sum (bytes) bytes
From dba_temp_files
Group by tablespace_name),
(Select tablespace_name, sum (bytes_cached) bytes
From v $ temp_extent_pool
Group by tablespace_name) T
Where D. tablespace_name = A. tablespace_name (+)
And D. tablespace_name = T. tablespace_name (+)
And D. extent_management like 'local'
And D. Contents like 'temporary'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.