Tablespace 관리

Tablespace 관리

데이터베이스를 운영하다 보면 테이블스페이스(tablespace)를 관리해야 하는 상황이 발생한다. 데이터베이스도 결국 파일을 기반으로 만들어지므로 파일의 용량이 비대해지면 문제가 발생하기 때문에 기본적으로 용량이 제한되어 있다.

참조한 사이트

오류 증상

테이블을 생성하려 할 때 다음과 같은 메세지가 나온다

ORA-01658: unable to create INITIAL extent for segment in tablespace SYSTEM

Tablespace 확인하기

다음 구문으로 tablespace의 관리 파일과 여유 공간 등을 확인할 수 있다.

col file_name format a60
col bytes format 999,999,999
col free  format 999,999,999

select a.file_id id, a.file_name, a.bytes, sum(b.bytes) free
    from dba_data_files a,    dba_free_space b
    where a.file_id = b.file_id(+)
    group by a.file_id, a.file_name, a.bytes, a.blocks;

Tablespace 증설

alter database datafile '파일경로' resize 크기; 

파일은 오라클 설치 위치에 존재하며 11g xe의 경우 기본 설치위치를 가정하고 다음과 같은 구문으로 크기를 변경할 수 있다.

alter database datafile 'C:\oraclexe\app\oracle\oradata\XE\system.dbf' resize 500m;

Tablespace 사용자 배정

특정 tablespace에 사용자가 집중되어 있다면 사용자를 분산할 수 있다.

alter user 사용자이름 default tablespace 테이블스페이스명;

Tablespace와 사용자 확인

tablespace에 할당된 사용자는 다음 구문으로 확인 가능하다.

-- tablespace, 파일명, 크기 확인
SELECT TABLESPACE_NAME, FILE_NAME, BYTES FROM dba_data_files;

-- tablespace에 배정된 사용자 확인
SELECT USERNAME, DEFAULT_TABLESPACE FROM dba_users;  

Last updated