Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get available space in tablespace for a user (Oracle)

I'm working on a web application where I need to warn the user that they're running out of space in the given db user's tablespace. The application doesn't know the credentials of the db's system user, so I can't query views like dba_users, dba_free_space..etc.

My question is, is there a way in Oracle for a user to find out how much space there is left for them in their tablespace?

Thanks!

like image 1000
Emrah Avatar asked May 13 '11 15:05

Emrah


People also ask

How do I find user quota in tablespace?

The base dictionary view is DBA_TS_QUOTAS to fetch the specific tablespace user quota details. MAX_BYTES column value -1 means unlimited quota for the user for the particular tablespace. DROPPED column determines whether the tablespace is dropped but the quota has been allocated to the user.

How do you find the space in a table?

To get the tablespace for a particular Oracle table: SQL> select tablespace_name from all_tables where owner = 'USR00' and table_name = 'Z303'; To get the tablespaces for all Oracle tables in a particular library: SQL> select table_name, tablespace_name from all_tables where owner = 'USR00';

How much space does Oracle user use?

To find out space allocated, you can query DBA_TS_QUOTAS - if MAX_BYTES = -1 that means unlimited quota allocated to the user onto the following the tablespace. Following query will give you the result.

How do you check the space occupied by a table in Oracle?

Use the radio button to select the table you want to look at and click on Edit (Don't click on the table name link) Click on the Segments tab (and wait...) You will see the size of the table data and the indexes used.


1 Answers

Forgive my ignorance on the subject, for I believed only views available on data storage were dba_free_space etc..

I realized that for the logged user, there are user_free_space.. views for them. Modified version of the query mentioned here would be the answer my question.

Query is as follows: (Getting the space left on the DEFAULT_TABLESPACE of the logged user)

SELECT
  ts.tablespace_name,
  TO_CHAR(SUM(NVL(fs.bytes,0))/1024/1024, '99,999,990.99') AS MB_FREE
FROM
  user_free_space fs,
  user_tablespaces ts,
  user_users us
WHERE
  fs.tablespace_name(+)   = ts.tablespace_name
AND ts.tablespace_name(+) = us.default_tablespace
GROUP BY
  ts.tablespace_name;

It would return free space in MB

like image 153
Emrah Avatar answered Oct 10 '22 21:10

Emrah