- 개요
- Replication 설정 없이, WAL 파일로만 Database를 Restore할 수 있는가? - 시나리오
1) SS가 무너진 경우, DR로 서비스 이전.
2) DR에서 서비스 중영중, SS 복구로 DR의 쌓인 데이터를 다시 SS로 가져옴 - 세팅
1) 서버 2대 동시 생성
2) Archieve Log Enable
## vi /etc/postgresql/9.6/main/postgresql.conf
#------------------------------------------------------------------------------
# WRITE AHEAD LOG
#------------------------------------------------------------------------------
# - Settings -
wal_level = archive # minimal, replica, or logical
# (change requires restart)
# - Archiving -
archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'test ! -f /archivelog/%f && cp %p /archivelog/%f' # command to use to archive a logfile segment
# placeholders: %p = path of file to archive
# %f = file name only
# e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
archive_timeout = 120 # force a logfile segment switch after this
# number of seconds; 0 disables
3) jmeter를 통해 100만 row insert
sdb001=# select count(*) from test;
count
---------
1195086
(1개 행)
4) rsync를 통해 arhive log 전달 (svr 1 → 2)
root@C1-L-SAOF1-PSQL-47-014:/home/DEVOPS# rsync -avz --progress -e 'ssh -p 2022' /archivelog/ root@10.70.165.13:/archivelog
root@1*.**.1**.**'s password:
sending incremental file list
5) Recovery config 작성
recovery.conf 는 postgresql의 data directory에 작성해야 한다.
F1DB는
/var/lib/postgresql/9.6/main
restore_command 'cp /archivelog/%f %p'
6) 서버 실행
# tail -f /auditlog/postgresql*
WAL File (archive Log)를 통한 Failover는 정상 확인.
sdb001=# select count(*) from test;
count
---------
1195086
(1개 행)
7) Failback
- 2번서버에서 200만 row Insert
sdb001=# select count(*) from test;
count
---------
3195086
(1개 행)
8) 양쪽 DB Stop이후, Archivelog 이동. (svr 2 → svr 1)
9) DB01 Restart
'DBA > Postgresql' 카테고리의 다른 글
| wal_log_hint에 대한 테스트 (0) | 2024.05.03 |
|---|---|
| Failover & Failback (pg_rewind) (1) | 2024.05.03 |
| 테이블 생성시 자동을 신규 테이블에 grant하는 trigger (0) | 2024.05.03 |
| PostgreSQL Type(JSON과 JSONB 타입) (0) | 2024.05.03 |
| PostgreSQL 테이블 생성 및 변경 (1) | 2024.05.03 |