Find out free space for every tablespace

From: Michael Kiesel <mkie_at_izb.de>
Date: 1996/01/19
Message-ID: <4do7cl$h1t_at_izb.izb.de>#1/1


I'm looking for an easy way to find out how much space is still free in every tablespace. I know that the views

   dba_data_files
   dba_free_space

are holding information about

  • the size, id (and name etc.) of the datafiles and there association with the tablespaces
  • the size of all free areas in all the datafiles

so

   SELECT tablespace_name, sum(blocks)
   FROM dba_data_files GROUP BY tablespace_name;

yields a list of the total size of all tablespaces whereas

   SELECT tablespace_name, sum(blocks)
   FROM dba_free_space GROUP BY tablespace_name;

yields a list of the total *free* space of all tablespaces.

Now I would like to have the *percentage* of free space to total size for each tablespace. How can I accomplish this in one SQL statement?

My first (naive) approach by joining the two views on the file_id column:

   SELECT fs.tablespace_name, sum(fs.blocks), sum(df.blocks)    FROM dba_free_space fs, dba_data_files df    WHERE fs.file_id=df.file_id
   GROUP by fs.tablespace_name;

are giving a wrong value for the total size if there is more than one free space in a data file ...

Please help!

--
Michael Kiesel
mkie_at_izb.de
Received on Fri Jan 19 1996 - 00:00:00 CET

Original text of this message