Oracle/Admin2010. 12. 15. 16:10






Q : 인덱스가 저장되는 테이블 스페이스가 잘못 지정되었을 경우 테이블스페이스를 어떻게 옮길까?


데이터베이스의 버전은 아래와 같다.

SQL> select * from v$version where rownum <=1;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod




우선, 테스트를 위한 테이블 스페이스들과 유저를 생성한다.

SQL> create tablespace test_data
  2  datafile '/u01/app/oracle/oradata/ORCL/test_data01.dbf' size 10m;

Tablespace created.

SQL> create tablespace test_idx
  2  datafile '/u01/app/oracle/oradata/ORCL/test_idx01.dbf' size 10m;

Tablespace created.

SQL> create user test identified by test
  2  default tablespace test_data;
User created.
SQL> grant resource, connect to test;
Grant succeeded.



test 유저로 접속한다.

SQL> conn test/test
Connected.

테이블을 생성하고 데이터를 입력해준다.


SQL> create table t1(col1 number);
Table created.
SQL> insert into t1
  2  select level
  3  from dual
  4  connect by level<=100;
100 rows created.
SQL> commit;
Commit complete.

인덱스를 생성해준다.


SQL> create index t1_col1 on t1(col1);
Index created


생성한 인덱스가 어느 테이블 스페이스에 저장되어 있는지 확인한다.


SQL> select index_name, tablespace_name 
  2  from all_indexes
  3  where index_name = 'T1_COL1';
INDEX_NAME         TABLESPACE_NAME
------------------------------ ------------------------------
T1_COL1          TEST_DATA


TEST_DATA 테이블 스페이스에 저장되어 있을 것이다. 이것을 TEST_IDX 테이블 스페이스로 옮기는 작업을 할 것이다.



SQL> alter index t1_col1 rebuild tablespace test_idx;
Index altered.


다시 한번 인덱스가 어느 테이블 스페이스에 생성되었는지 확인해본다.


SQL> select index_name, tablespace_name 
from all_indexes
where index_name = 'T1_COL1';
  2    3 
INDEX_NAME         TABLESPACE_NAME
------------------------------ ------------------------------
T1_COL1          TEST_IDX


TEST_IDX 테이블 스페이스로 옮겨진 것을 확인할 수 있다.



A : alter index <인덱스명> rebuild tablespace <옮길 테이블 스페이스명>; 구문을 실행한다.

Posted by 자수성가한 부자