2021. 11. 11. 16:02ㆍIT
Oracle
SELECT a.tablespace_name AS TablespaceName
, a.file_name FileName
, (a.bytes - b.free) AS Used
, b.free AS Free
, a.bytes Total
FROM (
SELECT file_id
, tablespace_name
, file_name
, SUM(bytes) bytes
FROM dba_data_files
GROUP BY file_id, tablespace_name, file_name) a,
(
SELECT tablespace_name
, file_id
, SUM(NVL(bytes,0)) FREE
FROM dba_free_space
GROUP BY tablespace_name, file_id
) B
WHERE a.tablespace_name = b.tablespace_name
AND a.file_id = b.file_id
MySQL / Maria
SELECT table_schema as "schema"
, IFNULL(table_name,'-') as tablename
, sum(data_length) "data"
, sum(index_length) "index"
, sum(data_length)+sum(index_length) total
FROM information_schema.tables
GROUP BY table_schema, table_name WITH ROLLUP;
MySQL 계열은 실제로 Disk에 쌓이는 용량과 쿼리로 보는 용량차이가 있으므로 쿼리로 보는 용량은 참고용으로만 사용하고 Disk Full 을 방지하려면 물리적 Disk 공간 용량을 확인하면 좋다.
SQL Server
SELECT db.name AS dbname
, SUM(CASE WHEN af.groupid = 0 THEN 0 ELSE af.size / 128.0E END) AS [database]
, SUM(CASE WHEN af.groupid = 0 THEN af.size / 128.0E ELSE 0 END) AS [logs]
, SUM(af.size / 128.0E) AS [total]
FROM master..sysdatabases AS db WITH(NOLOCK) INNER JOIN master..sysaltfiles AS af WITH(NOLOCK)
ON af.[dbid] = db.[dbid]
WHERE db.name NOT IN ('distribution', 'Resource', 'master', 'tempdb', 'model', 'msdb')
AND db.name NOT IN ('Northwind', 'pubs', 'AdventureWorks', 'AdventureWorksDW')
GROUP BY db.name
SELECT t.Name AS TableName
, p.rows AS RowCounts
, CAST(ROUND((SUM(a.used_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS used
, CAST(ROUND((SUM(a.total_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS total
FROM sys.tables t WITH(NOLOCK)
INNER JOIN sys.indexes i WITH(NOLOCK)
ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p WITH(NOLOCK)
ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a WITH(NOLOCK)
ON p.partition_id = a.container_id
INNER JOIN sys.schemas s WITH(NOLOCK)
ON t.schema_id = s.schema_id
GROUP BY t.Name, s.Name, p.Rows
ORDER BY s.Name, t.Name
PostgreSQL
SELECT schemaname
, relname
, pg_total_relation_size(relid) as total_relation_size
, pg_relation_size(relid) as relation_size
, pg_table_size(relid) as table_size
, pg_indexes_size(relid) as index_size
, n_live_tup
, n_dead_tup
, n_tup_ins
, n_tup_upd
, n_tup_del
, n_tup_hot_upd
, last_vacuum
, last_autovacuum
FROM pg_stat_user_tables
ORDER BY 1,2
PG는 접속한 계정의 DB용량만 나오니까 전체 DB들의 용량을 확인하려면 하나하나 다 들어가봐야 전체 용량을 알수 있다.. 그게 제일 불편하지만...
'IT' 카테고리의 다른 글
PostgreSQL Partition Table Full scan bug (0) | 2022.02.24 |
---|---|
ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated ORA-01262: Stat failed on a file destination directory (0) | 2022.02.08 |
PostgreSQL Column alter Test, 속도 테스트 (0) | 2021.11.26 |
Oracle plan_hash_value가 0 값을 가지는 이유 (0) | 2021.11.23 |
안드로이드 스튜디오를 이용해서 Web View (웹앱) URL 연동,, 그냥 따라해보기 (0) | 2021.11.12 |