티스토리 뷰

 


-- 엔진별 용량 확인
SELECT ENGINE
     , COUNT(1) AS 'TABLES'
     , CONCAT(ROUND(SUM(TABLE_ROWS) / (1024 * 1024), 2), 'M') AS 'TABLE_ROWS_SIZE'
     , CONCAT(ROUND(SUM(DATA_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'DATA_SIZE'
     , CONCAT(ROUND(SUM(INDEX_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'IDX_SIZE'
     , CONCAT(ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'TOTAL_SIZE'
     , ROUND(SUM(INDEX_LENGTH) / SUM(DATA_LENGTH), 2) AS 'IDX_FRAC'
  FROM INFORMATION_SCHEMA.TABLES
 GROUP BY ENGINE;

-- 데이터베이스별 용량 확인
SELECT TABLE_SCHEMA AS 'DATABASE_NAME'
     , CONCAT(ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024), 2), 'MB') AS 'TOTAL_SIZE(M)'
     , CONCAT(ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'TOTAL_SIZE(G)'
  FROM INFORMATION_SCHEMA.TABLES
 WHERE TABLE_ROWS IS NOT NULL
 GROUP BY TABLE_SCHEMA;

-- 테이블 총 용량 확인
SELECT COUNT(1) AS 'TABLES'
     , CONCAT(ROUND(SUM(TABLE_ROWS) / (1024 * 1024), 2), 'M') AS 'TABLE_ROWS_SIZE'
     , CONCAT(ROUND(SUM(DATA_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'DATA_SIZE'
     , CONCAT(ROUND(SUM(INDEX_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'IDX_SIZE'
     , CONCAT(ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'TOTAL_SIZE'
     , ROUND(SUM(INDEX_LENGTH) / SUM(DATA_LENGTH), 2) AS 'IDX_FRAC'
  FROM INFORMATION_SCHEMA.TABLES
 WHERE TABLE_ROWS IS NOT NULL;

-- 테이블별 용량 확인
SELECT CONCAT(TABLE_SCHEMA,'.', TABLE_NAME) AS 'TABLE_NAME'
     , CONCAT(ROUND(DATA_LENGTH / (1024 * 1024 * 1024) , 2), 'G') AS 'DATA_SIZE'
     , CONCAT(ROUND(INDEX_LENGTH / (1024 * 1024 * 1024), 2), 'G') AS 'IDX_SIZE'
     , CONCAT(ROUND((DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024 * 1024), 2), 'G') AS 'TOTAL_SIZE'
     , ROUND(INDEX_LENGTH / DATA_LENGTH, 2) AS 'IDX_FRAC'
  FROM INFORMATION_SCHEMA.TABLES
 WHERE TABLE_ROWS IS NOT NULL;

 

'데이터베이스 > SQL' 카테고리의 다른 글

[SQL] PK(Primary Key) 기본 키  (0) 2021.01.28
[SQL] 디자인의 3가지 관계 유형  (0) 2021.01.27
[SQL] Mybatis를 활용한 페이징  (0) 2021.01.22
[SQL] WHERE 1=1 의미  (0) 2021.01.20
[SQL] MySQL SYSDATE() NOW() 차이  (0) 2021.01.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함