출처  :  http://kr.forums.oracle.com/forums/thread.jspa?threadID=472027&tstart=180



제품 : ORACLE SERVER

작성날짜 : 2003-01-21


DATAFILE SIZE를 줄이는 방법
=================================================================================================





Explanation
-------------------------------------------------------------------------------------------------

기존의 datafile을 resize하여 늘리거나 줄일 수 있습니다.
datafile size를 증가하는 경우는 disk에 free space만 있다면 다음과 같이 간단합니다.
다음과 같이 늘리면 되나 줄일 경우는 계산을 하여 줄여야 합니다.

<Bulletin No: 10165> 참고


SQL>alter database datafile '/oracle/dbs/toolsORA.dbf' resize 100M;

줄이실 경우는 주의가 필요합니다. 만일 지정한 size만큼 data가 있다면 error가 발생되고 resize되지 않습니다.


SQL> alter database datafile '/oracle/dbs/toolsORA.dbf' resize 100M;
alter database datafile '/oracle/dbs/toolsORA.dbf' resize 100M'
*
ERROR at line 1:
ORA-03297: file contains used data beyond requested RESIZE value



방법1
-------------------------------------------------------------------------------------------------

1) 줄이고자하는 file id를 확인합니다.

SVRMGR> select file_id, file_name from dba_data_files;


2) 얼마를 사용했는지 확인합니다.

SVRMGR> select block_id, blocks from dba_extents
2> where file_id='FILE_ID' order by block_id;

FILE_ID 대신에 줄이려는 file id를 기술합니다.


3) 현재 사용중이 db block size를 확인합니다.

SVRMGR> show parameter db_block_size

만일 2048일 경우 다음과 같이 계산합니다.

2) 에서 조회된 마지막의 block_id, blocks 값을 가지고 계산합니다.
block_id * 2048 + blocks * 2048 의 결과에 한 block더한 값만큼만 줄이는 것이 가능합니다.

만일 마지막으로 조회된 값이 block_id가 578261, blocks가 515일 경우
578261*2048 + 515*2048 =1185333248로 최소한 1.2GB이상은 써야 합니다.


4) 실제 datafile을 줄입니다.

svrmgr>alter database datafile '/oracle/dbs/toolsORA.dbf' resize 1200M;




방법 2
-------------------------------------------------------------------------------------------------

1) 기존의 data export

exp username/password file=filename owner=username log=username.log


2) tablespace drop

svrmgr>drop tablespace tbs including contents;
rm datafile

tbs대신에 작게 만드시려는 tablespace name을 기술합니다.
datafile대신에 tablespace와 연계된 모든 datafile을 remove합니다.


3) tablespace 재생성
svrmgr>create tablespace tbs
datafile '...' size 100M;
원하시는 size로 줄입니다.


4) data import
imp username/password file=filename fromuser=username touser=username commit=y log=imp.log




Example
-------------------------------------------------------------------------------------------------



Reference Documents
-------------------------------------------------------------------------------------------------


+ Recent posts