테이블과 인덱스를 다른 테이블스페이스로 이동하기
사용자가 생성하는 테이블과 인덱스는 지정하지 않으면 default tablespace에 생성된다. default tablespace로 users를 가지는 kang이라는 사용자로 예를 들어보겠다.
SQL> select username, default_tablespace from user_users;
USERNAME DEFAULT_TABLESPACE ------------------------------ ------------------------------ KANG USERS
SQL> create table test(id varchar(10), name varchar(10), 2 constraint test_pk primary key(id));
테이블이 생성되었습니다.
SQL> select table_name, tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ TEST USERS
SQL> select index_name, table_name, tablespace_name from user_indexes;
INDEX_NAME TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ ----------------- TEST_PK TEST USERS
인덱스를 다른 테이블스페이스로 이동(users에서 ts_kang_ind로) SQL> alter index test_pk rebuild 2 tablespace ts_kang_ind;
인덱스가 변경되었습니다.
SQL> select index_name, table_name, tablespace_name from user_indexes;
INDEX_NAME TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ ----------------- TEST_PK TEST TS_KANG_IND
테이블 데이터를 다른 테이블스페이스로 이동(users에서 ts_kang으로) SQL> insert into test values('maddog','강명규');
1 개의 행이 만들어졌습니다.
SQL> alter table test 2 move tablespace ts_kang;
테이블이 변경되었습니다.
SQL> select table_name, tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ TEST TS_KANG
SQL> select * from test;
ID NAME ---------- ---------- maddog 강명규
테이블 생성시 인덱스를 테이블과 다른 테이블스페이스에 생성하는 방법은 다음과 같다. 테이블의 테이터는 ts_kang, 인덱스는 indx 테이블스페이스로 들어가게 된다.
SQL> create table test 2 ( 3 id varchar(10), 4 name varchar(10), 5 constraint test_pk primary key(id) 6 using index tablespace indx 7 storage(initial 1m next 1m pctincrease 0) 8 ) 9 tablespace ts_kang 10 storage(initial 2m next 2m pctincrease 0);
테이블이 생성되었습니다.
위의 예를 아래와 같이 분리하여 처리할 수도 있다.
SQL> create table test 2 ( 3 id varchar(10), 4 name varchar(10) 5 ) 6 tablespace ts_kang 7 storage (initial 2m next 2m pctincrease 0);
테이블이 생성되었습니다.
SQL> alter table test 2 add constraint test_pk primary key(id) 3 using index tablespace indx;
테이블이 변경되었습니다.
실제 설명한대로 되었는지 질의해 보자. SQL> select table_name, tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ TEST TS_KANG
SQL> select index_name, table_name, tablespace_name from user_indexes;
INDEX_NAME TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ ------------------------------ TEST_PK TEST INDX
보너스) temporary tablespace에는 영구적인 테이블,인덱스등을 생성하지 못한다.
SQL> create table aa (id varchar(10))tablespace temp; create table aa (id varchar(10))tablespace temp * 1행에 오류: ORA-02195: PERMANENT 객체를 TEMPORARY 테이블스페이스에서 만들도록 시도합니다
일반 테이블스페이스의 temporary변경은 다음과 같이 할 수 있다. SQL> alter tablespace ts_kang temporary;
테이블 영역이 변경되었습니다.
SQL> select tablespace_name, contents from dba_tablespaces;
TABLESPACE_NAME CONTENTS ------------------------------ --------- SYSTEM PERMANENT RBS PERMANENT USERS PERMANENT TEMP TEMPORARY TOOLS PERMANENT INDX PERMANENT DRSYS PERMANENT TS_KANG TEMPORARY TS_KANG_IND PERMANENT
9 개의 행이 선택되었습니다.
SQL>
| This article comes from dbakorea.pe.kr (Leave this line as is)
|