1. Install Environment
1) Monitor node
(1) OS Version : Rocky Linux 8.8
(2) RAM : 4096MB (4GB)
(3) IP Address : xxx.xxx.xxx.119
(4) Port : 5432
(5) PG Version : 15.2
2) Primary node
(1) OS Version : Rocky Linux 8.8
(2) RAM : 4096MB (4GB)
(3) IP Address : xxx.xxx.xxx.117
(4) Port : 5432
(5) PG Version : 15.2
3) Standby node
(1) OS Version : Rocky Linux 8.8
(2) RAM : 4096MB (4GB)
(3) IP Address : xxx.xxx.xxx.118
(4) Port : 5432
(5) PG Version : 15.2
2. Node 공통 설정 (Monitor / Primary / Standby)
들어가기에 앞서 PostgreSQL Install 및 conf 설정 과정은 기존 포스팅의 문서대로 진행했습니다. 보러가기
PostgreSQL 엔진이 설치되었다는 가정 하에 내용을 진행하도록 하겠습니다.
(1) PG_AUTO_FAILOVER Source Unzip
[postgres@localhost pgaf]$ unzip pg_auto_failover-main.zip
[postgres@localhost pgaf]$ cd pg_auto_failover-main/
[postgres@localhost pg_auto_failover-main]$ ls
cgmanifest.json CHANGELOG.md ci CONTRIBUTING.md docker-compose.yml Dockerfile
Dockerfile.docs Dockerfile.i386 docs LICENSE Makefile NOTICE pyproject.toml
README.md src tests valgrind
(2) Source Build
[postgres@localhost pg_auto_failover-main]$ make
[postgres@localhost pg_auto_failover-main]$ make install
(3) Postgresql.conf 수정
[postgres@localhost data]$ vi postgresql.conf
...
shared_preload_libraries = 'pgautofailover'
...
기존의 내용은 모두 유지한 채, 라이브러리만 추가 할 것입니다.
shared_preload_libraries에 pgautofailover를 작성합니다.
(4) pg_hba.conf 수정
[postgres@localhost data]$ vi pg_hba.conf
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 0.0.0.0/0 trust
기존의 내용에 위의 항목들을 추가해줍니다.
Replication privilege는 추가하지 않으셔도 됩니다.
node를 연결하는 과정에서 자동으로 내용이 추가됩니다.
제 블로그의 PG15 Install 포스팅을 참고하셨다면 이 부분은 넘어가셔도 될 듯 합니다.
(5) PostgreSQL Extension 확인
[postgres@localhost data]$ psql
psql (15.2)
Type "help" for help.
postgres=# \x
Expanded display is on.
postgres=# \dx
List of installed extensions
-[ RECORD 1 ]-----------------------------
Name | plpgsql
Version | 1.0
Schema | pg_catalog
Description | PL/pgSQL procedural language
현재 DB에는 Extension이 설치되지 않은 기본상태입니다.
(6) PG_AUTO_FAILOVER Extension 설치
postgres=# create extension btree_gist;
CREATE EXTENSION
postgres=# create extension pgautofailover;
CREATE EXTENSION
postgres=# \dx
List of installed extensions
-[ RECORD 1 ]----------------------------------------------
Name | btree_gist
Version | 1.7
Schema | public
Description | support for indexing common datatypes in GiST
-[ RECORD 2 ]----------------------------------------------
Name | pgautofailover
Version | 2.0
Schema | public
Description | pg_auto_failover
-[ RECORD 3 ]----------------------------------------------
Name | plpgsql
Version | 1.0
Schema | pg_catalog
Description | PL/pgSQL procedural language
btree_gist와 pgautofailover Extension을 설치합니다.
btree_gist는 pgautofailover의 Dependency Extension 입니다.
(7) PostgreSQL DB 종료
[postgres@localhost data]$ pg_ctl stop -D /postgres/pgsql/data
waiting for server to shut down.... done
server stopped
설정 완료 후 PostgreSQL DB 엔진을 종료합니다.
만약, 종료하지 않는다면, PG_AUTO_FAILOVER 구성 과정 중 아래의 오류가 발생하게 됩니다.
17:43:26 3899 ERROR Installing pg_auto_failover monitor in existing PostgreSQL
instance at "/postgres/pgsql/data" running on port 5432 is not supported.
참고사항
Citusdata PG_AUTO_FAILOVER의 저작권 및 라이선스는 아래의 링크를 참고 부탁드립니다.
https://github.com/hapostgres/pg_auto_failover/blob/main/LICENSE
https://github.com/hapostgres/pg_auto_failover/blob/main/NOTICE
또한, 해당 문서의 주요 목적은 테스트 환경 구현에 있습니다.
실제 환경에 적용 시 발생할 수 있는 문제에 대해서는 책임질 수 없다는 점 참고 부탁드립니다.