表空间和表空间文件的使用情况

有关oracle表空间和表空间文件的查询sql
每张表属于某个表空间,也可以使用分区表空间(多个);表空间可以有多个文件组成。
表空间使用情况

SELECT a.tablespace_name "表空间名",
        total / (1024 * 1024 * 1024) "表空间大小(G)",
        free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
        (total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",
        round((total - free) / total, 4) * 100 "使用率 %"
   FROM (SELECT tablespace_name, SUM(bytes) free
           FROM dba_free_space
          GROUP BY tablespace_name) a,
        (SELECT tablespace_name, SUM(bytes) total
           FROM dba_data_files
          GROUP BY tablespace_name) b
  WHERE a.tablespace_name = b.tablespace_name;

表空间文件使用情况

SELECT b.file_name "物理文件名",
      b.tablespace_name "表空间",
      b.bytes / (1024 * 1024 * 1024) "大小(G)",
      (b.bytes - sum(nvl(a.bytes, 0))) / (1024 * 1024 * 1024) "已使用(G)",
      substr((b.bytes - sum(nvl(a.bytes, 0))) / (b.bytes) * 100, 1, 5) "利用率"
 FROM dba_free_space a, dba_data_files b
WHERE a.file_id = b.file_id
GROUP BY b.tablespace_name, b.file_name, b.bytes
ORDER BY b.tablespace_name;

猜你喜欢

转载自blog.csdn.net/weixin_44153121/article/details/87891981