查看錶空間使用的兩條常用SQL,資料表空間兩條sql

來源:互聯網
上載者:User

查看錶空間使用的兩條常用SQL,資料表空間兩條sql

1. 查看錶空間大小:
SELECT tablespace_name, SUM(bytes)/1024/1024 total FROM DBA_FREE_SPACE GROUP BY tablespace_name ORDER BY 2 DESC;


SQL> SELECT tablespace_name, SUM(bytes)/1024/1024 || 'MB' total FROM DBA_FREE_SPACE GROUP BY tablespace_name ORDER BY 2 DESC;


注意下上面兩條SQL的排序,顯然第一條SQL是我們需要的結果,按照資料表空間大小降序排列。之所以第二條SQL的排序亂,是因為使用了|| 'MB'連接字串,則這個欄位就作為字串類型檢索, 排序時就會按照字元的ASCII進行排序

2. 查看錶空間使用率:
SQL>BREAK ON REPORTSQL>COMPUT SUM OF tbsp_size ON REPORTSQL>compute SUM OF used        ON REPORTSQL>compute SUM OF free         ON REPORT
SQL>COL tbspname     FORMAT     a20          HEADING 'Tablespace Name'SQL>COL tbsp_size       FORMAT     999,999   HEADING 'Size|(MB)'SQL>COL used             FORMAT     999,999    HEADING 'Used|(MB)'SQL>COL free              FORMAT      999,999   HEADING 'Free|(MB)'SQL>COL pct_used       FORMAT     999,999    HEADING '% Used'
SQL>SELECT df.tablespace_name                              tbspname,sum(df.bytes)/1024/1024                                           tbsp_size,nvl(sum(e.used_bytes)/1024/1024,0)                         used,nvl(sum(f.free_bytes)/1024/1024,0)                            free,nvl((sum(e.used_bytes)*100)/sum(df.bytes),0)            pct_usedFROM DBA_DATA_FILES df, (SELECT file_id, SUM(nvl(bytes, 0)) used_bytesFROM dba_extentsGROUP BY file_id) e,(SELECT MAX(bytes) free_bytes, file_idFROM dba_free_spaceGROUP BY file_id) fWHERE e.file_id(+) = df.file_idAND df.file_id = f.file_id(+)GROUP BY df.tablespace_nameORDER BY 5 DESC;



視圖定義:       



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.