간마늘작업소

[PGSQL] PostgreSQL 11 – 02.Replication(복제) 설정 본문

Linux/31.PostgreSQL

[PGSQL] PostgreSQL 11 – 02.Replication(복제) 설정

간마늘 2022. 7. 5. 10:52

0.개요

 

1.사전 환경.

  • Master 1대 - Standby 1대로 구성할 것을 가정.

 

2.Master Node 설정

su - postgres

cd /data/pgdata/
mkdir archive
vi postgresql.conf
(전략)
wal_level = hot_standby
archive_mode = on
archive_command = 'cp %p /data/pgdata/archive/%f'
max_wal_senders = 10
max_replication_slots = 10
  • postgresql.conf 파일 하단에 내용 추가.
vi pg_hba.conf
(전략)
host    replication     all             [Master Node IP]/32        trust
host    replication     all             [Standby Node IP]/32        trust
  • pg_hba.conf 파일 하단에 위치한 '# replication privilege.' 부분에 내용 추가 후 저장.
psql
ALTER USER postgres WITH PASSWORD 'postgres';
\du

exit
pg_ctl restart -mf
  • PostgreSQL 콘솔 접속 후, 'postgres' 계정의 비밀번호를 설정.
  • PostgreSQL 재시작.

 

3.Standby Node 설정

su - postgres

cd /data
rm -rf pgdata
  • 데이터 디렉토리의 상위 디렉토리로 이동.
    • 이름이 중복되어 있을 수 있으므로 사전에 확인 후 정리해야함.
pg_basebackup -h [Master Node IP] -D /data/pgdata/ -P -v -X stream
  • pg_basebackup 명령어를 이용하여 Master Node의 데이터 디렉토리를 복제.
cd /data/pgdata
vi recovery.conf
standby_mode = on
primary_conninfo = 'host=[Master DB IP] port=5432 user=postgres password=postgres'
  • recovery.conf 파일 작성 후 저장.
chmod -R 0750 /data/pgdata

pg_ctl start
  • 데이터 디렉토리 권한 조정.
  • PostgreSQL 시작.
Comments