간마늘작업소

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

Linux/31.PostgreSQL

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

간마늘 2022. 7. 4. 15:02

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     replication     [Standby Node IP]/32        trust
  • pg_hba.conf 파일 하단에 위치한 '# replication privilege.' 부분에 내용 추가 후 저장.
psql
create role replication with replication password 'password' login;
\du

exit
pg_ctl restart -mf
  • PostgreSQL 콘솔 접속 후, 복제 목적의 계정인 'replication'을 생성.
  • PostgreSQL 재시작.

 

3.Standby Node 설정

su - postgres

cd /data
rm -rf pgdata
  • 데이터 디렉토리의 상위 디렉토리로 이동.
    • 이름이 중복되어 있을 수 있으므로 사전에 확인 후 정리해야함.
pg_basebackup -h [Master Node IP] -D /data/pgdata -U replication -P -v  -R -X stream -C -S pgstandby1
  • pg_basebackup 명령어를 이용하여 Master Node의 데이터 디렉토리를 복제.
cd /data/pgdata
touch standby.signal
  • standby.signal 파일 생성.
cat postgresql.auto.conf
  • 자동으로 생성된 postgresql.auto.conf 파일의 내용 확인.
    • user 이름이 'replication' 인지 확인.
    • Master Node의 IP 확인.
chmod -R 0750 /data/pgdata

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