2023년 5월 16일 화요일

Greenplum Backup & Restore

Greenplum에서는 gpbackup과 gprestore를 이용해서 대량의 데이터를 병렬로 백업/병렬로 복구를 지원하고 있습니다.

Full 백업이외에도 incremental 백업을 지원하고 있습니다.
 - incremental 백업시에는 반드시 사전에 full 백업이 되어 있어야 합니다.
 - 복구시에는 full 백업/incremental 백업과 관계없이 동일한 옵션을 적용합니다. 



1. 백업 

1.1 Full Backup 

$ gpbackup --dbname edu --backup-dir /data/dbbackup/ --leaf-partition-data --with-stats --jobs 2 --verbose 

백업 Timestamp: 20230509114630, duration: 0:00:27, DB size: 2138 MB, backup size: 1GB


1.2 incremental backup

$ gpbackup --dbname edu --backup-dir /data/dbbackup/ --leaf-partition-data --with-stats --jobs 2 --incremental --verbose 

백업 Timestamp: 20230509114803, duration: 0:00:02, DB size: 2138 MB, backup size: 18MB




2. Database 재설치시의 복구 

2.1 role, resource queue/group, database 복구 - Database 재설치시 복구 (주의 사항: instance 구성이 기존과 동일해야 함) 

2.1.0 테스트 시나리오

- DB 재설치 이후 backup본으로 부터 DB 복구(role, resource queue/group 까지 복구)


2.1.1 Full backup에서 Database 복구        (role, resource queue/group, database 복구)

$ gprestore --timestamp 20230509114630 --backup-dir /data/dbbackup/ --create-db  --with-stats --with-globals --jobs 2 --verbose


2.1.2 incremental backup에서 Database 복구 (role, resource queue/group, database 복구)

$ gprestore --timestamp 20230509114803 --backup-dir /data/dbbackup/ --create-db  --with-stats --with-globals --jobs 2 --verbose




2.2 Database만 복구 

2.2.0 테스트 시나리오

- database drop 후 database만 복구


2.2.1 Full backup에서 Database 복구 (database만 복구)   

$ gprestore --timestamp 20230509114630 --backup-dir /data/dbbackup/ --create-db  --with-stats  --jobs 2 --verbose


2.2.1 incremental 에서 Database 복구 (database만 복구)

$ gprestore --timestamp 20230509114803 --backup-dir /data/dbbackup/ --create-db  --with-stats  --jobs 2 --verbose




2.3 특정 테이블만 복구 (파티션 포함, DDL 포함)

2.3.0 테스트 시나리오

- 파티션이 포함된 테이블 drop 이후 해당 테이블만 복구


2.3.1 Full backup에서 특정 테이블만 복구 (DDL 포함, 파티션 포함)                                 

$ gprestore --timestamp 20230509114630 --backup-dir /data/dbbackup/ --include-table edu_sch.orders  --with-stats --jobs 2 --verbose  


2.3.2 incremental backup에서 특정 테이블만 복구 (DDL 포함, 파티션 포함)                          

$ gprestore --timestamp 20230509114803 --backup-dir /data/dbbackup/ --include-table edu_sch.orders  --with-stats --jobs 2 --verbose  




2.4 특정 파티션만 복구 

2.4.0 테스트 시나리오

- 특정 파티션 truncate 이후 특정 파티션 데이터 복구


2.4.1 Full backup에서 특정 파티션만 복구                                                     

gprestore --timestamp 20230509114630 --backup-dir /data/dbbackup/ --include-table edu_sch.orders_1_prt_p1999  --data-only --verbose  


2.4.2 incremental backup에서 특정 파티션만 복구                                          

gprestore --timestamp 20230509114803 --backup-dir /data/dbbackup/ --include-table edu_sch.orders_1_prt_p1999  --data-only  --verbose  




3. 새로운 database로 복구

3.1 새로운 DB에서의 복구

3.1.0 테스트 시나리오

- 새로운 DB생성 후 새로 생성된 database에 복구 


3.1.1 Full backup에서 Database 복구 (database만 복구)                               

$ gprestore --timestamp 20230509114630 --backup-dir /data/dbbackup/ --redirect-db newedu --with-stats  --jobs 2 --verbose


3.1.1 incremental 에서 Database 복구 (database만 복구)                              

$ gprestore --timestamp 20230509114803 --backup-dir /data/dbbackup/ --redirect-db newedu --with-stats  --jobs 2 --verbose




4. 기존 database에서 새로운 스키마에 테이블 복구

4.1 기존 database에서 새로운 스키마에 테이블 복구

4.1.0 테스트 시나리오

- 스키마 새로 생성 한 후 생성된 스키마의 테이블에 복구

- edu_new 스키마 생성, 원본은 edu_sch.orders 이지만, edu_new.orders에 복구 


4.1.1 Full backup에서 특정 테이블만 복구 (DDL 포함, 파티션 포함), (테이블을 별도 생성하지 않음) 

$ gprestore --timestamp 20230509114630 --backup-dir /data/dbbackup/ --include-table edu_sch.orders   --redirect-schema edu_new --jobs 2 --verbose  


4.1.2 incremental backup에서 특정 테이블만 복구 (DDL 포함, 파티션 포함), (테이블을 별도 생성하지 않음)

$ gprestore --timestamp 20230509114803 --backup-dir /data/dbbackup/ --include-table edu_sch.orders   --redirect-schema edu_new --jobs 2 --verbose  




5. 기타 공유 사항

5.1 새로운 DB에 새로운 스키마에 복구시 에러 발생, 즉 --redirect-schema와 --redirect-db 혼횽해서 사용할 수는 없음.

5.2 데이터 복구시 분산키 위치가 맞지 않다고 에러 떨어지는 경우에는 randomly로 테이블 생성 후 적재

    - 에러 메시지 유형: ERROR: value of distribution key doesn't belong to segment with ID 0, it belongs to segment with ID 3 

GP2GP (Greenplum 클러스터간 연동, Greenplum_fdw)



Greenplum 6.20+에서는 클러스터간의 쿼리 실행할 수 있도록 Foreign data wrapper(FDW)를 제공합니다.

Greenplum FDW
 - Greenplum 클러스터간의 쿼리 실행할 수 있는 Foreign data wrapper(외부 데이터 래퍼)
 - Local Greenplum에서 Remote Greenplum 의 인스턴스 차이가 나더라도 병렬처리 지원
 - 외부 테이블에 대해서 조회 기능 제공
 - pushdown 기능 제공: 원격지의 테이블을 조회할 경우, index/파티션 수행후 결과 리턴 
   => 리모트의 테이블 전체를 가져오는 것이 아니라, 필요한 부분만 필터링해서 가져옴. 





1. 테스트 환경 

1.1 Remote

 - OS: CentOS Linux release 7.9

 - Greenplum: 6.21.0

 - 4 segment VM

 - 4 Primary segment instance 


1.2 Local

 - OS: Rocky Linux release 8.7 

 - Greenplum: 6.23.0

 - 1 segment VM

 - 2 Primary segment instance


2. 사전 준비

2.1 remote 서버

 -  Local 서버의 mdw/smdw/vip IP 등록

[gpadmin@mdw ~]$ vi $MASTER_DATA_DIRECTORY/pg_hba.conf

host    all          all             172.16.65.90/32        md5


2.2 local 서버

 - local 서버에서 remote 서버로 접속하기 때문에, local 서버에서 remote 서버 접속이 가능해야 함.

 - local 서버에서 remote 서버로 접속할 때에는 remote 서버의 hostname을 참고 함. 

 - gp_segment_configuration의 hostname 찾음.

 - local 서버에 /etc/hosts에 remote 서버 리스트가 포함 되어야 함.

 - ex) 


[gpadmin@r8g6single ~]$ cat /etc/hosts

# local server

172.16.65.90 r8g6single


# remote server 리스트 추가

172.16.65.141 c7g6mdw

172.16.65.141 c7g6sdw1

172.16.65.142 c7g6sdw2

172.16.65.143 c7g6sdw3

172.16.65.144 c7g6sdw4 



3. Greenplum_pdw 셋업

3.1 Remote

CREATE EXTENSION IF NOT EXISTS gp_parallel_retrieve_cursor;



3.2 Local

CREATE EXTENSION greenplum_fdw;

CREATE EXTENSION IF NOT EXISTS gp_parallel_retrieve_cursor;


--Options 옆에 -- 와 같은 주석 처리하면 안됨.

--클러스터간의 병렬 연동을 위해서는 2가지 옵션을 적용해야 함.

1) mpp_execute 'all segments' --병렬로 처리하기 위한 옵션

2) num_segments '4'  --원격지의 세그먼트 개수, default 값은 원격지 세그먼트 인스턴스 수,


CREATE SERVER gp_remote_edu

       FOREIGN DATA WRAPPER greenplum_fdw 

       OPTIONS (host '172.16.65.140',            

                port '5432',      

                dbname 'edu',                     

                mpp_execute 'all segments', 

                num_segments '4');


CREATE USER MAPPING FOR udba 

       SERVER gp_remote_edu 

       OPTIONS (user 'udba', password 'changeme');


CREATE USER MAPPING FOR gpadmin 

       SERVER gp_remote_edu 

       OPTIONS (user 'gpadmin', password 'changeme');


DROP FOREIGN TABLE remote.lineitem;

CREATE FOREIGN TABLE remote.lineitem (

    l_orderkey bigint NOT NULL,

    l_partkey integer NOT NULL,

    l_suppkey integer NOT NULL,

    l_linenumber integer NOT NULL,

    l_quantity numeric(15,2) NOT NULL,

    l_extendedprice numeric(15,2) NOT NULL,

    l_discount numeric(15,2) NOT NULL,

    l_tax numeric(15,2) NOT NULL,

    l_returnflag character(1) NOT NULL,

    l_linestatus character(1) NOT NULL,

    l_shipdate date NOT NULL,

    l_commitdate date NOT NULL,

    l_receiptdate date NOT NULL,

    l_shipinstruct character(25) NOT NULL,

    l_shipmode character(10) NOT NULL,

    l_comment character varying(44) NOT NULL

)

SERVER gp_remote_edu 

OPTIONS (schema_name 'edu_sch', table_name 'lineitem'); 


--test

select * from remote.lineitem limit 10;



4. 쿼리 테스트

4.1 remote 서버에서 internal table 쿼리 수행 (4vm, 4 primary segment)

edu=# select count(*) from edu_sch.lineitem where l_shipdate >= '19990101' and l_shipdate <'19990131';

 count

-------

  8894

(1 row)


Time: 103.797 ms

edu=#


4.2 local서버에서 remote 테이블에 쿼리 수행

- remote : 4 segment vms, 4 primary instances

- local  : 1 segment vms, 2 primary instances

## pushdown 기능제공,리모트  테이블에서는 파티션이 포함되어 있음.

gpadmin=# select count(*) from remote.lineitem where l_shipdate >= '19990101' and l_shipdate <'19990131';

 count

-------

  8894

(1 row)


Time: 350.271 ms

gpadmin=#


5. 규모 있는 장비에서 테스트한 결과

5.1 테스트 환경 

- Greenplum #1 : Master: 2VMs, Segment:   4VMs, 8 primay instance/VM, total primary:    32

- Greenplum #2 : Master: 2VMs, Segment: 3~4VMs, 8 primay instance/VM, total primary: 24~32


5.1 테스트 테이블

 - LOG 테이블   : 압축6.6GB, 비압축  12GB, 데이터 직렬화(array data)

 - MASTER 테이블: 압축 42MB, 비압축 294MB, row model 데이터

                        수행시간(초)     







Greenplum Backup & Restore

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