1. MS-SQL
테이블 이름 및 크기 구하기
select table_name = convert(varchar(30), min(o.name)), table_size = ltrim(str(sum(reserved)*8192/1024.,15,0)+'KB')
from sysindexes i inner join sysobjects o on (o.id=i.id)
where i.indid in (0,1,255) and o.xtype='U'
group by i.id;
--------------------------------------------------------------------
테이블 이름, Rows, 테이블크기, Data 크기, Index 크기, Unused
DECLARE @Low bigint
SELECT @Low = low FROM mASter.dbo.spt_values
WHERE number = 1 and type = 'E'
SELECT OBJECT_NAME(tmp.id) AS Name
,convert(char(11),sum(rows)) AS Rows
,ltrim(str(sum(tmp.reserved) * @Low / 1024.,15,0) + ' ' + 'KB') AS Reserved
,ltrim(str(sum(tmp.data) * @Low / 1024.,15,0) + ' ' + 'KB') AS Data
,ltrim(str((sum(tmp.used) - sum(tmp.data)) * @Low / 1024.,15,0) + ' ' + 'KB') AS Index_Size
,ltrim(str((sum(tmp.reserved) - sum(tmp.used)) * @Low / 1024.,15,0) + ' ' + 'KB') AS Unused
FROM (
SELECT obj.id AS id, sum(ind.rows) AS rows, sum(ind.reserved) AS reserved, sum(dpages) AS data,
isnull(sum(used), 0) AS used
FROM sysindexes ind JOIN sysobjects obj ON ind.id = obj.id
WHERE obj.xtype='U' AND ind.indid < 2
GROUP BY obj.id
UNION
SELECT obj.id AS id, 0 AS rows, sum(ind.reserved) AS reserved, isnull(sum(used), 0) AS data,
isnull(sum(used), 0) AS used
FROM sysindexes ind JOIN sysobjects obj ON ind.id = obj.id
WHERE obj.xtype='U' AND ind.indid = 255
GROUP BY obj.id ) tmp
GROUP BY tmp.id
ORDER BY Name
관리하는 DB, Table, index 크기및 해당 Low 갯수를 확인하자.
A. DB 크기
1. sp_helpdb DB 이름
2. sp_helpdb tempDB
자신이 사용하는 DB 이름이나 2번같이 Temp DB의 크기를 알아볼때
사용한다.
B. 로그 크기
1. dbcc sqlperf(logspace)
DB별 로그의 크기를 알려줌
C. 테이블 정보
1. sp_spaceused 테이블이름
테이블이름, Row수, 전체크기, Data 크기, index 크기를 알려줌
2. sp_help 테이블 이름
테이블의 가장 기본적인 속성을 알려줌
3. sp_MSindexspace 테이블이름
인덱스별 개별 크기를 알려줌
============================================================================
2. ORACLE
TABLE SIZE 및 INDEX SIZE(크기) 계산 1. TABLE SIZE 계산 공식(ORACLE BLOCK SIZE : 2K 로 가정) ------------------------------------------------------ $ sqlplus scott/tiger SQL> SELECT GREATEST(4, ceil(ROW_COUNT / ((round(((1958 - (initrans * 23)) * ((100 - PCTFREE) /100)) / ADJ_ROW_SIZE)))) * BLOCK_SIZE) TableSize_Kbytes FROM dual; *. 한 개의 BLOCK에 Available 한 Bytes - 1958 *. 각 initrans 는 23 Bytes *. PCT_FREE : Table 의 pctfree 값(default 10) *. ADJ_ROW_SIZE : 각 row 의 평균 SIZE 추정치 *. ROW_COUNT : table 의 row 의 갯수 *. BLOCK_SIZE : 1 block의 크기 (단위: K) 예) table 이름이 EMP 일 경우 ROW_COUNT : select count(*) from emp; ADJ_ROW_SIZE : analyze table emp compute statistics; (또는 건수가 매우 많을 때에는 compute 대신 estimate 사용) select avg_row_len from user_tables where table_name='EMP'; 2. INDEX SIZE 계산 공식 ----------------------- SQL> SELECT GREATEST(4, (1.01) * ((ROW_COUNT / ((floor(((2048 - 113 - (initrans * 23)) * (1 - (PCTFREE/100))) / ((10 + uniqueness) + number_col_index + (total_col_length)))))) * DB_BLOCK_SIZE)) IndexSize_Kbytes FROM dual; *. 한 개의 block에 available 한 bytes ( 1935 or 2048 - 113 ) *. 각 initrans 는 23 Bytes *. ROW_COUNT : table 의 row 의 갯수 *. PCTFREE : Index 의 pctfree 값(default 10) *. number_col_index : Index 에서 column 의 수 *. total_col_length : Index 의 길이 추정치 *. uniqueness : 만일 unique index 이면 1, non-unique index 이면 0. *. DB_BLOCK_SIZE : 1 lock의 크기 (단위: K) |