Find out free space on tablespace

后端 未结 10 1672
北荒
北荒 2020-12-12 12:21

Our application has failed a few times because an \'ORA-01536: space quota exceeded for tablespace\', and we would like to be able to prevent this by checking regularly the

10条回答
  •  一个人的身影
    2020-12-12 12:34

    Unless I'm mistaken, the above code does not take unallocated space into account, so if you really want to know when you'll hit a hard limit, you should use maxbytes.

    I think the code below does that. It calculates free space as "freespace" + unallocated space.

    select 
         free.tablespace_name,
         free.bytes,
         reserv.maxbytes,
         reserv.bytes,
         reserv.maxbytes - reserv.bytes + free.bytes "max free bytes",
         reserv.datafiles
    from
        (select tablespace_name, count(1) datafiles, sum(maxbytes) maxbytes, sum(bytes) bytes from dba_data_files group by tablespace_name) reserv,
        (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) free
    where free.tablespace_name = reserv.tablespace_name;
    

提交回复
热议问题