• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Oracle » Oracle Database » How to check Tablespace in Oracle -Size,Free space,datafiles ,growth

How to check Tablespace in Oracle -Size,Free space,datafiles ,growth

November 7, 2021 by techgoeasy 2 Comments

Here in this article, we will check how to check tablespace  in Oracle database, tablespace free space, tablespace growth information, tablespace size, associated datafiles with tablespace, checking the highest allocated extent in the tablespace

Table of Contents

  • how to check tablespace in oracle
  • To list the Datafiles and Associated Tablespace of a Database
  • How to check oracle tablespace usage
  • How to check highest allocated extent
  • To check the free space , largest free chunk and no of free chunk in tablespace.
  •  How to check tablespace size in oracle
  • To check all tablespace information in the database
  • How to check Oracle tablespace growth history
  • how to check tablespace used by schema in oracle
  • How to list datafiles in tablespace in oracle
  • How to list datafiles with size in tablespace in oracle
  • Recommended  Courses

how to check tablespace in oracle

To list the names and various others parameter of all tablespace in a database, use the following query on the DBA_TABLESPACES view:

SELECT TABLESPACE_NAME "TABLESPACE", EXTENT_MANAGEMENT,FORCE_LOGGING,
BLOCK_SIZE,
SEGMENT_SPACE_MANAGEMENT
FROM DBA_TABLESPACES;
Download

How to check tablespace in Oracle

With CDB Databases, you need to connect to individual PDB and execute the query to check the tablespace. If you want to gather all the tablespace across all the PDBs and Root containers, then you need to fire the below query connected to the root container

select tablespace_name, con_id from cdb_tablespaces;

To list the Datafiles and Associated Tablespace of a Database

To list the names, sizes, and associated tablespace of a database, enter the following query on the DBA_DATA_FILES view

SELECT
FILE_NAME, 
BLOCKS, 
TABLESPACE_NAME
FROM DBA_DATA_FILES;
Download sql

How to check oracle tablespace usage

To produce statistics about free extents and coalescing activity for each tablespace in the database, enter the following query:

set echo off feedback off verify off pages 75
col tablespace_name format a20 head 'Tablespace Name'
col total format 999,999,999,999 head 'Total(KB)'
col used format 999,999,999,999 head 'Used(KB)'
col free format 999,999,999,999 head 'Free(KB)'
col pct format 999 head 'Percent|Used'
break on report
compute sum of total on report
compute sum of used on report
compute sum of free on report
select    tbs.tablespace_name,
tot.bytes/1024 total,
tot.bytes/1024-sum(nvl(fre.bytes,0))/1024 used,
sum(nvl(fre.bytes,0))/1024 free,
(1-sum(nvl(fre.bytes,0))/tot.bytes)*100 pct
from      dba_free_space fre,
(select  tablespace_name, sum(bytes) bytes
from      dba_data_files
group by tablespace_name) tot,
dba_tablespaces tbs
where   tot.tablespace_name    = tbs.tablespace_name
and        fre.tablespace_name(+) = tbs.tablespace_name
group by tbs.tablespace_name, tot.bytes/1024, tot.bytes
union
select    tsh.tablespace_name,
dtf.bytes/1024 total,
sum(nvl(tsh.bytes_used,0))/1024 used,
sum(nvl(tsh.bytes_free,0))/1024 free,
(1-sum(nvl(tsh.bytes_free,0))/dtf.bytes)*100 pct
from             v$temp_space_header tsh,
(select tablespace_name, sum(bytes) bytes
from dba_temp_files
group by tablespace_name) dtf
where   dtf.tablespace_name     = tsh.tablespace_name(+)
group by tsh.tablespace_name, dtf.bytes/1024, dtf.bytes
order by 1
/
Download sql

We have another view dba_tablespace_usage_metrics introduced from 11.2 which can be used to find oracle tablespace utilization. The values reported are in blocks, not bytes, which can be easily computed using the database block size

column value new_value dbblock noprint
select value from v$parameter where name = 'db_block_size';
select tablespace_name,
used_space used_blocks,
(used_space*&dbblocks)/(1024*1024) used_mb,
tablespace_size tablespace_blocks,
(tablespace_size*&dbblocks)/(1024*1024) tablespace_mb,
used_percent
from dba_tablespace_usage_metrics;


How to check highest allocated extent

column file_name format a50;
column tablespace_name format a15;
column highwater format 9999999999;
set pagesize 9999select a.tablespace_name
,a.file_name
,(b.maximum+c.blocks-1)*d.db_block_size highwater
from dba_data_files a
,(select file_id,max(block_id) maximum
from dba_extents
group by file_id) b
,dba_extents c
,(select value db_block_size
from v$parameter
where name='db_block_size') d
where a.file_id = b.file_id
and c.file_id = b.file_id
and c.block_id = b.maximum
order by a.tablespace_name,a.file_name;

To check the free space , largest free chunk and no of free chunk in tablespace.

set feedback off
set echo off
set numwidth 15
set linesize 150
set pages  1000Accept tname Prompt "Enter Tablespace Name : "
Select (Sum(bytes)/1024/1024) Free_space_MB,(max(bytes)/1024/1024) Largest_Free_chunck_MB,count(*) No_of_free_chunk
from dba_free_space where tablespace_name=upper('&tname');
Download sql

 How to check tablespace size in oracle

The below query will provide the tablespace size in MB

Select (sum(bytes)/1024/1024) Space_allocated
from dba_data_files
where tablespace_name=upper('&tname');

Download sql

The below query will provide the tablespace size in GB

Select (sum(bytes)/1024/1024/1024) Space_allocated
from dba_data_files
where tablespace_name=upper('&tname');

If Autoextensible is “On” on the tablespace, then Tablespace can grow without explicitly adding the space. we can use the below query to find the size of the tablespace to which, it can be extended automatically if required

Select (sum(maxbytes)/1024/1024) Space_allocated
from dba_data_files
where tablespace_name=upper('&tname');

For GB


Select (sum(maxbytes)/1024/1024/1024) Space_allocated
from dba_data_files
where tablespace_name=upper('&tname');

To check all tablespace information in the database

set echo off feedback off verify off pages 60col tablespace_name format a16 head 'Tablespace Name'
col initial_extent format 99,999,999 head 'Initial|Extent(K)'
col next_extent format 99,999,999 head 'Next|Extent(K)'
col max_extents format a4 head 'Max|Ext'
col pct_increase format 999 head 'Pct|Inc'
col extent_management format a10 head 'Extent|Management'
col allocation_type format a10 head 'Allocation|Type'
col status format a7 head 'Status'select   tbs.tablespace_name
,           tbs.initial_extent
,           tbs.next_extent
,           decode(tbs.max_extents,2147483645,'UL',tbs.max_extents) max_extents
,           tbs.pct_increase
,           tbs.extent_management
,           tbs.allocation_type
,           tbs.status
from    dba_tablespaces tbs
order by 1
/
Download sql

How to check Oracle tablespace growth history

Starting Oracle 10G, Oracle records tablespaces usage (allocated, used, etc.) in AWR which can be retrieved by querying the data dictionary view dba_hist_tbspc_space_usage. We can use the below script to view the history of tablespace(s) usage and predict the expected growth for the future.

This script is based on AWR. If your AWR retention period is 7 days, this script can only tell the growth history of the last 7 days and predict based on the last 7 day’s growth. I would recommend changing AWR retention to at least 35 days – this will also be more helpful in case of performance tuning situation as you will have a longer window from the past to look into for performance comparisons.

SELECT TO_CHAR (sp.begin_interval_time,'DD-MM-YYYY') days
, ts.tsname
, max(round((tsu.tablespace_size* dt.block_size )/(1024*1024),2) ) cur_size_MB
, max(round((tsu.tablespace_usedsize* dt.block_size )/(1024*1024),2)) usedsize_MB
FROM DBA_HIST_TBSPC_SPACE_USAGE tsu
, DBA_HIST_TABLESPACE_STAT ts
, DBA_HIST_SNAPSHOT sp
, DBA_TABLESPACES dt
WHERE tsu.tablespace_id= ts.ts#
AND tsu.snap_id = sp.snap_id
AND ts.tsname = dt.tablespace_name
AND ts.tsname NOT IN ('SYSAUX','SYSTEM')
GROUP BY TO_CHAR (sp.begin_interval_time,'DD-MM-YYYY'), ts.tsname
ORDER BY ts.tsname, days;

how to check tablespace used by schema in oracle

select distinct tablespace_name from dba_segments where owner='&schema';

How to list datafiles in tablespace in oracle

select file_name from dba_data_files where tablespace_name like '%&tablespace%';

How to list datafiles with size in tablespace in oracle

In MB

select file_name,bytes/1024/1024 from dba_data_files where tablespace_name like '%&tablespace%';

In GB

 select file_name,bytes/1024/1024/1024 from dba_data_files where tablespace_name like '%&tablespace%'; 

I hope you like the queries given in the post for Oracle tablespace. Please do let me know your feedback

Related Articles

oracle create tablespace: This article on how to create tablespace in oracle, various characteristics associated with it and different create tablespace statements
ORA-01652: ORA-01652 error usually because when the tablespace does not have free space in Permanent and Temporary tablespace in oracle database. Check out how to resolve it
shrink datafile in Oracle: Check out how to shrink the datafile and reclaim space on the filesystem. How to resolve ORA-03297
Oracle database administration tutorial: This lists all the Oracle DBA-related stuff. Very helpful for administration
how to change default tablespace in oracle: Default tablespace is the tablespace where the objects are created when no tablespace name is specified by users. Find out how to check default tablespace
How to check temp tablespace in Oracle: This article is about temp tablespace in Oracle, resize the tempfile, drop the temp file, find the temp usage by Session
alter tablespace add datafile: Check out this post on How to add a datafile to tablespace in Oracle, add tempfile to the temporary tablespace, how to add datafile in ASM
https://docs.oracle.com/cd/B28359_01/server.111/b28310/tspaces002.htm

Recommended  Courses

The following are some of the recommended courses you can buy if you want to get a step further

Given below are the links to some of the courses


Oracle DBA 11g/12c – Database Administration for Junior DBA : This course is good for the people who are starting as Junior DBA or aspire to be Oracle DBA. This will provide a good understanding of backup & recovery and General administration tasks
Oracle Database: Oracle 12C R2 RAC Administration : This course covers the installation, administration of Oracle RAC. A good course for Oracle DBA who want to upgrade his skills for Oracle RAC
Oracle Data Guard: Database Administration for Oracle 12C R2 : This course covers the installation, administration of Oracle Dataguard. A good course for Oracle DBA who want to upgrade his skills for Oracle Dataguard

Filed Under: Oracle, Oracle Database, Oracle Sql

Reader Interactions

Comments

  1. BabuReddy says

    July 15, 2021 at 11:20 pm

    tq

    Reply
    • techgoeasy says

      July 24, 2021 at 9:09 am

      Thanks Babu

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • Password Version in oracle
  • How to login as user without changing the password in Oracle database(alter user identified by values)
  • How to check encrypted tablespace in the Database
  • How To Export -Import TDE Master Encryption Key
  • How to Configure Auto Login TDE Wallet

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us