Ubuntu - PostgreSQL 이중화 환경세팅

작성자 김성민

Description

Ubuntu(22.04) 환경에 PostgreSQL 이중화 (Active - Standby)를 구성한다. Active Server는 CRUD가 가능하나, Standby Server는 read-only가 적용된다. Active Server에 작성되는 Data를 Streaming 방식으로 Standby Server에 적용 시킨다.

Main Server Standby Server
OS Ubuntu 22.04 Ubuntu 22.04
DB PostgreSQL 15 PostgreSQL 15

How To Install PostgreSQL 15 on Ubuntu 22.04 / 20.04

Ubuntu 22.04에는 PostgreSQL을 install하면 기본적으로 PostgreSQL 14가 설치된다.

그렇기에 PostgreSQL 15 Package Repository를 활성화 해야 한다.

환경 세팅


PostgreSQL 15 패키지 리포지토리 활성화

sudo apt update && sudo apt dist-upgrade -y
sudo apt install gnupg2 wget vim -y
# 설치할 수 있는 postgresql 확인 명령어
sudo apt-cache search postgresql | grep postgresql

# PostgreSQL 15는 기본 패키지 리포지토리에서 사용할 수 없으므로 다음 명령을 실행하여
# 공식 패키지 리포지토리를 활성화하여 설치를 시작합니다.
# 1째줄에 lsb_release가 없다고 뭐라뭐라하면 /etc/apt/sources.list.d/pgdg.list를 확인하여 앞의 주소를 고쳐준다.
sudo sh -c 'echo "deb <http://apt.postgresql.org/pub/repos/apt> $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# 다음으로 리포지토리의 GPG 서명 키를 가져옵니다. 다음 명령을 실행하여 이를 수행하십시오.
wget -qO- <https://www.postgresql.org/media/keys/ACCC4CF8.asc> | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null

# 마지막으로 위의 변경 사항이 적용될 수 있도록 시스템 패키지를 업데이트합니다.
sudo apt update -y

README - http://apt.postgresql.org/pub/repos/apt/README