查询以列出Oracle表空间

时间:2018-12-23 22:36:14

标签: oracle oracle11g

如何通过显示

列出Oracle 所有表空间+ temp表空间

使用一个SQL查询分配空间(MB),已用空间(MB),状态(在线\离线)类型

1 个答案:

答案 0 :(得分:2)

像这样吗?

SQL> set pagesize 100
SQL> set linesize 100
SQL> break on tablespace_name on status on total_mb
SQL> compute sum of used_mb on tablespace_name
SQL> WITH total
  2       AS (  SELECT f.tablespace_name,
  3                    ROUND (SUM (f.bytes) / POWER (2, 20)) total_mb
  4               FROM dba_data_files f
  5           GROUP BY f.tablespace_name),
  6       used
  7       AS (  SELECT s.tablespace_name,
  8                    s.segment_type,
  9                    ROUND (SUM (s.bytes) / POWER (2, 20)) used_mb
 10               FROM dba_segments s
 11           GROUP BY s.tablespace_name, s.segment_type)
 12    SELECT ts.tablespace_name,
 13           ts.status,
 14           t.total_mb,
 15           u.segment_type,
 16           u.used_mb
 17      FROM dba_tablespaces ts
 18           JOIN total t ON t.tablespace_name = ts.tablespace_name
 19           JOIN used u ON u.tablespace_name = ts.tablespace_name
 20  ORDER BY ts.tablespace_name, u.segment_type;

TABLESPACE_NAME                STATUS      TOTAL_MB SEGMENT_TYPE          USED_MB
------------------------------ --------- ---------- ------------------ ----------
APEX                           ONLINE           544 INDEX                     150
                                                    LOBINDEX                    8
                                                    LOBSEGMENT                157
                                                    TABLE                     179
****************************** ********* **********                    ----------
sum                                                                           494
APEX_9695076087226093          ONLINE           200 INDEX                       1
                                                    LOBINDEX                    0
                                                    LOBSEGMENT                  0
                                                    TABLE                       1
****************************** ********* **********                    ----------
sum                                                                             2
SYSAUX                         ONLINE          9816 CLUSTER                     3
                                                    INDEX                     565
                                                    INDEX PARTITION          3198
                                                    LOB PARTITION               0
                                                    LOBINDEX                   46
                                                    LOBSEGMENT                727
                                                    NESTED TABLE                3
                                                    TABLE                     643
                                                    TABLE PARTITION          4017
                                                    TABLE SUBPARTITION          2
****************************** ********* **********                    ----------
sum                                                                          9204
SYSTEM                         ONLINE          1724 CLUSTER                    68
                                                    INDEX                     184
                                                    LOBINDEX                    7
                                                    LOBSEGMENT                 16
                                                    NESTED TABLE                1
                                                    ROLLBACK                    0
                                                    TABLE                     813
****************************** ********* **********                    ----------
sum                                                                          1089
UNDOTBS1                       ONLINE          4608 TYPE2 UNDO                144
****************************** ********* **********                    ----------
sum                                                                           144
USER_DATA                      ONLINE         38820 INDEX                    5335
                                                    LOBINDEX                   40
                                                    LOBSEGMENT               9168
                                                    TABLE                   18104
****************************** ********* **********                    ----------
sum                                                                         32647

30 rows selected.

SQL>