메뉴 건너뛰기

조회 수 115 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

MySQL/MariaDB을 사용하다 보면 현재 데이터베이스(Database) 혹은 테이블(Table)에 용량(Size)을 확인해야 하는 경우가 있다. 

DB(디비)가 올라가있는 시스템의 디스크 용량이 모자라거나, 아니면 백업(Backup) 혹은 마이그레이션(Migration) 할때 용량을 알아야 그에 맞게 대응을 할 수 있다. 

그럼 데이터베이스 혹은 테이블별 용량을 확인하는 방법을 알아보도록 하자. 

1. 데이터베이스(Database)별 용량 확인

# 데이터베이스(DataBase)별 용량 확인

SELECT 
	table_schema AS DBMS,
	CONCAT((SUM(data_length + index_length) / 1024 / 1024)," MB") AS "Size"
FROM
	information_schema.TABLES
GROUP BY 
	table_schema;



-----------------------------------------
DBMS  			| Size(MB)
test  			| 82.98437500 MB
test1 			| 30.22327000 MB
information_schema	| 0.15625000 MB 
 

2. 테이블(Table)별 용량 확인

# 테이블(Table)별 용량 확인

SELECT
	concat(table_schema,'.',table_name) AS "table",
	concat(round(data_length/(1024*1024),2)," MB") AS data,
	concat(round(index_length/(1024*1024),2)," MB") AS idx,
	concat(round((data_length+index_length)/(1024*1024),2)," MB") AS total_size,
	round(index_length/data_length,2) idxfrac
FROM 
	information_schema.TABLES
WHERE 
	table_rows is not null;
    
    
    
-----------------------------------------------------------------------------------------
table		|	data	|	idx	|	total_size	|	idxfrac
test.tb_list	|	0.08 MB	|	0.08 MB	|	0.16 MB		|	1.00
test.tb_info	|	0.02 MB	|	0.02 MB	|	0.03 MB		|	1.00
test.tb_test	|	0.02 MB	|	0.00 MB	|	0.02 MB		|	0.00
test.tb_data	|	82.52 MB|	0.02 MB	|	82.53 MB	|	0.00
test.tb_summary	|	0.05 MB	|	0.03 MB	|	0.08 MB		|	0.67

이와 같이 Query(쿼리)만으로도 데이터베이스 / 테이블의 용량을 확인할 수 있다. 


하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved