[PostgreSQL] Citusdata PG_AUTO_FAILOVER install on PostgreSQL15 (4) - Primary node 구성

4. Primary node 구성

1) Monitor node와 연결

(1) 옵션

- pg_autoctl create postgres --help 로 옵션 조회할 수 있습니다.

--pg_ctl : pg_ctl 경로 (보통 $PGHOME/bin 아래에 위치)
--pghost : PostgreSQL 의 hostname
--pgdata : pgdata 경로 (보통 $PGHOME/data)
--pgport : PostgreSQL DB 에 사용할 포트 (Default 5432)

--listen : PostgreSQL 의 listen address
--username : PostgreSQL 의 유저명
--dbname : PostgreSQL 의 데이터베이스명
--name : pg_auto_failover 에서 사용 할 노드명 (여기서는 Active 로 명명)
--hostname : 해당 node 의 hostname
--formation : pg_auto_failover 포메이션 (일종의 Logical Connection 으로 보면 됨)
--monitor : pg_auto_failover monitor URL (pg_autoctl show uri 로 조회 가능)
--auth : monitor 와의 연결에 사용할 인증 방식 [trust | password | scram-sha-256]
--skip-pg-hba : pg_hba 편집 하지 않기 (Default 는 pg_hba.conf 에 내용 추가됨)
--ssl-self-signed : 자체 서명된 인증서를 통해 네트워크 암호화
--no-ssl : ssl 암호화 사용하지 않음 (권장하지 않음, ssl-self-signed 사용 권장)
--ssl-mode : 연결에 사용 할 ssl 모드
--ssl-ca-file : Postgres ssl_ca_file 의 경로 설정
--ssl-crl-file : Postgres ssl_crl_file 의 경로 설정
--server-key : Postgres ssl_key_file 의 경로 설정
--server-cert : Postgres ssl_cert_file 의 경로 설정
--candidate-priority : Primary node 로 promote 하는 과정에서의 우선순위 지정
--replication-quorum : node 가 write quorum 에 사용될 경우 true
--maximum-backup-rate : 초기 복제 과정 중 데이터의 전송 속도

 

(2) Monitor node와 연결

[postgres@localhost data]$ pg_autoctl create postgres \
--pgctl /postgres/pgsql/bin/pg_ctl \
--pgdata /postgres/pgsql/data \
--hostname xxx.xxx.xxx.117 \
--pgport 5432 \
--auth trust \
--ssl-self-signed \
--monitor
postgres://autoctl_node@xxx.xxx.xxx.119:5432/pg_auto_failover?sslmode=require \
--name "Active"

17:55:34 119425 INFO Using default --ssl-mode "require"
17:55:34 119425 INFO Using --ssl-self-signed: pg_autoctl will create self-signed 
certificates, allowing for encrypted network traffic
17:55:34 119425 WARN Self-signed certificates provide protection against 
eavesdropping; this setup does NOT protect against Man-In-The-Middle attacks nor 
Impersonation attacks.
17:55:34 119425 WARN See https://www.postgresql.org/docs/current/libpq-ssl.html for 
details
17:55:34 119425 INFO Started pg_autoctl postgres service with pid 119428
17:55:34 119425 INFO Started pg_autoctl node-init service with pid 119429
17:55:34 119428 INFO /postgres/pgsql/bin/pg_autoctl do service postgres --pgdata 
/postgres/pgsql/data -v
17:55:34 119429 INFO Registering Postgres system 7238844049713875812 found at 
"/postgres/pgsql/data"
17:55:34 119429 INFO Registered node 1 "Active" (xxx.xxx.xxx.117:5432) in formation 
"default", group 0, state "single"
17:55:34 119429 INFO Writing keeper state file at 
"/postgres/.local/share/pg_autoctl/postgres/pgsql/data/pg_autoctl.state"
17:55:34 119429 INFO Writing keeper init state file at 
"/postgres/.local/share/pg_autoctl/postgres/pgsql/data/pg_autoctl.init"
17:55:34 119429 INFO Successfully registered as "single" to the monitor.
17:55:34 119429 INFO FSM transition from "init" to "single": Start as a single node
17:55:34 119429 INFO Initialising postgres as a primary
17:55:34 119429 INFO /usr/bin/openssl req -new -x509 -days 365 -nodes -text -out 
/postgres/pgsql/data/server.crt -keyout /postgres/pgsql/data/server.key -subj 
"/CN=xxx.xxx.xxx.117"
17:55:34 119435 INFO /postgres/pgsql/bin/postgres -D /postgres/pgsql/data -p 5432 
-h *
17:55:34 119429 INFO The user "postgres" already exists, skipping.
17:55:34 119429 INFO CREATE USER postgres
17:55:34 119429 INFO CREATE DATABASE postgres;
17:55:34 119429 INFO The database "postgres" already exists, skipping.
17:55:34 119429 INFO CREATE EXTENSION pg_stat_statements;
17:55:34 119429 INFO Disabling synchronous replication
17:55:34 119429 INFO Reloading Postgres configuration and HBA rules
17:55:34 119429 INFO /usr/bin/openssl req -new -x509 -days 365 -nodes -text -out 
/postgres/pgsql/data/server.crt -keyout /postgres/pgsql/data/server.key -subj 
"/CN=xxx.xxx.xxx.117"
17:55:34 119429 INFO Contents of "/postgres/pgsql/data/postgresql-autofailover.conf" have changed, overwriting
17:55:34 119428 INFO Postgres is now serving PGDATA "/postgres/pgsql/data" on port 
5432 with pid 119435
17:55:34 119429 INFO Reloading Postgres configuration and HBA rules
17:55:34 119429 INFO Transition complete: current state is now "single"
17:55:34 119429 INFO keeper has been successfully initialized.
17:55:34 119425 WARN pg_autoctl service node-init exited with exit status 0
17:55:34 119428 INFO Postgres controller service received signal SIGTERM, 
terminating
17:55:34 119428 INFO Stopping pg_autoctl postgres service
17:55:34 119428 INFO /postgres/pgsql/bin/pg_ctl --pgdata /postgres/pgsql/data --
wait stop --mode fast
17:55:34 119425 INFO Stop pg_autoctl

 

(3) PG_AUTO_FAILOVER 기동

[postgres@localhost data]$ pg_autoctl run --pgdata /postgres/pgsql/data &

[1] 119470
[postgres@localhost data]$ 17:57:05 119470 INFO Started pg_autoctl postgres service 
with pid 119473
17:57:05 119470 INFO Started pg_autoctl node-active service with pid 119474
17:57:05 119473 INFO /postgres/pgsql/bin/pg_autoctl do service postgres --pgdata 
/postgres/pgsql/data -v
17:57:05 119474 INFO /postgres/pgsql/bin/pg_autoctl do service node-active --
pgdata /postgres/pgsql/data -v
17:57:05 119474 INFO Reloaded the new configuration from 
"/postgres/.config/pg_autoctl/postgres/pgsql/data/pg_autoctl.cfg"
17:57:05 119474 INFO pg_autoctl service is running, current state is "single"
17:57:05 119482 INFO /postgres/pgsql/bin/postgres -D /postgres/pgsql/data -p 5432 
-h *
17:57:05 119474 WARN PostgreSQL was not running, restarted with pid 119482
17:57:05 119473 INFO Postgres is now serving PGDATA "/postgres/pgsql/data" on port 
5432 with pid 119482
17:57:06 119474 INFO New state for this node (node 1, "Active") 
(xxx.xxx.xxx.117:5432): single ➜ single

구성 완료 후 pg_autoctl 명령어를 통해 기동합니다.

pg_ctl 옵션을 명시해두었기에, pg_autoctl 명령어를 입력하는 것 만으로도 PostgreSQL DB를 기동할 수 있습니다.

 

(4) Monitor node 조회

17:55:34 3967 INFO Registering node 1 "Active" (xxx.xxx.xxx.117:5432) to formation 
"default" with replication quorum true and candidate priority 50 [50]
17:55:34 3967 INFO Setting goal state of node 1 "Active" (xxx.xxx.xxx.117:5432) to 
single as there is no other node.
17:55:34 3967 INFO New state for node 1 "Active" (xxx.xxx.xxx.117:5432): init ➜ 
single
17:55:34 3967 INFO New state is reported by node 1 "Active" (xxx.xxx.xxx.117:5432): 
"single"
17:55:34 3967 INFO New state for node 1 "Active" (xxx.xxx.xxx.117:5432): single ➜ 
single
17:55:42 3967 INFO Node node 1 "Active" (xxx.xxx.xxx.117:5432) is marked as 
unhealthy by the monitor
17:55:42 3967 INFO New state for node 1 "Active" (xxx.xxx.xxx.117:5432): single ➜ 
single

[postgres@localhost data]$ pg_autoctl show state
 Name | Node | Host:Port | TLI: LSN | Connection | Reported 
State | Assigned State
-------+-------+---------------------+----------------+--------------+--------------
-------+--------------------
Active | 1 | xxx.xxx.xxx.117:5432 | 1: 0/174F328 | read-write ! | 
single | single

Monitor node에 성공적으로 등록되었음을 확인할 수 있습니다.

 

 

참고사항

Citusdata PG_AUTO_FAILOVER의 저작권 및 라이선스는 아래의 링크를 참고 부탁드립니다.

https://github.com/hapostgres/pg_auto_failover/blob/main/LICENSE

https://github.com/hapostgres/pg_auto_failover/blob/main/NOTICE

 

또한, 해당 문서의 주요 목적은 테스트 환경 구현에 있습니다.

실제 환경에 적용 시 발생할 수 있는 문제에 대해서는 책임질 수 없다는 점 참고 부탁드립니다.

Designed by JB FACTORY