프린트 하기

OS환경 : Oracle Linux 7.6 (64bit)

 

DB 환경 : Oracle Database 19.10.0.0

 

방법 : 오라클 19c 테이블 move 동일 테이블스페이스 테스트

테이블 용량을 줄이거나 특정 테이블스페이스의 여유공간이 부족 할때

move 명령을(reorg) 사용해 여유 용량을 확보할 수 있음

이때 move를 기존 테이블스페이스가 아닌 다른 테이블스페이스로 이동을 해야만

용량이 줄어든다고 알고있는 경우가 있음

동일 테이블스페이스에 move 할때도 용량 감소 효과가 있는지 확인하는 테스트를 진행함

 

 

테스트 테이블 생성

1
2
3
SQL> create table movetest as select * from dba_objects , (select 1 from dual connect by level <= 5);
 
Table created.

 

 

테스트 테이블의 테이블스페이스 확인

1
2
3
4
5
6
7
8
9
SQL> 
col table_name for a15
col tablespace_name for a30
select table_name, tablespace_name from dba_tables
where table_name = 'MOVETEST';
 
TABLE_NAME  TABLESPACE_NAME
--------------  -------------------------
MOVETEST    USERS

USERS 테이블스페이스에 저장되어 있음

 

 

통계정보 수집

1
SQl> exec dbms_stats.gather_table_stats('IMSI','MOVETEST');

 

 

BLOCKS 확인

1
2
3
4
5
6
7
8
9
10
11
SQL> 
col table_name for a16
select table_name,
   num_rows, 
   blocks
from dba_tables 
where table_name = 'MOVETEST';
 
TABLE_NAME       NUM_ROWS    BLOCKS
---------------- ---------- ----------
MOVETEST         130005      2406

 

 

용량 확인

1
2
3
4
5
6
7
8
9
SQL> 
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST';
 
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST           2432        19

 

 

일부 row 제거

1
2
3
4
5
6
7
SQL> delete movetest where rownum <= 50000;
 
50000 rows deleted.
 
SQL> commit;
 
Commit complete.

 

 

BLOCKS 재확인

1
2
3
4
5
6
7
8
9
10
11
SQL> 
col table_name for a16
select table_name,
   num_rows, 
   blocks
from dba_tables 
where table_name = 'MOVETEST';
 
TABLE_NAME       NUM_ROWS    BLOCKS
---------------- ---------- ----------
MOVETEST         130005      2406

그대로임

 

 

용량 재확인

1
2
3
4
5
6
7
8
9
SQL> 
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST';
 
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST           2432        19

 

 

통계정보 재수집

1
SQL> exec dbms_stats.gather_table_stats('IMSI','MOVETEST');

 

 

통계 수집이후 BLOCKS 재확인

1
2
3
4
5
6
7
8
9
10
11
SQL> 
col table_name for a16
select table_name,
   num_rows, 
   blocks
from dba_tables 
where table_name = 'MOVETEST';
 
TABLE_NAME       NUM_ROWS    BLOCKS
---------------- ---------- ----------
MOVETEST          80005      2406

NUM_ROWS 는 130005에서 80005로 줄어들었지만 BLOCKS는 그대로임

 

 

통계 수집이후 용량 재확인

1
2
3
4
5
6
7
8
9
SQL>
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST';
 
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST           2432        19

그대로임

 

 

동일 테이블스페이스로 move 진행

1
2
3
SQL> alter table movetest move tablespace users;
 
Table altered.

 

 

move 후 BLOCKS 재확인

1
2
3
4
5
6
7
8
9
10
11
SQL> 
col table_name for a16
select table_name,
   num_rows, 
   blocks
from dba_tables 
where table_name = 'MOVETEST';
 
TABLE_NAME       NUM_ROWS    BLOCKS
---------------- ---------- ----------
MOVETEST          80005      2406

그대로임

 

 

move 후 용량 재확인

1
2
3
4
5
6
7
8
9
SQL>
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST';
 
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST           1536        12

BLOCKS와 할당되어있던 용량이 줄어듬

 

 

dba_tables 는 통계 수집 후 정확한 값으로 줄어듬

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SQL>  exec dbms_stats.gather_table_stats('IMSI','MOVETEST');
 
PL/SQL procedure successfully completed.
 
SQL> 
col table_name for a16
select table_name,
   num_rows, 
   blocks
from dba_tables 
where table_name = 'MOVETEST';
 
TABLE_NAME       NUM_ROWS    BLOCKS
---------------- ---------- ----------
MOVETEST          80005      1480

BLOCKS가 줄어듬

 

 

추가 테스트

다른 테이블스페이스로 move 시 용량이 동일한 수준으로 줄어드는지 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
테스트 테이블2 생성
SQL> create table movetest2 as select * from dba_objects , (select 1 from dual connect by level <= 5);
 
Table created.
 
 
TS 조회
SQL> 
col table_name for a15
col tablespace_name for a30
select table_name, tablespace_name from dba_tables
where table_name = 'MOVETEST2';
 
TABLE_NAME  TABLESPACE_NAME
--------------  -------------------------
MOVETEST2    USERS
 
 
용량 조회
SQL> 
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST2';
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST2           2432        19
 
 
일부 데이터 삭제
SQL> 
delete movetest2 where rownum <= 50000;
commit;
 
 
용량 확인(delete 만 했기때문에 변함없음)
SQL> 
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST2';
 
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST2           2432        19
 
 
테이블 기존과 다른 테이블스페이스로 move
통계정보 수집
SQL> alter table movetest2 move tablespace imsits;
SQL> exec dbms_stats.gather_table_stats('IMSI','MOVETEST2');
 
 
용량 확인
SQL>
col segment_name for a16
select segment_name, blocks, bytes/1024/1024 mb 
from dba_segments 
where segment_name = 'MOVETEST2';
 
SEGMENT_NAME         BLOCKS        MB
---------------- ---------- ----------
MOVETEST2           1536        12

 

 

결론 : 어떤 테이블스페이스로 move를 하더라도 리오그 효과가 있음

 

 

참고1. move 시 속도 향상을 위해 parallel 명령도 사용할수 있음

1
2
3
SQL> alter table movetest2 move tablespace imsits parallel 8;
 
Table altered.

 

 

참고2. move 시 online 옵션을 사용할 수 있고 파티션도 move 가능함

1
2
3
4
SQL> 
alter table movetest move tablespace imsits online;
alter table movetest move partition 202301_p tablespace imsits online;
alter table movetest move subpartition 202301_p_01 tablespace imsits online;

 

 

참고3. move 중 Ctrl+C로 중단해도 영향 없음(롤백처럼 시간이 걸린다거나 대기하지 않고 바로 끊김)

1
2
3
4
5
SQL> alter table movetest2 move tablespace imsits parallel 8 online;
^Calter table movetest2 move tablespace imsits parallel 8 online <- 진행중 Ctrl + C 입력
            *
ERROR at line 1:
ORA-01013: user requested cancel of current operation

 

 

참조 : https://positivemh.tistory.com/350

 

오라클 reorg, hwm, shrink, move 설명 및 테스트

OS환경 : Oracle Linux6.8(64bit) DB 환경 : Oracle Database 11.2.0.4 설명 : 오라클 reorg, hwm, shrink, move 테스트 HWM(High Water Mark)란 고수위 즉, 마지막까지 등록된 블록위치임 만약 데이터가 대량으로 지워지면 이

positivemh.tistory.com

https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/managing-tables.html#GUID-3DE67CF4-84C5-4AED-A8A3-B1D28D8EBEF6

https://forums.oracle.com/ords/apexds/post/alter-table-move-partition-in-parallel-4250

https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/ALTER-TABLE.html#GUID-552E7373-BF93-477D-9DA3-B2C9386F2877__I2081902