제 6회 엑셈 수요 세미나 자료
EXEM seminar report no. 006 (2016.06.29)
Research & Contents Team
Table of Agenda
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
01.
02.
03.
[MySQL] Page Dump 분석
[PostgreSQL] Vacuum의 거의 모든 것 (2차)
[MySQL] 통계정보 관리
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
01. [PostgreSQL] Vacuum의 거의 모든 것 (2차)
발표자: 연구컨텐츠팀 김숙진
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
목차
1차
1) Vacuum 정의 및 필요성
2) Vacuum 실행 구조
3) 표준 Vacuum VS Vacuum full (시나리오)
2차
1) dump로 보는 “표준 Vacuum VS Vacuum full”
[PostgreSQL] Vacuum의 거의 모든 것
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
<표준 Vacuum과 Vacuum full 비교 시나리오>
순서 command 순서 command
1. Database 생성 create database vac; 9. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
2. oid 확인 oid2name | grep vac 10. myt 테이블에 vacuum 작업 vacuum myt;
3. 테이블 생성 create table myt(id char(7)); 11. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
4. pg_relation_path 확인 select pg_relation_filepath(‘myt’); 12. myt 테이블에 200부터 11건 삽입
insert into myt select
generate_series(200,210);
5. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 13. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
6. myt 테이블에 100건 삽입
insert into myt select
generate_series(100,199);
14. myt 테이블에 vacuum full 작업 vauum full myt;
7. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 15. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
8. myt 테이블에서 id가 150이상이면
삭제
delete from myt where id>=‘150’; 16. pg_relation_path 확인 select pg_relation_filepath(‘myt’);
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
[postgres@153_40 base]$ createdb vac
[postgres@153_40 base]$ oid2name | grep vac
1254094 vac pg_default
[postgres@153_40 base]$ cd 1254094/
[postgres@153_40 1254094]$ psql -d vac
(postgres@[local]:5432) [vac] > ! pwd
/usr/local/pgsql/data/base/1254094
(postgres@[local]:5432) [vac] > ! ls | head -5
12735
12735_fsm
12735_vm
12737
12737_fsm
(postgres@[local]:5432) [vac] > create table myt(id char(7));
CREATE TABLE
(postgres@[local]:5432) [vac] > select pg_relation_filepath('myt');
pg_relation_filepath
----------------------
base/ 1254094/1254095
(1 row)
(postgres@[local]:5432) [vac] > ! ls -lt 123*
-rw------- 1 postgres postgres 0 Jun 21 16:10 1254094
(postgres@[local]:5432) [vac] > select pg_total_relation_size('myt');
pg_total_relation_size
------------------------
0
(1 row)
1
2
3
4
5
<시나리오>
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
(postgres@[local]:5432) [vac] > insert into myt select generate_series(100,199);
INSERT 0 100
(postgres@[local]:5432) [vac] > select pg_total_relation_size('myt');
pg_total_relation_size
------------------------
8192
(1 row)
(postgres@[local]:5432) [vac] > ! ls –l 1254095
-rw------- 1 postgres postgres 8192 Jun 24 13:59
/usr/local/pgsql/data/base/1254094/1254095
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
6
7
<시나리오> <dump>
000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................<
…
0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001380 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001390 64 00 01 00 02 08 18 00 11 31 39 39 20 20 20 20 >d........199 <
0013a0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
0013b0 63 00 01 00 02 08 18 00 11 31 39 38 20 20 20 20 >c........198 <
…
001980 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001990 34 00 01 00 02 08 18 00 11 31 35 31 20 20 20 20 >4........151 <
0019a0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
0019b0 33 00 01 00 02 08 18 00 11 31 35 30 20 20 20 20 >3........150 <
…
001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 <
100~199
Insert 결과
insert into myt select generate_series(100,199); Page Header
+
Item Pointer
Tuple
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
(postgres@[local]:5432) [vac] > delete from myt where id>='150';
DELETE 50
(postgres@[local]:5432) [vac] > select pg_total_relation_size('myt');
pg_total_relation_size
------------------------
8192
(1 row)
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
8
9
000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................<
…
0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001380 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 <
0013a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
0013b0 63 00 01 20 02 01 18 00 11 31 39 38 20 20 20 20 >c.. .....198 <
…
001980 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 <
0019a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 <
…
001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 <
<dump><시나리오>
delete 후, 150부터 199
까지 xmax가 표시됨
100~149
delete from myt where id>=‘150’; Page Header
+
Item Pointer
Tuple
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
(postgres@[local]:5432) [vac] > vacuum myt;
VACUUM
(postgres@[local]:5432) [vac] > select pg_total_relation_size('myt');
pg_total_relation_size
------------------------
40960
(1 row)
(postgres@[local]:5432) [vac] > ! ls –l 1254095
-rw------- 1 postgres postgres 8192 Jun 24 14:00/usr/local/pgsql/data/base/1254094/1254095
-rw------- 1 postgres postgres 24576 Jun 24 14:00 /usr/local/pgsql/data/base/1254094/1254095_fsm
-rw------- 1 postgres postgres 8192 Jun 24 14:00 /usr/local/pgsaql/data/base/1254094/1254095_vm
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
10
11
000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................<
…
0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001380 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 <
0013a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
0013b0 63 00 01 20 02 01 18 00 11 31 39 38 20 20 20 20 >c.. .....198 <
…
001980 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 <
0019a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 <
…
001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 <
50건에 대한 Item Pointer 삭제
<dump><시나리오>
vacuum myt;
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
(postgres@[local]:5432) [vac] > insert into myt select generate_series(200,210);
INSERT 0 11
(postgres@[local]:5432) [vac] > select pg_total_relation_size('myt');
pg_total_relation_size
------------------------
40960
(1 row)
(postgres@[local]:5432) [vac] > ! ls –l 1254095
-rw------- 1 postgres postgres 8192 Jun 24 14:01 /usr/local/pgsql/data/base/1254094/1254095
-rw------- 1 postgres postgres 24576 Jun 24 14:01 /usr/local/pgsql/data/base/1254094/1254095_fsm
-rw------- 1 postgres postgres 8192 Jun 24 14:01 /usr/local/pgsql/data/base/1254094/1254095_vm
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
13
12
000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................<
…
000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001380 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 <
…
001840 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........<
001850 3e 00 01 20 02 05 18 00 11 31 36 31 20 20 20 20 >>.. .....161 <
001860 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001870 3d 00 01 00 02 08 18 00 11 32 31 30 20 20 20 20 >=........210 <
…
0019a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
0019b0 33 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >3........200 <
0019c0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 <
…
001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 <
<dump><시나리오>
200~210이 delete 된
150 자리부터 reuse 됨
insert into myt select generate_series(200,210);
11건에 대한 Item Pointer 추가
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
000000 07 00 00 00 50 60 0b 1a 00 00 05 00 a8 01 c0 19 >....P`..........<
000010 00 20 04 20 00 00 00 00 e0 9f 40 00 c0 9f 40 00 >. . ......@...@.<
000020 a0 9f 40 00 80 9f 40 00 60 9f 40 00 40 9f 40 00 >..@...@.`.@.@.@.<
000030 20 9f 40 00 00 9f 40 00 e0 9e 40 00 c0 9e 40 00 > .@...@...@...@.<
000040 a0 9e 40 00 80 9e 40 00 60 9e 40 00 40 9e 40 00 >..@...@.`.@.@.@.<
000050 20 9e 40 00 00 9e 40 00 e0 9d 40 00 c0 9d 40 00 > .@...@...@...@.<
000060 a0 9d 40 00 80 9d 40 00 60 9d 40 00 40 9d 40 00 >..@...@.`.@.@.@.<
000070 20 9d 40 00 00 9d 40 00 e0 9c 40 00 c0 9c 40 00 > .@...@...@...@.<
000080 a0 9c 40 00 80 9c 40 00 60 9c 40 00 40 9c 40 00 >..@...@.`.@.@.@.<
000090 20 9c 40 00 00 9c 40 00 e0 9b 40 00 c0 9b 40 00 > .@...@...@...@.<
0000a0 a0 9b 40 00 80 9b 40 00 60 9b 40 00 40 9b 40 00 >..@...@.`.@.@.@.<
0000b0 20 9b 40 00 00 9b 40 00 e0 9a 40 00 c0 9a 40 00 > .@...@...@...@.<
0000c0 a0 9a 40 00 80 9a 40 00 60 9a 40 00 40 9a 40 00 >..@...@.`.@.@.@.<
0000d0 20 9a 40 00 00 9a 40 00 e0 99 40 00 c0 99 40 00 > .@...@...@...@.<
0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
000000 07 00 00 00 78 aa 0b 1a 00 00 01 00 a8 01 60 18 >....x.........`.<
000010 00 20 04 20 00 00 00 00 e0 9f 40 00 c0 9f 40 00 >. . ......@...@.<
000020 a0 9f 40 00 80 9f 40 00 60 9f 40 00 40 9f 40 00 >..@...@.`.@.@.@.<
000030 20 9f 40 00 00 9f 40 00 e0 9e 40 00 c0 9e 40 00 > .@...@...@...@.<
000040 a0 9e 40 00 80 9e 40 00 60 9e 40 00 40 9e 40 00 >..@...@.`.@.@.@.<
000050 20 9e 40 00 00 9e 40 00 e0 9d 40 00 c0 9d 40 00 > .@...@...@...@.<
000060 a0 9d 40 00 80 9d 40 00 60 9d 40 00 40 9d 40 00 >..@...@.`.@.@.@.<
000070 20 9d 40 00 00 9d 40 00 e0 9c 40 00 c0 9c 40 00 > .@...@...@...@.<
000080 a0 9c 40 00 80 9c 40 00 60 9c 40 00 40 9c 40 00 >..@...@.`.@.@.@.<
000090 20 9c 40 00 00 9c 40 00 e0 9b 40 00 c0 9b 40 00 > .@...@...@...@.<
0000a0 a0 9b 40 00 80 9b 40 00 60 9b 40 00 40 9b 40 00 >..@...@.`.@.@.@.<
0000b0 20 9b 40 00 00 9b 40 00 e0 9a 40 00 c0 9a 40 00 > .@...@...@...@.<
0000c0 a0 9a 40 00 80 9a 40 00 60 9a 40 00 40 9a 40 00 >..@...@.`.@.@.@.<
0000d0 20 9a 40 00 00 9a 40 00 e0 99 40 00 c0 99 40 00 > .@...@...@...@.<
0000e0 a0 99 40 00 80 99 40 00 60 99 40 00 40 99 40 00 >..@...@.`.@.@.@.<
0000f0 20 99 40 00 00 99 40 00 e0 98 40 00 c0 98 40 00 > .@...@...@...@.<
000100 a0 98 40 00 80 98 40 00 60 98 40 00 00 00 00 00 >..@...@.`.@.....<
000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
<Page Header + Item Pointer>
Item Pointer
11건 추가됨
insert into myt select
generate_series(200,210);
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
11건 insert
Page Header
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
000000 07 00 00 00 78 aa 0b 1a 00 00 01 00 a8 01 60 18 >....x.........`.<
000010 00 20 04 20 00 00 00 00 e0 9f 40 00 c0 9f 40 00 >. . ......@...@.<
000020 a0 9f 40 00 80 9f 40 00 60 9f 40 00 40 9f 40 00 >..@...@.`.@.@.@.<
000030 20 9f 40 00 00 9f 40 00 e0 9e 40 00 c0 9e 40 00 > .@...@...@...@.<
000040 a0 9e 40 00 80 9e 40 00 60 9e 40 00 40 9e 40 00 >..@...@.`.@.@.@.<
000050 20 9e 40 00 00 9e 40 00 e0 9d 40 00 c0 9d 40 00 > .@...@...@...@.<
000060 a0 9d 40 00 80 9d 40 00 60 9d 40 00 40 9d 40 00 >..@...@.`.@.@.@.<
000070 20 9d 40 00 00 9d 40 00 e0 9c 40 00 c0 9c 40 00 > .@...@...@...@.<
000080 a0 9c 40 00 80 9c 40 00 60 9c 40 00 40 9c 40 00 >..@...@.`.@.@.@.<
000090 20 9c 40 00 00 9c 40 00 e0 9b 40 00 c0 9b 40 00 > .@...@...@...@.<
0000a0 a0 9b 40 00 80 9b 40 00 60 9b 40 00 40 9b 40 00 >..@...@.`.@.@.@.<
0000b0 20 9b 40 00 00 9b 40 00 e0 9a 40 00 c0 9a 40 00 > .@...@...@...@.<
0000c0 a0 9a 40 00 80 9a 40 00 60 9a 40 00 40 9a 40 00 >..@...@.`.@.@.@.<
0000d0 20 9a 40 00 00 9a 40 00 e0 99 40 00 c0 99 40 00 > .@...@...@...@.<
0000e0 a0 99 40 00 80 99 40 00 60 99 40 00 40 99 40 00 >..@...@.`.@.@.@.<
0000f0 20 99 40 00 00 99 40 00 e0 98 40 00 c0 98 40 00 > .@...@...@...@.<
000100 a0 98 40 00 80 98 40 00 60 98 40 00 00 00 00 00 >..@...@.`.@.....<
000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
<Page Header + Item Pointer>
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
001860 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001870 3d 00 01 00 02 08 18 00 11 32 31 30 20 20 20 20 >=........210 <
001880 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001890 3c 00 01 00 02 08 18 00 11 32 30 39 20 20 20 20 ><........209 <
0018a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
0018b0 3b 00 01 00 02 08 18 00 11 32 30 38 20 20 20 20 >;........208 <
0018c0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
0018d0 3a 00 01 00 02 08 18 00 11 32 30 37 20 20 20 20 >:........207 <
0018e0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
0018f0 39 00 01 00 02 08 18 00 11 32 30 36 20 20 20 20 >9........206 <
001900 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001910 38 00 01 00 02 08 18 00 11 32 30 35 20 20 20 20 >8........205 <
001920 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001930 37 00 01 00 02 08 18 00 11 32 30 34 20 20 20 20 >7........204 <
001940 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001950 36 00 01 00 02 08 18 00 11 32 30 33 20 20 20 20 >6........203 <
001960 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001970 35 00 01 00 02 08 18 00 11 32 30 32 20 20 20 20 >5........202 <
001980 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001990 34 00 01 00 02 08 18 00 11 32 30 31 20 20 20 20 >4........201 <
0019a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
0019b0 33 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >3........200 <
<Tuple> 새롭게 Insert된 데이터
insert into myt select generate_series(200,210);
60 98 40 00
00 40 98 60
뒤 세자리 860이
Tuple 첫 항목과 동일
새롭게 Insert된 데이터
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
(postgres@[local]:5432) [vac] > vacuum full myt;
VACUUM
(postgres@[local]:5432) [vac] > select pg_total_relation_size('myt');
pg_total_relation_size
------------------------
8192
(1 row)
(postgres@[local]:5432) [vac] > select pg_relation_filepath('myt');
pg_relation_filepath
----------------------
/base/1254094/1254098
(1 row)
원래 pg_relation_filepath
base/ 1254094/1254095
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
14
15
16
<시나리오>
000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................<
…
000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001860 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001870 3d 00 01 00 02 0b 18 00 11 32 31 30 20 20 20 20 >=........210 <
001880 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
001890 3c 00 01 00 02 0b 18 00 11 32 30 39 20 20 20 20 ><........209 <
…
0019a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............<
0019b0 33 00 01 00 02 0b 18 00 11 32 30 30 20 20 20 20 >3........200 <
0019c0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
0019d0 32 00 01 00 02 0b 18 00 11 31 34 39 20 20 20 20 >2........149 <
…
001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............<
001ff0 01 00 01 00 02 0b 18 00 11 31 30 30 20 20 20 20 >.........100 <
<dump>
200~210 삽입된 튜플을
제외하고, 그 뒤에
161~199 삭제
vauum full myt; Page Header
+
Item Pointer
200~210
Tuple
100~149
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
1. Dump로 보는 “표준 Vacuum VS Vacuum full”
Page Header
+
Item Pointer
Tuple
insert into myt select generate_series(100,199);
100건에 대한 Page Header와
Item Pointer 생성
100건에 대한 tuple 생성
delete from myt where id>=‘150’; 변경 X delete 후, 150부터 199까지 xmax 표시
vacuum myt; 50건에 대한 Item Pointer 삭제 변경 X
insert into myt select generate_series(200,210); 11건에 대한 Item Pointer 생성 200~210이 150 자리부터 reuse 됨
vauum full myt; 변경 X
200~210 삽입된 튜플을 제외하고,
그 뒤에 161~199 삭제
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
1. DB 생성 후, 무엇이 생성되는가?
2. Vacuum Full하면 새로운 파일이 생성되는데, 이전의 파일은 계속 있는가?
3. Delete 후 바로 Insert 하면, Delete 된 튜플에 Insert data가 삽입되는가?
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
12735 12755 12775 12793_fsm 12809 12825_fsm 12845 12862_vm 12910 12925 12949 12968_vm 12988_fsm
12735_fsm 12756 12776 12793_vm 12809_fsm 12825_vm 12846 12864 12910_fsm 12925_fsm 12953 12970 12988_vm
12735_vm 12757 12776_fsm 12795 12809_vm 12827 12847 12865 12910_vm 12925_vm 12953_fsm 12972 12990
12737 12757_fsm 12776_vm 12796 12811 12828 12847_fsm 12866 12912 12927 12953_vm 12973 12992
12737_fsm 12757_vm 12778 12797 12812 12828_fsm 12847_vm 12866_fsm 12913 12928 12955 12973_fsm 12993
12737_vm 12759 12780 12797_fsm 12813 12828_vm 12849 12866_vm 12913_fsm 12929 12956 12973_vm 12995
12739 12761 12781 12797_vm 12814 12830 12851 12868 12913_vm 12931 12957 12975 12997
12740 12762 12782 12799 12814_fsm 12830_fsm 12852 12869 12915 12932 12957_fsm 12977
pg_filenode.m
ap
12741 12763 12783 12800 12814_vm 12830_vm 12853 12870 12916 12933 12957_vm 12978 PG_VERSION
12741_fsm 12764 12784 12801 12816 12832 12853_fsm 12871 12917 12935 12959 12978_fsm
12741_vm 12764_fsm 12785 12801_fsm 12817 12833 12853_vm 12871_fsm 12917_fsm 12936 12960 12978_vm
12743 12764_vm 12787 12801_vm 12818 12834 12855 12871_vm 12917_vm 12937 12962 12980
12744 12766 12788 12803 12818_fsm 12835 12856 12873 12919 12939 12963 12982
12749 12767 12789 12804 12818_vm 12837 12857 12874 12920 12940 12963_fsm 12983
12751 12768 12789_fsm 12805 12820 12839 12859 12906 12921 12942 12963_vm 12983_fsm
12752 12769 12789_vm 12805_fsm 12821 12840 12860 12906_fsm 12921_fsm 12943 12965 12983_vm
12753 12771 12791 12805_vm 12822 12841 12861 12906_vm 12921_vm 12944 12967 12985
12753_fsm 12773 12792 12807 12824 12842 12862 12908 12923 12946 12968 12987
12753_vm 12774 12793 12808 12825 12843 12862_fsm 12909 12924 12948 12968_fsm 12988
DB 생성 시 생성되는 파일들
select * from pg_class where relfilenode='12735’;
1. DB 생성 후, 무엇이 생성되는가?
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
2. Vacuum Full하면 새로운 파일이 생성되는데, 이전의 파일은 계속 있는가?
[postgres@153_40 1262281]$ ls
1262282 12753 12771 12791 12805_vm 12822 12841 12861 12906_vm 12921_vm 12944 12967 12985
1262282_fsm 12753_fsm 12773 12792 12807 12824 12842 12862 12908 12923 12946 12968 12987
1262282_vm 12753_vm 12774 12793 12808 12825 12843 12862_fsm 12909 12924 12948 12968_fsm 12988
12735 12755 12775 12793_fsm 12809 12825_fsm 12845 12862_vm 12910 12925 12949 12968_vm 12988_fsm
12735_fsm 12756 12776 12793_vm 12809_fsm 12825_vm 12846 12864 12910_fsm 12925_fsm 12953 12970 12988_vm
12735_vm 12757 12776_fsm 12795 12809_vm 12827 12847 12865 12910_vm 12925_vm 12953_fsm 12972 12990
12737 12757_fsm 12776_vm 12796 12811 12828 12847_fsm 12866 12912 12927 12953_vm 12973 12992
12737_fsm 12757_vm 12778 12797 12812 12828_fsm 12847_vm 12866_fsm 12913 12928 12955 12973_fsm 12993
12737_vm 12759 12780 12797_fsm 12813 12828_vm 12849 12866_vm 12913_fsm 12929 12956 12973_vm 12995
12739 12761 12781 12797_vm 12814 12830 12851 12868 12913_vm 12931 12957 12975 12997
12740 12762 12782 12799 12814_fsm 12830_fsm 12852 12869 12915 12932 12957_fsm 12977 pg_filenode.map
12741 12763 12783 12800 12814_vm 12830_vm 12853 12870 12916 12933 12957_vm 12978 pg_internal.init
12741_fsm 12764 12784 12801 12816 12832 12853_fsm 12871 12917 12935 12959 12978_fsm PG_VERSION
12741_vm 12764_fsm 12785 12801_fsm 12817 12833 12853_vm 12871_fsm 12917_fsm 12936 12960 12978_vm
12743 12764_vm 12787 12801_vm 12818 12834 12855 12871_vm 12917_vm 12937 12962 12980
12744 12766 12788 12803 12818_fsm 12835 12856 12873 12919 12939 12963 12982
12749 12767 12789 12804 12818_vm 12837 12857 12874 12920 12940 12963_fsm 12983
12751 12768 12789_fsm 12805 12820 12839 12859 12906 12921 12942 12963_vm 12983_fsm
12752 12769 12789_vm 12805_fsm 12821 12840 12860 12906_fsm 12921_fsm 12943 12965 12983_vm
<표준 Vacuum한 상태>
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
2. Vacuum Full하면 새로운 파일이 생성되는데, 이전의 파일은 계속 있는가?
[postgres@153_40 1262281]$ ls
1262285 12753_vm 12774 12793 12808 12825 12843 12862_fsm 12909 12924 12948 12968_fsm 12988
12735 12755 12775 12793_fsm 12809 12825_fsm 12845 12862_vm 12910 12925 12949 12968_vm 12988_fsm
12735_fsm 12756 12776 12793_vm 12809_fsm 12825_vm 12846 12864 12910_fsm 12925_fsm 12953 12970 12988_vm
12735_vm 12757 12776_fsm 12795 12809_vm 12827 12847 12865 12910_vm 12925_vm 12953_fsm 12972 12990
12737 12757_fsm 12776_vm 12796 12811 12828 12847_fsm 12866 12912 12927 12953_vm 12973 12992
12737_fsm 12757_vm 12778 12797 12812 12828_fsm 12847_vm 12866_fsm 12913 12928 12955 12973_fsm 12993
12737_vm 12759 12780 12797_fsm 12813 12828_vm 12849 12866_vm 12913_fsm 12929 12956 12973_vm 12995
12739 12761 12781 12797_vm 12814 12830 12851 12868 12913_vm 12931 12957 12975 12997
12740 12762 12782 12799 12814_fsm 12830_fsm 12852 12869 12915 12932 12957_fsm 12977 pg_filenode.map
12741 12763 12783 12800 12814_vm 12830_vm 12853 12870 12916 12933 12957_vm 12978 pg_internal.init
12741_fsm 12764 12784 12801 12816 12832 12853_fsm 12871 12917 12935 12959 12978_fsm PG_VERSION
12741_vm 12764_fsm 12785 12801_fsm 12817 12833 12853_vm 12871_fsm 12917_fsm 12936 12960 12978_vm
12743 12764_vm 12787 12801_vm 12818 12834 12855 12871_vm 12917_vm 12937 12962 12980
12744 12766 12788 12803 12818_fsm 12835 12856 12873 12919 12939 12963 12982
12749 12767 12789 12804 12818_vm 12837 12857 12874 12920 12940 12963_fsm 12983
12751 12768 12789_fsm 12805 12820 12839 12859 12906 12921 12942 12963_vm 12983_fsm
12752 12769 12789_vm 12805_fsm 12821 12840 12860 12906_fsm 12921_fsm 12943 12965 12983_vm
12753 12771 12791 12805_vm 12822 12841 12861 12906_vm 12921_vm 12944 12967 12985
12753_fsm 12773 12792 12807 12824 12842 12862 12908 12923 12946 12968 12987
이전 파일은 사라짐
<Vacuum Full한 상태>
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
3. Delete 후 바로 Insert 하면, Delete 된 튜플에 Insert data가 삽입되는가?
순서 command 순서 command
1. Database 생성 create database vac; 9. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
2. oid 확인 oid2name | grep vac 10. myt 테이블에 vacuum 작업 vacuum myt;
3. 테이블 생성 create table myt(id char(7)); 11. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
4. pg_relation_path 확인 select pg_relation_filepath(‘myt’); 12. myt 테이블에 210부터 51건 삽입
insert into myt select
generate_series(210,260);
5. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 13. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
6. myt 테이블에 100건 삽입
insert into myt select
generate_series(100,199);
14. myt 테이블에 vacuum full 작업 vauum full myt;
7. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 15. 총 사이즈 확인 select pg_total_relation_size(‘myt’);
8. myt 테이블에서 id가 150이상이면
삭제
delete from myt where id>=‘150’; 16. pg_relation_path 확인 select pg_relation_filepath(‘myt’);
insert into myt select
generate_series(200,209);
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
insert into myt select generate_series(100,199);
000000 07 00 00 00 38 5e 24 1a 00 00 00 00 a8 01 80 13 >....8^$.........<
…
0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001380 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001390 64 00 01 00 02 08 18 00 11 31 39 39 20 20 20 20 >d........199 <
0013a0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0013b0 63 00 01 00 02 08 18 00 11 31 39 38 20 20 20 20 >c........198 <
…
001980 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001990 34 00 01 00 02 08 18 00 11 31 35 31 20 20 20 20 >4........151 <
0019a0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019b0 33 00 01 00 02 08 18 00 11 31 35 30 20 20 20 20 >3........150 <
…
001fe0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 <
Page Header
+
Item Pointer
100~199
Insert결과
Tuple
* 실제 Dump를 옮겨놓은 엑셀 파일
http://cafe.naver.com/playexem/332
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
delete from myt where id>=‘150’;
000000 07 00 00 00 a8 79 24 1a 00 00 00 00 a8 01 80 13 >.....y$.........<
…
0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001380 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 <
0013a0 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
0013b0 63 00 01 20 02 01 18 00 11 31 39 38 20 20 20 20 >c.. .....198 <
…
001980 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 <
0019a0 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 <
…
001fe0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001ff0 01 00 01 00 02 09 18 00 11 31 30 30 20 20 20 20 >.........100 <
Delete 후 150부터
199까지 xmax 표시
Page Header
+
Item Pointer
Tuple
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
insert into myt select generate_series(200,209);
000000 07 00 00 00 a8 79 24 1a 00 00 00 00 a8 01 80 13 >.....y$.........<
…
0001a0 a0 93 40 00 80 93 40 00 60 93 40 00 40 93 40 00 >..@...@.`.@.@.@.<
0001b0 20 93 40 00 00 93 40 00 e0 92 40 00 c0 92 40 00 > .@...@...@...@.<
0001c0 a0 92 40 00 80 92 40 00 60 92 40 00 40 92 40 00 >..@...@.`.@.@.@.<
0001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001250 6e 00 01 00 02 08 18 00 11 32 30 39 20 20 20 20 >n........209 <
001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001250 6e 00 01 00 02 08 18 00 11 32 30 39 20 20 20 20 >n........209 <
…
001360 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001370 65 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >e........200 <
001380 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 <
001980 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 <
0019a0 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 <
0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 <
…
001fc0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001fd0 02 00 01 00 02 09 18 00 11 31 30 31 20 20 20 20 >.........101 <
001fe0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001ff0 01 00 01 00 02 09 18 00 11 31 30 30 20 20 20 20 >.........100 <
새로 Insert 된 10건의
Item Pointer
10건을 insert 했을 때,
• 10건에 대한 Item Pointer 생성
• Tuple에서는 delete된 튜플 위로 생성
Delete 된 튜플
위에 새로운 튜플 생성
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
vacuum myt;
000000 07 00 00 00 58 96 24 1a 00 00 05 00 d0 01 80 18 >....X.$.........<
…
0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
…
0001a0 00 00 00 00 00 00 00 00 a0 99 40 00 80 99 40 00 >..........@...@.<
0001b0 60 99 40 00 40 99 40 00 20 99 40 00 00 99 40 00 >`.@.@.@. .@...@.<
0001c0 e0 98 40 00 c0 98 40 00 a0 98 40 00 80 98 40 00 >..@...@...@...@.<
0001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001250 6e 00 01 00 02 09 18 00 11 32 30 39 20 20 20 20 >n........209 <
001260 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001270 6d 00 01 00 02 09 18 00 11 32 30 38 20 20 20 20 >m........208 <
…
001360 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001370 65 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >e........200 <
001380 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 <
…
001860 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........<
001870 3d 00 01 20 02 05 18 00 11 31 36 30 20 20 20 20 >=.. .....160 <
001880 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001890 6e 00 01 00 02 09 18 00 11 32 30 39 20 20 20 20 >n........209 <
0018a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0018b0 6d 00 01 00 02 09 18 00 11 32 30 38 20 20 20 20 >m........208 <
…
0019a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019b0 65 00 01 00 02 09 18 00 11 32 30 30 20 20 20 20 >e........200 <
0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 <
…
200~209
200~209
Vacuum 작업을 하면, 위에 존재하는 튜플들은 그대로
유지되고, delete 된 자리 150부터 200~209가 reuse됨
위의 Item Pointer는 아래의 200~209 튜플을 가리킴
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
insert into myt select generate_series(210,260);
000000 07 00 00 00 58 96 24 1a 00 00 05 00 d0 01 80 18 >....X.$.........<
…
0000e0 60 98 40 00 40 98 40 00 20 98 40 00 00 98 40 00 >`.@.@.@. .@...@.<
0000f0 e0 97 40 00 c0 97 40 00 a0 97 40 00 80 97 40 00 >..@...@...@...@.<
…
0001b0 60 99 40 00 40 99 40 00 20 99 40 00 00 99 40 00 >`.@.@.@. .@...@.<
0001c0 e0 98 40 00 c0 98 40 00 a0 98 40 00 80 98 40 00 >..@...@...@...@.<
0001d0 20 92 40 00 00 00 00 00 00 00 00 00 00 00 00 00 > .@.............<
0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001220 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001230 6f 00 01 00 02 08 18 00 11 32 36 30 20 20 20 20 >o........260 <
001240 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001250 64 00 01 00 02 08 18 00 11 32 35 39 20 20 20 20 >d........259 <
…
001860 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001870 33 00 01 00 02 08 18 00 11 32 31 30 20 20 20 20 >3........210 <
001880 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001890 6e 00 01 00 02 09 18 00 11 32 30 39 20 20 20 20 >n........209 <
0018a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0018b0 6d 00 01 00 02 09 18 00 11 32 30 38 20 20 20 20 >m........208 <
…
0019a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019b0 65 00 01 00 02 09 18 00 11 32 30 30 20 20 20 20 >e........200 <
0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 <
…
새로 Insert 된 51건
210~260
위에 남아있던 200~209는
새로 Insert된 210~260으로 reuse됨
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
Questions
vauum full myt;
000000 07 00 00 00 58 96 24 1a 00 00 05 00 d0 01 80 18 >....X.$.........<
…
0000e0 60 98 40 00 40 98 40 00 20 98 40 00 00 98 40 00 >`.@.@.@. .@...@.<
0000f0 e0 97 40 00 c0 97 40 00 a0 97 40 00 80 97 40 00 >..@...@...@...@.<
…
0001b0 60 99 40 00 40 99 40 00 20 99 40 00 00 99 40 00 >`.@.@.@. .@...@.<
0001c0 e0 98 40 00 c0 98 40 00 a0 98 40 00 80 98 40 00 >..@...@...@...@.<
0001d0 20 92 40 00 00 00 00 00 00 00 00 00 00 00 00 00 > .@.............<
0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
001220 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001230 6f 00 01 00 02 0b 18 00 11 32 36 30 20 20 20 20 >o........260 <
001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001250 6e 00 01 00 02 0b 18 00 11 32 30 39 20 20 20 20 >n........209 <
…
001360 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001370 65 00 01 00 02 0b 18 00 11 32 30 30 20 20 20 20 >e........200 <
001380 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
001390 64 00 01 00 02 0b 18 00 11 32 35 39 20 20 20 20 >d........259 <
…
0019a0 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019b0 33 00 01 00 02 0b 18 00 11 32 31 30 20 20 20 20 >3........210 <
0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............<
0019d0 32 00 01 00 02 0b 18 00 11 31 34 39 20 20 20 20 >2........149 <
…
100~149, 210~259, 200~209, 260 순으로
튜플이 정리됨
200~209
210~259
260
100~149
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
02. [MySQL] Page Dump 분석
발표자: 연구컨텐츠팀 이근오
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
MySQL Page Dump 분석
출처: 하등성(何登成) 블로그
http://hedengcheng.com/?p=118
하등성(何登成)이 분석한 Page 구조 그림 (중국어)
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
출처: https://blog.jcole.us/2013/01/03/the-
basics-of-innodb-space-file-layout/
MySQL Page Dump 분석
- 기본 Page 사이즈 : 16 KB
- 모든 Page는 Header(38 Byte) 와 Trailer(8 Byte) 로 구성
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
create table exem_i.t1 ( c1 char(04), c2 char(1),
c3 char(7), c4 char(7) ) engine=innodb ;
There are 5
directory slots
beginning of free
space
Slot 1:
Infimum을 가리킴
Slot M:
Supremum을 가리킴
last record inserted
at location
Field Length
Per Field 1 byte
MySQL Page Dump 분석
위와 같은 구조로 T1 테이블을 생성하고, 12건의 데이터를
Insert 한 후, T1테이블에 해당되는 덤프파일을 분석한 내용
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
03. [MySQL] 통계정보 관리
발표자: 연구컨텐츠팀 이대덕
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
MySQL 통계정보 관리
mysql> show global variables like '%stats%';
+--------------------------------------+---------------+
| Variable_name | Value |
+--------------------------------------+---------------+
| innodb_stats_auto_recalc | ON |
| innodb_stats_method | nulls_equal |
| innodb_stats_on_metadata | OFF |
| innodb_stats_persistent | ON |
| innodb_stats_persistent_sample_pages | 20 |
| innodb_stats_sample_pages | 8 |
| innodb_stats_transient_sample_pages | 8 |
| myisam_stats_method | nulls_unequal |
+--------------------------------------+---------------+
8 rows in set (0.01 sec)
innodb_stats_auto_recalc ON boolean
• 테이블의 로우가 10%이상 변경되면 recalculate함
• innodb_stats_persistent 가 on 되어있어야 함
• stats_auto_recalc로 테이블단위 설정 가능
innodb_stats_method
myisam_stats_method
nulls_equal
nulls_equal
nulls_unequal
nulls_ignored
• Null 값 처리방법(동일처리, 불일치, 무시)
innodb_stats_on_metadata OFF boolean
• SHOW TABLE STATUS 명령어사용
• INFORMATION_SCHEMA.TABLES 테이블과 INFORMATI
ON_SCHEMA.STATISTICS 테이블에 엑세스 시 통계정
보 갱신
innodb_stats_persistent ON boolean
• 통계정보를 영구적으로 디스크에 저장할지 여부,
테이블 생성시 stats_persistent 옵션으로 테이블 별
설정 가능
innodb_stats_persistent_sample_pages 20 integer • 통계정보를 디스크에 저장할 때 샘플링 페이지 수
innodb_stats_sample_pages • 5.6 버전부터 사용되지 않음
innodb_stats_transient_sample_pages 8 integer • 통계정보를 자동으로 수집할 때 샘플링 페이지 수
show global variables like ‘%stats%’;
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
mysql> select * from mysql.innodb_table_stats;
+---------------+---------------+---------------------+--------+----------------------+--------------------------+
| database_name | table_name | last_update | n_rows | clustered_index_size | sum_of_other_index_siz
es |
+---------------+---------------+---------------------+--------+----------------------+--------------------------+
| employees | employees | 2016-06-22 14:46:23 | 299468 | 929 | 0 |
| exem_i | foo | 2016-06-20 14:51:25 | 0 | 1 | 0 |
| exem_i | t1 | 2016-06-28 14:26:46 | 5 | 1 | 0 |
| mysql | gtid_executed | 2016-06-20 10:55:38 | 0 | 1 | 0 |
| mysqlslap | t1 | 2016-06-23 09:54:45 | 2 | 1 | 0 |
| sys | sys_config | 2016-06-20 10:55:39 | 6 | 1 | 0 |
+---------------+---------------+---------------------+--------+----------------------+--------------------------+
6 rows in set (0.00 sec)
database_name 데이터베이스 이름
table_name 테이블이나 파티션 이름
last_update 마지막으로 갱신된 시간
n_rows 로우 수
clustered_index_size 프라이머리 인덱스 사이즈(페이지)
sum_of_other_index_sizes
PK인덱스를 제외한 모든 인덱스의 사이
즈 합계
MySQL 통계정보 관리
select * from mysql.innodb_table_stats;
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.
MySQL 통계정보 관리
mysql> select * from mysql.innodb_index_stats where table_name = 'employees';
+---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+
| database_name | table_name | index_name | last_update | stat_name | stat_value | sample_size | stat_description |
+---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+
| employees | employees | PRIMARY | 2016-06-22 14:46:23 | n_diff_pfx01 | 299468 | 20 | emp_no |
| employees | employees | PRIMARY | 2016-06-22 14:46:23 | n_leaf_pages | 886 | NULL | Number of leaf pages in the index |
| employees | employees | PRIMARY | 2016-06-22 14:46:23 | size | 929 | NULL | Number of pages in the index |
+---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+
3 rows in set (0.06 sec)
database_name 데이터베이스 이름
table_name 테이블이나 파티션 이름
index_name 인덱스 이름
last_update 마지막으로 갱신된 시간
stat_name 통계정보의 이름
stat_value 해당 통계정보의 수치
sample_size
stat_value를 측정할때의 샘플
링 한 사이즈
stat_description 해당 통계정보의 설명
select * from mysql.innodb_index_stats where table_name = 'employees';
Research & Contents
Blog
Video
E-mail
NAVER http://cafe.naver.com/playexem
ITPUB http://blog.itpub.net/31135309/
Wordpress https://playexem.wordpress.com/
Slideshare http://www.slideshare.net/playexem
Youtube https://www.youtube.com/channel/UC5wKR
_-A0eL_Pn_EMzoauJg
Tudou http://www.tudou.com/home/maxgauge/
교육 문의: 연구컨텐츠팀 김숙진
edu@ex-em.com
© Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.

제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀

  • 1.
    제 6회 엑셈수요 세미나 자료 EXEM seminar report no. 006 (2016.06.29) Research & Contents Team
  • 2.
    Table of Agenda ©Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved. 01. 02. 03. [MySQL] Page Dump 분석 [PostgreSQL] Vacuum의 거의 모든 것 (2차) [MySQL] 통계정보 관리
  • 3.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 01. [PostgreSQL] Vacuum의 거의 모든 것 (2차) 발표자: 연구컨텐츠팀 김숙진
  • 4.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 목차 1차 1) Vacuum 정의 및 필요성 2) Vacuum 실행 구조 3) 표준 Vacuum VS Vacuum full (시나리오) 2차 1) dump로 보는 “표준 Vacuum VS Vacuum full” [PostgreSQL] Vacuum의 거의 모든 것
  • 5.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 1. Dump로 보는 “표준 Vacuum VS Vacuum full” <표준 Vacuum과 Vacuum full 비교 시나리오> 순서 command 순서 command 1. Database 생성 create database vac; 9. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 2. oid 확인 oid2name | grep vac 10. myt 테이블에 vacuum 작업 vacuum myt; 3. 테이블 생성 create table myt(id char(7)); 11. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 4. pg_relation_path 확인 select pg_relation_filepath(‘myt’); 12. myt 테이블에 200부터 11건 삽입 insert into myt select generate_series(200,210); 5. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 13. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 6. myt 테이블에 100건 삽입 insert into myt select generate_series(100,199); 14. myt 테이블에 vacuum full 작업 vauum full myt; 7. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 15. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 8. myt 테이블에서 id가 150이상이면 삭제 delete from myt where id>=‘150’; 16. pg_relation_path 확인 select pg_relation_filepath(‘myt’);
  • 6.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 1. Dump로 보는 “표준 Vacuum VS Vacuum full” [postgres@153_40 base]$ createdb vac [postgres@153_40 base]$ oid2name | grep vac 1254094 vac pg_default [postgres@153_40 base]$ cd 1254094/ [postgres@153_40 1254094]$ psql -d vac (postgres@[local]:5432) [vac] > ! pwd /usr/local/pgsql/data/base/1254094 (postgres@[local]:5432) [vac] > ! ls | head -5 12735 12735_fsm 12735_vm 12737 12737_fsm (postgres@[local]:5432) [vac] > create table myt(id char(7)); CREATE TABLE (postgres@[local]:5432) [vac] > select pg_relation_filepath('myt'); pg_relation_filepath ---------------------- base/ 1254094/1254095 (1 row) (postgres@[local]:5432) [vac] > ! ls -lt 123* -rw------- 1 postgres postgres 0 Jun 21 16:10 1254094 (postgres@[local]:5432) [vac] > select pg_total_relation_size('myt'); pg_total_relation_size ------------------------ 0 (1 row) 1 2 3 4 5 <시나리오>
  • 7.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. (postgres@[local]:5432) [vac] > insert into myt select generate_series(100,199); INSERT 0 100 (postgres@[local]:5432) [vac] > select pg_total_relation_size('myt'); pg_total_relation_size ------------------------ 8192 (1 row) (postgres@[local]:5432) [vac] > ! ls –l 1254095 -rw------- 1 postgres postgres 8192 Jun 24 13:59 /usr/local/pgsql/data/base/1254094/1254095 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 6 7 <시나리오> <dump> 000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................< … 0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001380 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001390 64 00 01 00 02 08 18 00 11 31 39 39 20 20 20 20 >d........199 < 0013a0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 0013b0 63 00 01 00 02 08 18 00 11 31 39 38 20 20 20 20 >c........198 < … 001980 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001990 34 00 01 00 02 08 18 00 11 31 35 31 20 20 20 20 >4........151 < 0019a0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 0019b0 33 00 01 00 02 08 18 00 11 31 35 30 20 20 20 20 >3........150 < … 001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 < 100~199 Insert 결과 insert into myt select generate_series(100,199); Page Header + Item Pointer Tuple
  • 8.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. (postgres@[local]:5432) [vac] > delete from myt where id>='150'; DELETE 50 (postgres@[local]:5432) [vac] > select pg_total_relation_size('myt'); pg_total_relation_size ------------------------ 8192 (1 row) 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 8 9 000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................< … 0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001380 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 < 0013a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 0013b0 63 00 01 20 02 01 18 00 11 31 39 38 20 20 20 20 >c.. .....198 < … 001980 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 < 0019a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 < … 001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 < <dump><시나리오> delete 후, 150부터 199 까지 xmax가 표시됨 100~149 delete from myt where id>=‘150’; Page Header + Item Pointer Tuple
  • 9.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. (postgres@[local]:5432) [vac] > vacuum myt; VACUUM (postgres@[local]:5432) [vac] > select pg_total_relation_size('myt'); pg_total_relation_size ------------------------ 40960 (1 row) (postgres@[local]:5432) [vac] > ! ls –l 1254095 -rw------- 1 postgres postgres 8192 Jun 24 14:00/usr/local/pgsql/data/base/1254094/1254095 -rw------- 1 postgres postgres 24576 Jun 24 14:00 /usr/local/pgsql/data/base/1254094/1254095_fsm -rw------- 1 postgres postgres 8192 Jun 24 14:00 /usr/local/pgsaql/data/base/1254094/1254095_vm 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 10 11 000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................< … 0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001380 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 < 0013a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 0013b0 63 00 01 20 02 01 18 00 11 31 39 38 20 20 20 20 >c.. .....198 < … 001980 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 < 0019a0 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 < … 001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 < 50건에 대한 Item Pointer 삭제 <dump><시나리오> vacuum myt;
  • 10.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. (postgres@[local]:5432) [vac] > insert into myt select generate_series(200,210); INSERT 0 11 (postgres@[local]:5432) [vac] > select pg_total_relation_size('myt'); pg_total_relation_size ------------------------ 40960 (1 row) (postgres@[local]:5432) [vac] > ! ls –l 1254095 -rw------- 1 postgres postgres 8192 Jun 24 14:01 /usr/local/pgsql/data/base/1254094/1254095 -rw------- 1 postgres postgres 24576 Jun 24 14:01 /usr/local/pgsql/data/base/1254094/1254095_fsm -rw------- 1 postgres postgres 8192 Jun 24 14:01 /usr/local/pgsql/data/base/1254094/1254095_vm 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 13 12 000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................< … 000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001380 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 < … 001840 69 31 00 00 6b 31 00 00 00 00 00 00 00 00 00 00 >i1..k1..........< 001850 3e 00 01 20 02 05 18 00 11 31 36 31 20 20 20 20 >>.. .....161 < 001860 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001870 3d 00 01 00 02 08 18 00 11 32 31 30 20 20 20 20 >=........210 < … 0019a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 0019b0 33 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >3........200 < 0019c0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 < … 001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 < <dump><시나리오> 200~210이 delete 된 150 자리부터 reuse 됨 insert into myt select generate_series(200,210); 11건에 대한 Item Pointer 추가
  • 11.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 000000 07 00 00 00 50 60 0b 1a 00 00 05 00 a8 01 c0 19 >....P`..........< 000010 00 20 04 20 00 00 00 00 e0 9f 40 00 c0 9f 40 00 >. . ......@...@.< 000020 a0 9f 40 00 80 9f 40 00 60 9f 40 00 40 9f 40 00 >..@...@.`.@.@.@.< 000030 20 9f 40 00 00 9f 40 00 e0 9e 40 00 c0 9e 40 00 > .@...@...@...@.< 000040 a0 9e 40 00 80 9e 40 00 60 9e 40 00 40 9e 40 00 >..@...@.`.@.@.@.< 000050 20 9e 40 00 00 9e 40 00 e0 9d 40 00 c0 9d 40 00 > .@...@...@...@.< 000060 a0 9d 40 00 80 9d 40 00 60 9d 40 00 40 9d 40 00 >..@...@.`.@.@.@.< 000070 20 9d 40 00 00 9d 40 00 e0 9c 40 00 c0 9c 40 00 > .@...@...@...@.< 000080 a0 9c 40 00 80 9c 40 00 60 9c 40 00 40 9c 40 00 >..@...@.`.@.@.@.< 000090 20 9c 40 00 00 9c 40 00 e0 9b 40 00 c0 9b 40 00 > .@...@...@...@.< 0000a0 a0 9b 40 00 80 9b 40 00 60 9b 40 00 40 9b 40 00 >..@...@.`.@.@.@.< 0000b0 20 9b 40 00 00 9b 40 00 e0 9a 40 00 c0 9a 40 00 > .@...@...@...@.< 0000c0 a0 9a 40 00 80 9a 40 00 60 9a 40 00 40 9a 40 00 >..@...@.`.@.@.@.< 0000d0 20 9a 40 00 00 9a 40 00 e0 99 40 00 c0 99 40 00 > .@...@...@...@.< 0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 000000 07 00 00 00 78 aa 0b 1a 00 00 01 00 a8 01 60 18 >....x.........`.< 000010 00 20 04 20 00 00 00 00 e0 9f 40 00 c0 9f 40 00 >. . ......@...@.< 000020 a0 9f 40 00 80 9f 40 00 60 9f 40 00 40 9f 40 00 >..@...@.`.@.@.@.< 000030 20 9f 40 00 00 9f 40 00 e0 9e 40 00 c0 9e 40 00 > .@...@...@...@.< 000040 a0 9e 40 00 80 9e 40 00 60 9e 40 00 40 9e 40 00 >..@...@.`.@.@.@.< 000050 20 9e 40 00 00 9e 40 00 e0 9d 40 00 c0 9d 40 00 > .@...@...@...@.< 000060 a0 9d 40 00 80 9d 40 00 60 9d 40 00 40 9d 40 00 >..@...@.`.@.@.@.< 000070 20 9d 40 00 00 9d 40 00 e0 9c 40 00 c0 9c 40 00 > .@...@...@...@.< 000080 a0 9c 40 00 80 9c 40 00 60 9c 40 00 40 9c 40 00 >..@...@.`.@.@.@.< 000090 20 9c 40 00 00 9c 40 00 e0 9b 40 00 c0 9b 40 00 > .@...@...@...@.< 0000a0 a0 9b 40 00 80 9b 40 00 60 9b 40 00 40 9b 40 00 >..@...@.`.@.@.@.< 0000b0 20 9b 40 00 00 9b 40 00 e0 9a 40 00 c0 9a 40 00 > .@...@...@...@.< 0000c0 a0 9a 40 00 80 9a 40 00 60 9a 40 00 40 9a 40 00 >..@...@.`.@.@.@.< 0000d0 20 9a 40 00 00 9a 40 00 e0 99 40 00 c0 99 40 00 > .@...@...@...@.< 0000e0 a0 99 40 00 80 99 40 00 60 99 40 00 40 99 40 00 >..@...@.`.@.@.@.< 0000f0 20 99 40 00 00 99 40 00 e0 98 40 00 c0 98 40 00 > .@...@...@...@.< 000100 a0 98 40 00 80 98 40 00 60 98 40 00 00 00 00 00 >..@...@.`.@.....< 000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< <Page Header + Item Pointer> Item Pointer 11건 추가됨 insert into myt select generate_series(200,210); 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 11건 insert Page Header
  • 12.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 000000 07 00 00 00 78 aa 0b 1a 00 00 01 00 a8 01 60 18 >....x.........`.< 000010 00 20 04 20 00 00 00 00 e0 9f 40 00 c0 9f 40 00 >. . ......@...@.< 000020 a0 9f 40 00 80 9f 40 00 60 9f 40 00 40 9f 40 00 >..@...@.`.@.@.@.< 000030 20 9f 40 00 00 9f 40 00 e0 9e 40 00 c0 9e 40 00 > .@...@...@...@.< 000040 a0 9e 40 00 80 9e 40 00 60 9e 40 00 40 9e 40 00 >..@...@.`.@.@.@.< 000050 20 9e 40 00 00 9e 40 00 e0 9d 40 00 c0 9d 40 00 > .@...@...@...@.< 000060 a0 9d 40 00 80 9d 40 00 60 9d 40 00 40 9d 40 00 >..@...@.`.@.@.@.< 000070 20 9d 40 00 00 9d 40 00 e0 9c 40 00 c0 9c 40 00 > .@...@...@...@.< 000080 a0 9c 40 00 80 9c 40 00 60 9c 40 00 40 9c 40 00 >..@...@.`.@.@.@.< 000090 20 9c 40 00 00 9c 40 00 e0 9b 40 00 c0 9b 40 00 > .@...@...@...@.< 0000a0 a0 9b 40 00 80 9b 40 00 60 9b 40 00 40 9b 40 00 >..@...@.`.@.@.@.< 0000b0 20 9b 40 00 00 9b 40 00 e0 9a 40 00 c0 9a 40 00 > .@...@...@...@.< 0000c0 a0 9a 40 00 80 9a 40 00 60 9a 40 00 40 9a 40 00 >..@...@.`.@.@.@.< 0000d0 20 9a 40 00 00 9a 40 00 e0 99 40 00 c0 99 40 00 > .@...@...@...@.< 0000e0 a0 99 40 00 80 99 40 00 60 99 40 00 40 99 40 00 >..@...@.`.@.@.@.< 0000f0 20 99 40 00 00 99 40 00 e0 98 40 00 c0 98 40 00 > .@...@...@...@.< 000100 a0 98 40 00 80 98 40 00 60 98 40 00 00 00 00 00 >..@...@.`.@.....< 000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< <Page Header + Item Pointer> 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 001860 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001870 3d 00 01 00 02 08 18 00 11 32 31 30 20 20 20 20 >=........210 < 001880 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001890 3c 00 01 00 02 08 18 00 11 32 30 39 20 20 20 20 ><........209 < 0018a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 0018b0 3b 00 01 00 02 08 18 00 11 32 30 38 20 20 20 20 >;........208 < 0018c0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 0018d0 3a 00 01 00 02 08 18 00 11 32 30 37 20 20 20 20 >:........207 < 0018e0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 0018f0 39 00 01 00 02 08 18 00 11 32 30 36 20 20 20 20 >9........206 < 001900 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001910 38 00 01 00 02 08 18 00 11 32 30 35 20 20 20 20 >8........205 < 001920 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001930 37 00 01 00 02 08 18 00 11 32 30 34 20 20 20 20 >7........204 < 001940 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001950 36 00 01 00 02 08 18 00 11 32 30 33 20 20 20 20 >6........203 < 001960 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001970 35 00 01 00 02 08 18 00 11 32 30 32 20 20 20 20 >5........202 < 001980 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001990 34 00 01 00 02 08 18 00 11 32 30 31 20 20 20 20 >4........201 < 0019a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 0019b0 33 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >3........200 < <Tuple> 새롭게 Insert된 데이터 insert into myt select generate_series(200,210); 60 98 40 00 00 40 98 60 뒤 세자리 860이 Tuple 첫 항목과 동일 새롭게 Insert된 데이터
  • 13.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. (postgres@[local]:5432) [vac] > vacuum full myt; VACUUM (postgres@[local]:5432) [vac] > select pg_total_relation_size('myt'); pg_total_relation_size ------------------------ 8192 (1 row) (postgres@[local]:5432) [vac] > select pg_relation_filepath('myt'); pg_relation_filepath ---------------------- /base/1254094/1254098 (1 row) 원래 pg_relation_filepath base/ 1254094/1254095 1. Dump로 보는 “표준 Vacuum VS Vacuum full” 14 15 16 <시나리오> 000000 07 00 00 00 08 0f 0b 1a 00 00 00 00 a8 01 80 13 >................< … 000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001860 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001870 3d 00 01 00 02 0b 18 00 11 32 31 30 20 20 20 20 >=........210 < 001880 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 001890 3c 00 01 00 02 0b 18 00 11 32 30 39 20 20 20 20 ><........209 < … 0019a0 6c 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >l1..............< 0019b0 33 00 01 00 02 0b 18 00 11 32 30 30 20 20 20 20 >3........200 < 0019c0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 0019d0 32 00 01 00 02 0b 18 00 11 31 34 39 20 20 20 20 >2........149 < … 001fe0 69 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >i1..............< 001ff0 01 00 01 00 02 0b 18 00 11 31 30 30 20 20 20 20 >.........100 < <dump> 200~210 삽입된 튜플을 제외하고, 그 뒤에 161~199 삭제 vauum full myt; Page Header + Item Pointer 200~210 Tuple 100~149
  • 14.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 1. Dump로 보는 “표준 Vacuum VS Vacuum full” Page Header + Item Pointer Tuple insert into myt select generate_series(100,199); 100건에 대한 Page Header와 Item Pointer 생성 100건에 대한 tuple 생성 delete from myt where id>=‘150’; 변경 X delete 후, 150부터 199까지 xmax 표시 vacuum myt; 50건에 대한 Item Pointer 삭제 변경 X insert into myt select generate_series(200,210); 11건에 대한 Item Pointer 생성 200~210이 150 자리부터 reuse 됨 vauum full myt; 변경 X 200~210 삽입된 튜플을 제외하고, 그 뒤에 161~199 삭제
  • 15.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions 1. DB 생성 후, 무엇이 생성되는가? 2. Vacuum Full하면 새로운 파일이 생성되는데, 이전의 파일은 계속 있는가? 3. Delete 후 바로 Insert 하면, Delete 된 튜플에 Insert data가 삽입되는가?
  • 16.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions 12735 12755 12775 12793_fsm 12809 12825_fsm 12845 12862_vm 12910 12925 12949 12968_vm 12988_fsm 12735_fsm 12756 12776 12793_vm 12809_fsm 12825_vm 12846 12864 12910_fsm 12925_fsm 12953 12970 12988_vm 12735_vm 12757 12776_fsm 12795 12809_vm 12827 12847 12865 12910_vm 12925_vm 12953_fsm 12972 12990 12737 12757_fsm 12776_vm 12796 12811 12828 12847_fsm 12866 12912 12927 12953_vm 12973 12992 12737_fsm 12757_vm 12778 12797 12812 12828_fsm 12847_vm 12866_fsm 12913 12928 12955 12973_fsm 12993 12737_vm 12759 12780 12797_fsm 12813 12828_vm 12849 12866_vm 12913_fsm 12929 12956 12973_vm 12995 12739 12761 12781 12797_vm 12814 12830 12851 12868 12913_vm 12931 12957 12975 12997 12740 12762 12782 12799 12814_fsm 12830_fsm 12852 12869 12915 12932 12957_fsm 12977 pg_filenode.m ap 12741 12763 12783 12800 12814_vm 12830_vm 12853 12870 12916 12933 12957_vm 12978 PG_VERSION 12741_fsm 12764 12784 12801 12816 12832 12853_fsm 12871 12917 12935 12959 12978_fsm 12741_vm 12764_fsm 12785 12801_fsm 12817 12833 12853_vm 12871_fsm 12917_fsm 12936 12960 12978_vm 12743 12764_vm 12787 12801_vm 12818 12834 12855 12871_vm 12917_vm 12937 12962 12980 12744 12766 12788 12803 12818_fsm 12835 12856 12873 12919 12939 12963 12982 12749 12767 12789 12804 12818_vm 12837 12857 12874 12920 12940 12963_fsm 12983 12751 12768 12789_fsm 12805 12820 12839 12859 12906 12921 12942 12963_vm 12983_fsm 12752 12769 12789_vm 12805_fsm 12821 12840 12860 12906_fsm 12921_fsm 12943 12965 12983_vm 12753 12771 12791 12805_vm 12822 12841 12861 12906_vm 12921_vm 12944 12967 12985 12753_fsm 12773 12792 12807 12824 12842 12862 12908 12923 12946 12968 12987 12753_vm 12774 12793 12808 12825 12843 12862_fsm 12909 12924 12948 12968_fsm 12988 DB 생성 시 생성되는 파일들 select * from pg_class where relfilenode='12735’; 1. DB 생성 후, 무엇이 생성되는가?
  • 17.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions 2. Vacuum Full하면 새로운 파일이 생성되는데, 이전의 파일은 계속 있는가? [postgres@153_40 1262281]$ ls 1262282 12753 12771 12791 12805_vm 12822 12841 12861 12906_vm 12921_vm 12944 12967 12985 1262282_fsm 12753_fsm 12773 12792 12807 12824 12842 12862 12908 12923 12946 12968 12987 1262282_vm 12753_vm 12774 12793 12808 12825 12843 12862_fsm 12909 12924 12948 12968_fsm 12988 12735 12755 12775 12793_fsm 12809 12825_fsm 12845 12862_vm 12910 12925 12949 12968_vm 12988_fsm 12735_fsm 12756 12776 12793_vm 12809_fsm 12825_vm 12846 12864 12910_fsm 12925_fsm 12953 12970 12988_vm 12735_vm 12757 12776_fsm 12795 12809_vm 12827 12847 12865 12910_vm 12925_vm 12953_fsm 12972 12990 12737 12757_fsm 12776_vm 12796 12811 12828 12847_fsm 12866 12912 12927 12953_vm 12973 12992 12737_fsm 12757_vm 12778 12797 12812 12828_fsm 12847_vm 12866_fsm 12913 12928 12955 12973_fsm 12993 12737_vm 12759 12780 12797_fsm 12813 12828_vm 12849 12866_vm 12913_fsm 12929 12956 12973_vm 12995 12739 12761 12781 12797_vm 12814 12830 12851 12868 12913_vm 12931 12957 12975 12997 12740 12762 12782 12799 12814_fsm 12830_fsm 12852 12869 12915 12932 12957_fsm 12977 pg_filenode.map 12741 12763 12783 12800 12814_vm 12830_vm 12853 12870 12916 12933 12957_vm 12978 pg_internal.init 12741_fsm 12764 12784 12801 12816 12832 12853_fsm 12871 12917 12935 12959 12978_fsm PG_VERSION 12741_vm 12764_fsm 12785 12801_fsm 12817 12833 12853_vm 12871_fsm 12917_fsm 12936 12960 12978_vm 12743 12764_vm 12787 12801_vm 12818 12834 12855 12871_vm 12917_vm 12937 12962 12980 12744 12766 12788 12803 12818_fsm 12835 12856 12873 12919 12939 12963 12982 12749 12767 12789 12804 12818_vm 12837 12857 12874 12920 12940 12963_fsm 12983 12751 12768 12789_fsm 12805 12820 12839 12859 12906 12921 12942 12963_vm 12983_fsm 12752 12769 12789_vm 12805_fsm 12821 12840 12860 12906_fsm 12921_fsm 12943 12965 12983_vm <표준 Vacuum한 상태>
  • 18.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions 2. Vacuum Full하면 새로운 파일이 생성되는데, 이전의 파일은 계속 있는가? [postgres@153_40 1262281]$ ls 1262285 12753_vm 12774 12793 12808 12825 12843 12862_fsm 12909 12924 12948 12968_fsm 12988 12735 12755 12775 12793_fsm 12809 12825_fsm 12845 12862_vm 12910 12925 12949 12968_vm 12988_fsm 12735_fsm 12756 12776 12793_vm 12809_fsm 12825_vm 12846 12864 12910_fsm 12925_fsm 12953 12970 12988_vm 12735_vm 12757 12776_fsm 12795 12809_vm 12827 12847 12865 12910_vm 12925_vm 12953_fsm 12972 12990 12737 12757_fsm 12776_vm 12796 12811 12828 12847_fsm 12866 12912 12927 12953_vm 12973 12992 12737_fsm 12757_vm 12778 12797 12812 12828_fsm 12847_vm 12866_fsm 12913 12928 12955 12973_fsm 12993 12737_vm 12759 12780 12797_fsm 12813 12828_vm 12849 12866_vm 12913_fsm 12929 12956 12973_vm 12995 12739 12761 12781 12797_vm 12814 12830 12851 12868 12913_vm 12931 12957 12975 12997 12740 12762 12782 12799 12814_fsm 12830_fsm 12852 12869 12915 12932 12957_fsm 12977 pg_filenode.map 12741 12763 12783 12800 12814_vm 12830_vm 12853 12870 12916 12933 12957_vm 12978 pg_internal.init 12741_fsm 12764 12784 12801 12816 12832 12853_fsm 12871 12917 12935 12959 12978_fsm PG_VERSION 12741_vm 12764_fsm 12785 12801_fsm 12817 12833 12853_vm 12871_fsm 12917_fsm 12936 12960 12978_vm 12743 12764_vm 12787 12801_vm 12818 12834 12855 12871_vm 12917_vm 12937 12962 12980 12744 12766 12788 12803 12818_fsm 12835 12856 12873 12919 12939 12963 12982 12749 12767 12789 12804 12818_vm 12837 12857 12874 12920 12940 12963_fsm 12983 12751 12768 12789_fsm 12805 12820 12839 12859 12906 12921 12942 12963_vm 12983_fsm 12752 12769 12789_vm 12805_fsm 12821 12840 12860 12906_fsm 12921_fsm 12943 12965 12983_vm 12753 12771 12791 12805_vm 12822 12841 12861 12906_vm 12921_vm 12944 12967 12985 12753_fsm 12773 12792 12807 12824 12842 12862 12908 12923 12946 12968 12987 이전 파일은 사라짐 <Vacuum Full한 상태>
  • 19.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions 3. Delete 후 바로 Insert 하면, Delete 된 튜플에 Insert data가 삽입되는가? 순서 command 순서 command 1. Database 생성 create database vac; 9. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 2. oid 확인 oid2name | grep vac 10. myt 테이블에 vacuum 작업 vacuum myt; 3. 테이블 생성 create table myt(id char(7)); 11. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 4. pg_relation_path 확인 select pg_relation_filepath(‘myt’); 12. myt 테이블에 210부터 51건 삽입 insert into myt select generate_series(210,260); 5. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 13. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 6. myt 테이블에 100건 삽입 insert into myt select generate_series(100,199); 14. myt 테이블에 vacuum full 작업 vauum full myt; 7. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 15. 총 사이즈 확인 select pg_total_relation_size(‘myt’); 8. myt 테이블에서 id가 150이상이면 삭제 delete from myt where id>=‘150’; 16. pg_relation_path 확인 select pg_relation_filepath(‘myt’); insert into myt select generate_series(200,209);
  • 20.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions insert into myt select generate_series(100,199); 000000 07 00 00 00 38 5e 24 1a 00 00 00 00 a8 01 80 13 >....8^$.........< … 0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001380 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001390 64 00 01 00 02 08 18 00 11 31 39 39 20 20 20 20 >d........199 < 0013a0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0013b0 63 00 01 00 02 08 18 00 11 31 39 38 20 20 20 20 >c........198 < … 001980 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001990 34 00 01 00 02 08 18 00 11 31 35 31 20 20 20 20 >4........151 < 0019a0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019b0 33 00 01 00 02 08 18 00 11 31 35 30 20 20 20 20 >3........150 < … 001fe0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001ff0 01 00 01 00 02 08 18 00 11 31 30 30 20 20 20 20 >.........100 < Page Header + Item Pointer 100~199 Insert결과 Tuple * 실제 Dump를 옮겨놓은 엑셀 파일 http://cafe.naver.com/playexem/332
  • 21.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions delete from myt where id>=‘150’; 000000 07 00 00 00 a8 79 24 1a 00 00 00 00 a8 01 80 13 >.....y$.........< … 0001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001380 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 < 0013a0 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 0013b0 63 00 01 20 02 01 18 00 11 31 39 38 20 20 20 20 >c.. .....198 < … 001980 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 < 0019a0 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 < … 001fe0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001ff0 01 00 01 00 02 09 18 00 11 31 30 30 20 20 20 20 >.........100 < Delete 후 150부터 199까지 xmax 표시 Page Header + Item Pointer Tuple
  • 22.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions insert into myt select generate_series(200,209); 000000 07 00 00 00 a8 79 24 1a 00 00 00 00 a8 01 80 13 >.....y$.........< … 0001a0 a0 93 40 00 80 93 40 00 60 93 40 00 40 93 40 00 >..@...@.`.@.@.@.< 0001b0 20 93 40 00 00 93 40 00 e0 92 40 00 c0 92 40 00 > .@...@...@...@.< 0001c0 a0 92 40 00 80 92 40 00 60 92 40 00 40 92 40 00 >..@...@.`.@.@.@.< 0001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001250 6e 00 01 00 02 08 18 00 11 32 30 39 20 20 20 20 >n........209 < 001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001250 6e 00 01 00 02 08 18 00 11 32 30 39 20 20 20 20 >n........209 < … 001360 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001370 65 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >e........200 < 001380 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 < 001980 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 001990 34 00 01 20 02 01 18 00 11 31 35 31 20 20 20 20 >4.. .....151 < 0019a0 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 0019b0 33 00 01 20 02 01 18 00 11 31 35 30 20 20 20 20 >3.. .....150 < 0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 < … 001fc0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001fd0 02 00 01 00 02 09 18 00 11 31 30 31 20 20 20 20 >.........101 < 001fe0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001ff0 01 00 01 00 02 09 18 00 11 31 30 30 20 20 20 20 >.........100 < 새로 Insert 된 10건의 Item Pointer 10건을 insert 했을 때, • 10건에 대한 Item Pointer 생성 • Tuple에서는 delete된 튜플 위로 생성 Delete 된 튜플 위에 새로운 튜플 생성
  • 23.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions vacuum myt; 000000 07 00 00 00 58 96 24 1a 00 00 05 00 d0 01 80 18 >....X.$.........< … 0000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< … 0001a0 00 00 00 00 00 00 00 00 a0 99 40 00 80 99 40 00 >..........@...@.< 0001b0 60 99 40 00 40 99 40 00 20 99 40 00 00 99 40 00 >`.@.@.@. .@...@.< 0001c0 e0 98 40 00 c0 98 40 00 a0 98 40 00 80 98 40 00 >..@...@...@...@.< 0001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001250 6e 00 01 00 02 09 18 00 11 32 30 39 20 20 20 20 >n........209 < 001260 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001270 6d 00 01 00 02 09 18 00 11 32 30 38 20 20 20 20 >m........208 < … 001360 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001370 65 00 01 00 02 08 18 00 11 32 30 30 20 20 20 20 >e........200 < 001380 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 001390 64 00 01 20 02 01 18 00 11 31 39 39 20 20 20 20 >d.. .....199 < … 001860 b7 31 00 00 b8 31 00 00 00 00 00 00 00 00 00 00 >.1...1..........< 001870 3d 00 01 20 02 05 18 00 11 31 36 30 20 20 20 20 >=.. .....160 < 001880 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001890 6e 00 01 00 02 09 18 00 11 32 30 39 20 20 20 20 >n........209 < 0018a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0018b0 6d 00 01 00 02 09 18 00 11 32 30 38 20 20 20 20 >m........208 < … 0019a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019b0 65 00 01 00 02 09 18 00 11 32 30 30 20 20 20 20 >e........200 < 0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 < … 200~209 200~209 Vacuum 작업을 하면, 위에 존재하는 튜플들은 그대로 유지되고, delete 된 자리 150부터 200~209가 reuse됨 위의 Item Pointer는 아래의 200~209 튜플을 가리킴
  • 24.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions insert into myt select generate_series(210,260); 000000 07 00 00 00 58 96 24 1a 00 00 05 00 d0 01 80 18 >....X.$.........< … 0000e0 60 98 40 00 40 98 40 00 20 98 40 00 00 98 40 00 >`.@.@.@. .@...@.< 0000f0 e0 97 40 00 c0 97 40 00 a0 97 40 00 80 97 40 00 >..@...@...@...@.< … 0001b0 60 99 40 00 40 99 40 00 20 99 40 00 00 99 40 00 >`.@.@.@. .@...@.< 0001c0 e0 98 40 00 c0 98 40 00 a0 98 40 00 80 98 40 00 >..@...@...@...@.< 0001d0 20 92 40 00 00 00 00 00 00 00 00 00 00 00 00 00 > .@.............< 0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001220 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001230 6f 00 01 00 02 08 18 00 11 32 36 30 20 20 20 20 >o........260 < 001240 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001250 64 00 01 00 02 08 18 00 11 32 35 39 20 20 20 20 >d........259 < … 001860 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001870 33 00 01 00 02 08 18 00 11 32 31 30 20 20 20 20 >3........210 < 001880 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001890 6e 00 01 00 02 09 18 00 11 32 30 39 20 20 20 20 >n........209 < 0018a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0018b0 6d 00 01 00 02 09 18 00 11 32 30 38 20 20 20 20 >m........208 < … 0019a0 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019b0 65 00 01 00 02 09 18 00 11 32 30 30 20 20 20 20 >e........200 < 0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019d0 32 00 01 00 02 09 18 00 11 31 34 39 20 20 20 20 >2........149 < … 새로 Insert 된 51건 210~260 위에 남아있던 200~209는 새로 Insert된 210~260으로 reuse됨
  • 25.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. Questions vauum full myt; 000000 07 00 00 00 58 96 24 1a 00 00 05 00 d0 01 80 18 >....X.$.........< … 0000e0 60 98 40 00 40 98 40 00 20 98 40 00 00 98 40 00 >`.@.@.@. .@...@.< 0000f0 e0 97 40 00 c0 97 40 00 a0 97 40 00 80 97 40 00 >..@...@...@...@.< … 0001b0 60 99 40 00 40 99 40 00 20 99 40 00 00 99 40 00 >`.@.@.@. .@...@.< 0001c0 e0 98 40 00 c0 98 40 00 a0 98 40 00 80 98 40 00 >..@...@...@...@.< 0001d0 20 92 40 00 00 00 00 00 00 00 00 00 00 00 00 00 > .@.............< 0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 001220 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001230 6f 00 01 00 02 0b 18 00 11 32 36 30 20 20 20 20 >o........260 < 001240 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001250 6e 00 01 00 02 0b 18 00 11 32 30 39 20 20 20 20 >n........209 < … 001360 b9 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001370 65 00 01 00 02 0b 18 00 11 32 30 30 20 20 20 20 >e........200 < 001380 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 001390 64 00 01 00 02 0b 18 00 11 32 35 39 20 20 20 20 >d........259 < … 0019a0 bb 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019b0 33 00 01 00 02 0b 18 00 11 32 31 30 20 20 20 20 >3........210 < 0019c0 b7 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >.1..............< 0019d0 32 00 01 00 02 0b 18 00 11 31 34 39 20 20 20 20 >2........149 < … 100~149, 210~259, 200~209, 260 순으로 튜플이 정리됨 200~209 210~259 260 100~149
  • 26.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 02. [MySQL] Page Dump 분석 발표자: 연구컨텐츠팀 이근오
  • 27.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. MySQL Page Dump 분석 출처: 하등성(何登成) 블로그 http://hedengcheng.com/?p=118 하등성(何登成)이 분석한 Page 구조 그림 (중국어)
  • 28.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 출처: https://blog.jcole.us/2013/01/03/the- basics-of-innodb-space-file-layout/ MySQL Page Dump 분석 - 기본 Page 사이즈 : 16 KB - 모든 Page는 Header(38 Byte) 와 Trailer(8 Byte) 로 구성
  • 29.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. create table exem_i.t1 ( c1 char(04), c2 char(1), c3 char(7), c4 char(7) ) engine=innodb ; There are 5 directory slots beginning of free space Slot 1: Infimum을 가리킴 Slot M: Supremum을 가리킴 last record inserted at location Field Length Per Field 1 byte MySQL Page Dump 분석 위와 같은 구조로 T1 테이블을 생성하고, 12건의 데이터를 Insert 한 후, T1테이블에 해당되는 덤프파일을 분석한 내용
  • 30.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. 03. [MySQL] 통계정보 관리 발표자: 연구컨텐츠팀 이대덕
  • 31.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. MySQL 통계정보 관리 mysql> show global variables like '%stats%'; +--------------------------------------+---------------+ | Variable_name | Value | +--------------------------------------+---------------+ | innodb_stats_auto_recalc | ON | | innodb_stats_method | nulls_equal | | innodb_stats_on_metadata | OFF | | innodb_stats_persistent | ON | | innodb_stats_persistent_sample_pages | 20 | | innodb_stats_sample_pages | 8 | | innodb_stats_transient_sample_pages | 8 | | myisam_stats_method | nulls_unequal | +--------------------------------------+---------------+ 8 rows in set (0.01 sec) innodb_stats_auto_recalc ON boolean • 테이블의 로우가 10%이상 변경되면 recalculate함 • innodb_stats_persistent 가 on 되어있어야 함 • stats_auto_recalc로 테이블단위 설정 가능 innodb_stats_method myisam_stats_method nulls_equal nulls_equal nulls_unequal nulls_ignored • Null 값 처리방법(동일처리, 불일치, 무시) innodb_stats_on_metadata OFF boolean • SHOW TABLE STATUS 명령어사용 • INFORMATION_SCHEMA.TABLES 테이블과 INFORMATI ON_SCHEMA.STATISTICS 테이블에 엑세스 시 통계정 보 갱신 innodb_stats_persistent ON boolean • 통계정보를 영구적으로 디스크에 저장할지 여부, 테이블 생성시 stats_persistent 옵션으로 테이블 별 설정 가능 innodb_stats_persistent_sample_pages 20 integer • 통계정보를 디스크에 저장할 때 샘플링 페이지 수 innodb_stats_sample_pages • 5.6 버전부터 사용되지 않음 innodb_stats_transient_sample_pages 8 integer • 통계정보를 자동으로 수집할 때 샘플링 페이지 수 show global variables like ‘%stats%’;
  • 32.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. mysql> select * from mysql.innodb_table_stats; +---------------+---------------+---------------------+--------+----------------------+--------------------------+ | database_name | table_name | last_update | n_rows | clustered_index_size | sum_of_other_index_siz es | +---------------+---------------+---------------------+--------+----------------------+--------------------------+ | employees | employees | 2016-06-22 14:46:23 | 299468 | 929 | 0 | | exem_i | foo | 2016-06-20 14:51:25 | 0 | 1 | 0 | | exem_i | t1 | 2016-06-28 14:26:46 | 5 | 1 | 0 | | mysql | gtid_executed | 2016-06-20 10:55:38 | 0 | 1 | 0 | | mysqlslap | t1 | 2016-06-23 09:54:45 | 2 | 1 | 0 | | sys | sys_config | 2016-06-20 10:55:39 | 6 | 1 | 0 | +---------------+---------------+---------------------+--------+----------------------+--------------------------+ 6 rows in set (0.00 sec) database_name 데이터베이스 이름 table_name 테이블이나 파티션 이름 last_update 마지막으로 갱신된 시간 n_rows 로우 수 clustered_index_size 프라이머리 인덱스 사이즈(페이지) sum_of_other_index_sizes PK인덱스를 제외한 모든 인덱스의 사이 즈 합계 MySQL 통계정보 관리 select * from mysql.innodb_table_stats;
  • 33.
    © Copyrights 2001~2016,EXEM CO.,LTD. All Rights Reserved. MySQL 통계정보 관리 mysql> select * from mysql.innodb_index_stats where table_name = 'employees'; +---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+ | database_name | table_name | index_name | last_update | stat_name | stat_value | sample_size | stat_description | +---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+ | employees | employees | PRIMARY | 2016-06-22 14:46:23 | n_diff_pfx01 | 299468 | 20 | emp_no | | employees | employees | PRIMARY | 2016-06-22 14:46:23 | n_leaf_pages | 886 | NULL | Number of leaf pages in the index | | employees | employees | PRIMARY | 2016-06-22 14:46:23 | size | 929 | NULL | Number of pages in the index | +---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+ 3 rows in set (0.06 sec) database_name 데이터베이스 이름 table_name 테이블이나 파티션 이름 index_name 인덱스 이름 last_update 마지막으로 갱신된 시간 stat_name 통계정보의 이름 stat_value 해당 통계정보의 수치 sample_size stat_value를 측정할때의 샘플 링 한 사이즈 stat_description 해당 통계정보의 설명 select * from mysql.innodb_index_stats where table_name = 'employees';
  • 34.
    Research & Contents Blog Video E-mail NAVERhttp://cafe.naver.com/playexem ITPUB http://blog.itpub.net/31135309/ Wordpress https://playexem.wordpress.com/ Slideshare http://www.slideshare.net/playexem Youtube https://www.youtube.com/channel/UC5wKR _-A0eL_Pn_EMzoauJg Tudou http://www.tudou.com/home/maxgauge/ 교육 문의: 연구컨텐츠팀 김숙진 edu@ex-em.com © Copyrights 2001~2016, EXEM CO.,LTD. All Rights Reserved.