2020년 2월 3일 월요일

Greenplum 4 Vs Greenplum 6의 Age 변경 사항

1. 테스트 목적
   1) Greenplum 6에서는 테이블 및 데이터베이스의 age가 서서히 올라가도록 기능 개선.
      - Greenplum 5에서 Lazy XID (less frequent xid wrap around) 기능 개선. 
      - https://gpdb.docs.pivotal.io/500/relnotes/GPDB_500_README.html
      - Greenplum 6에서는 root 파티션에서 Age 계산 제거하도록 개선
      - https://github.com/greenplum-db/gpdb/commit/44f9776071c3ecbfbcf6015f66207157916665e9


   2) Greenplum 4와 Greenplum 6 에서의 트랜잭션 age 가 어떻게 증가하는지 확인.
      - Greenplum 4 vs 6에서 테스트 진행      
      
2. 테스트 스크립트
   1) DDL
   
CREATE TABLE public.test_date (
    log_date timestamp without time zone NOT NULL,
    test_id numeric,
    count numeric DEFAULT 0
) DISTRIBUTED BY (test_id) PARTITION BY RANGE(log_date)
          (
          PARTITION p2008 START ('2008-01-01'::timestamp without time zone) END ('2009-01-01'::timestamp without time zone) WITH (tablename='test_date_1_prt_p2008'),
          PARTITION p2009 START ('2009-01-01'::timestamp without time zone) END ('2010-01-01'::timestamp without time zone) WITH (tablename='test_date_1_prt_p2009'),
          PARTITION p2010 START ('2010-01-01'::timestamp without time zone) END ('2011-01-01'::timestamp without time zone) WITH (tablename='test_date_1_prt_p2010'),
          DEFAULT PARTITION pother  WITH (tablename='test_date_1_prt_pother', appendonly='false')
          );   
   
create table trx ( a int)
DISTRIBUTED BY (test_id);
   
   2) 트랜잭션 발생 스크립트
      $ insert_trx.sh
for i in `seq 1 100`
do
echo $i
    psql -c "insert into aaa values ( 1 );"
done
   
   3) 테이블 Age 확인 SQL #1 (Greenplum 4 용, 마스터 인스턴스의 age 확인)
       $ cat xid.sql

SELECT  relname, relkind, relstorage, age(relfrozenxid)

FROM  pg_class c
where relname like 'test_date%'
ORDER BY 4 DESC;   
   
   3) 테이블 Age 확인 SQL #2 (Greenplum 6 용, 모든 인스턴스의 age 확인)
      select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;
   

3. 테스트 수행

   1) Age 확인 SQL 수행 - 2번 트랜잭션 발생 스크립트를 수행하는 동안 계속 실행 수행
      $ while true; do date; psql -f xid.sql ; sleep 2; done
      $ select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;
   2) 트랜잭션 발생 ( Insert )    

4. 테스트 로그

   1) Greenplum 4
### Session #1
[gpadmin@mdw4 ~]$ while true; do date; psql -f xid.sql ; sleep 2; done
2020. 02. 04. (화) 10:19:00 KST
Timing is on.
 coalesce |        relname         | relkind | relstorage | age
----------+------------------------+---------+------------+-----
 public   | test_date              | r       | h          |  31
 public   | test_date_1_prt_p2008  | r       | h          |  30
 public   | test_date_1_prt_p2009  | r       | h          |  29
 public   | test_date_1_prt_p2010  | r       | h          |  28
 public   | test_date_1_prt_pother | r       | h          |  27
(5 rows)

Time: 7.489 ms

2020. 02. 04. (화) 10:19:02 KST
Timing is on.
 coalesce |        relname         | relkind | relstorage | age       
----------+------------------------+---------+------------+-----
 public   | test_date              | r       | h          |  33
 public   | test_date_1_prt_p2008  | r       | h          |  32
 public   | test_date_1_prt_p2009  | r       | h          |  31
 public   | test_date_1_prt_p2010  | r       | h          |  30
 public   | test_date_1_prt_pother | r       | h          |  29
(5 rows)

Time: 4.359 ms

===> Idle 한 상태에서도 Age 가 증가

./insert_trx.sh 수행 후 결과

....
....


2020. 02. 04. (화) 10:19:55 KST

Timing is on.
 coalesce |        relname         | relkind | relstorage | age         
----------+------------------------+---------+------------+-----
 public   | test_date              | r       | h          | 305
 public   | test_date_1_prt_p2008  | r       | h          | 304
 public   | test_date_1_prt_p2009  | r       | h          | 303
 public   | test_date_1_prt_p2010  | r       | h          | 302
 public   | test_date_1_prt_pother | r       | h          | 301
(5 rows)
===> trx 테이블에 DML 실행시에 타 테이블에서 Age 증가

### Session #2

[gpadmin@mdw4 ~]$ psql -c "select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;"
 gp_segment_id | age
---------------+-----
             0 |  22
             1 |  22
             2 |  22
             3 |  22
             4 |  22
             5 |  22
             6 |  22
             7 |  22
             8 |  22
             9 |  22
(10 rows)

[gpadmin@mdw4 ~]$ psql -c "select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;"

 gp_segment_id | age
---------------+-----
             0 |  24
             1 |  24
             2 |  24
             3 |  24
             4 |  24
             5 |  24
             6 |  24
             7 |  24
             8 |  24
             9 |  24
(10 rows)

./insert_trx.sh 수행 후 결과
...

gpadmin@mdw4 ~]$ psql -c "select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;"

 gp_segment_id | age
---------------+-----
             0 | 162
             1 | 160
             2 | 160
             3 | 160
             4 | 160
             5 | 160
             6 | 158
             7 | 160
             8 | 160
             9 | 160
(10 rows)
### trx 모든 인스턴스에서 골고루 age 가 증가 됨을 확인

### Session #3.  ---트랜잭션 발생

[gpadmin@mdw4 ~]$ ./insert_trx.sh
1
INSERT 0 1
2
INSERT 0 1
...
INSERT 0 1
100
INSERT 0 1
[gpadmin@mdw4 ~]$
   

   2) Greenplum 6

   
### Session #1
[gpadmin@mdw6 ~]$ while true; do date; psql -f xid.sql ; sleep 2; done
2020. 02. 04. (화) 10:28:00 KST
 coalesce |        relname         | relkind | relstorage |    age
----------+------------------------+---------+------------+------------
 public   | test_date              | r       | h          | 2147483647
 public   | test_date_1_prt_p2008  | r       | h          |          7
 public   | test_date_1_prt_p2009  | r       | h          |          7
 public   | test_date_1_prt_p2010  | r       | h          |          7
 public   | test_date_1_prt_pother | r       | h          |          7
(5 rows)

2020. 02. 04. (화) 10:28:02 KST

 coalesce |        relname         | relkind | relstorage |    age
----------+------------------------+---------+------------+------------
 public   | test_date              | r       | h          | 2147483647
 public   | test_date_1_prt_p2008  | r       | h          |          7
 public   | test_date_1_prt_p2009  | r       | h          |          7
 public   | test_date_1_prt_p2010  | r       | h          |          7
 public   | test_date_1_prt_pother | r       | h          |          7
(5 rows)   
....
./insert_trx.sh 수행 후 로그 

2020. 02. 04. (화) 10:28:21 KST

 coalesce |        relname         | relkind | relstorage |    age
----------+------------------------+---------+------------+------------
 public   | test_date              | r       | h          | 2147483647
 public   | test_date_1_prt_p2008  | r       | h          |          8
 public   | test_date_1_prt_p2009  | r       | h          |          8
 public   | test_date_1_prt_p2010  | r       | h          |          8
 public   | test_date_1_prt_pother | r       | h          |          8
(5 rows)
==> root 파티션의 age는 2^31 -1 으로 고정 됨.

### Session #2

[gpadmin@mdw6 ~]$ psql -c "select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;"
 gp_segment_id | age
---------------+-----
             0 |   1
             1 |   1
             2 |   1
             3 |   1
             4 |   1
             5 |   1
(6 rows)

[gpadmin@mdw6 ~]$ psql -c "select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;"

 gp_segment_id | age
---------------+-----
             0 |   1
             1 |   1
             2 |   1
             3 |   1
             4 |   1
             5 |   1
(6 rows)
....
./insert_trx.sh 수행 후 로그 

[gpadmin@mdw6 ~]$ psql -c "select gp_segment_id, age(relfrozenxid)  from gp_dist_random('pg_class') where relname = 'trx' order by 1;"

 gp_segment_id | age
---------------+-----
             0 |   1  #### 마스터 인스턴스의 age는 증가 없음.
             1 |   1
             2 |   1
             3 |   1
             4 | 101  #### 트랜잭션이 발생한 특정 세그먼트의 Table age만 증가
             5 |   1
(6 rows)
===> 마스터에서는 age가 올라가지 않고, 해당 세그먼트에만 Age가 증가 됨.

[gpadmin@mdw6 ~]$



5. 결론

   1) Greenplum 4
       - 트랜잭션을 일으키지 않는 테이블도 자동적으로 Age 가 증가.
       - Root 파티션도 Age 가 증가 됨.
       - 마스터 인스턴스의 Age와 각 세그먼트 인스턴스의 Age도 함께 증가.

   2) Greenplum 6

       - 트랜잭션을 일으키는 테이블에 한해서만 Age 가 증가.
       - Root 파티션의 Age는 항상 2^31 -1 값으로 셋팅 
         ## Root 파티션에 대해서는 Age 줄일 필요 없음.
       - 트랜잭션이 테이블의 해당 세그먼트에 대해서만 Age 상승.
    
   

댓글 없음:

댓글 쓰기

Greenplum Backup & Restore

Greenplum에서는 gpbackup과 gprestore를 이용해서 대량의 데이터를 병렬로 백업/병렬로 복구를 지원하고 있습니다. Full 백업이외에도 incremental 백업을 지원하고 있습니다.  - incremental 백업시에는 반드시 사전...