ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • repmgr 설치
    PostgreSQL 2019. 10. 14. 16:02

    repmgr 시나리오(로컬 환경에서 3개의 agensgraph instance로 진행)

    • primary server의 postgresql.conf에 replication 설정
      • max_wal_senders = 10
      • wal_level = 'hot_standby'
      • hot_standby = on
      • archive_mode = on
      • archive_command = '/bin/true'
      • wal_log_hints = on
    • repmgr 사용자와 metadata용 데이터베이스를 생성
      • $ createuser -s repmgr
      • $ createdb repmgr -O repmgr  
    • pg_hba.conf 설정
      • local replication repmgr trust
        host replication repmgr 127.0.0.1/32 trust
        host replication repmgr 192.168.1.0/24 trust

        local repmgr repmgr trust
        host repmgr repmgr 127.0.0.1/32 trust
        host repmgr repmgr 192.168.1.0/24 trust

    • primary server에 repmgr-primary.conf 생성
      • node_id=1
        node_name=node1
        conninfo='host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2'
        data_directory='/home/bylee/install/agensgraph/pdata'

      • pg_bindir=/home/bylee/install//agensgraph/bin

    • primary server 등록

      • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf primary register
      • 확인
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf cluster show
        • repmgr=# SELECT * FROM repmgr.nodes;
    • standby server 구성
      • standby server에서 primary database에 연결 가능한지 확인
        • $ psql 'host=localhostport=5432 user=repmgr dbname=repmgr connect_timeout=2'
      • standby에 repmgr-standby.conf 생성
        • node_id=2
          node_name=node2
          conninfo='host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2'
          data_directory='/home/bylee/install/agensgraph/sdata'

        • pg_bindir=/home/bylee/install//agensgraph/bin

      • --dry-run 옵션으로 구성 여부 확인

        • $ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby clone --dry-run
      • 오류가 없다면 primary를 복사
        • $ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby clone
      • postgresql.conf의 port 변경(5433) 및 standby 시작
      • standby server 등록
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby register
          • 확인
            • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
            • repmgr=# SELECT * FROM repmgr.nodes;
      • standby에 repmgr-standby2.conf 생성
        • node_id=3
          node_name=node3
          conninfo='host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2'
          data_directory='/home/bylee/install/agensgraph/sdata2'

        • pg_bindir=/home/bylee/install//agensgraph/bin

      • --dry-run 옵션으로 구성 여부 확인

        • $ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby2.conf standby clone --dry-run
      • 오류가 없다면 primary를 복사
        • $ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby2.conf standby clone
      • postgresql.conf의 port 변경(5434) 및 standby 시작
      • standby server 등록
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf standby register
          • 확인
            • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
            • repmgr=# SELECT * FROM repmgr.nodes;
    • primary에 vertex 추가
    • standby에서 vertex 확인
    • 수동 failover
      • primary server 정지
        • $ ag_ctl -D /home/bylee/install/agensgraph/pdata -m fast stop
      • primary server 정지 확인
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf cluster show
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
      • standby server에서 promoting(명령어를 실행한 곳의 standby를 primary로 승격시킴)
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby promote
      • promoting 확인
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
      • following
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf  standby follow
      • following 확인
        • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
    • failback
      • failback 여부 확인
        • $ /home/bylee/ha/repmgr/repmgr standby switchover -f /home/bylee/ha/config/repmgr-standby2.conf --siblings-follow --dry-run
      • new primary로 만들 standby server에서 failback 실행
        • $ /home/bylee/ha/repmgr/repmgr -f  /home/bylee/ha/config/repmgr-standby2.conf standby switchover
      • failback 확인
        •  /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
    • 번외 테스트 
      • old primary server를 standby server로 role 변경
        • old primary server  시작
          • $ ag_ctl -D /home/bylee/install/agensgraph/pdata start
        • old primary server 시작 확인
          • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
        • old primary server를 standby server로 role 변경하기 위해서는 primary server clone하여 old primary server를 덮어쓰기 해야 한다.
          • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf --force  -h localhost -p 5434 -d repmgr -U repmgr --verbose standby clone
        • port 변경 및 시작 
          • $ vi postgresql.conf
          • $  ag_ctl -D /home/bylee/install/agensgraph/pdata start
        • --force 추가하여 standby register 명령어 실행
          • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf --force standby register
        • 확인
          • $ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show

    다음은 repmgr 시나리오를 실행한 명령어이다.

    --준비
    [bylee@localhost ha]$ sudo yum groupinstall "Development Tools"
    [bylee@localhost ha]$ sudo yum install yum-utils openjade docbook-dtds docbook-style-dsssl docbook-style-xsl
     
    --소스코드 다운로드
    [bylee@localhost ha]$ git clone https://github.com/2ndQuadrant/repmgr.git
    [bylee@localhost ha]$ cd repmgr/
    [bylee@localhost repmgr]$ ll
    합계 1176
    -rw-rw-r--. 1 bylee bylee   1286  8월 22 15:41 CONTRIBUTING.md
    -rw-rw-r--. 1 bylee bylee    692  8월 22 15:41 COPYRIGHT
    -rw-rw-r--. 1 bylee bylee    593  8월 22 15:41 CREDITS
    -rw-rw-r--. 1 bylee bylee    337  8월 22 15:41 FAQ.md
    -rw-rw-r--. 1 bylee bylee  24120  8월 22 15:41 HISTORY
    -rw-rw-r--. 1 bylee bylee  35148  8월 22 15:41 LICENSE
    -rw-rw-r--. 1 bylee bylee    628  8월 22 15:41 Makefile.global.in
    -rw-rw-r--. 1 bylee bylee   2895  8월 22 15:41 Makefile.in
    -rw-rw-r--. 1 bylee bylee   5143  8월 22 15:41 PACKAGES.md
    -rw-rw-r--. 1 bylee bylee   2996  8월 22 15:41 README.md
    -rw-rw-r--. 1 bylee bylee    700  8월 22 15:41 TODO.md
    -rw-rw-r--. 1 bylee bylee   2786  8월 22 15:41 compat.c
    -rw-rw-r--. 1 bylee bylee   1037  8월 22 15:41 compat.h
    -rw-rw-r--. 1 bylee bylee     65  8월 22 15:41 config.h.in
    -rw-rw-r--. 1 bylee bylee  53233  8월 22 15:41 configfile.c
    -rw-rw-r--. 1 bylee bylee   8360  8월 22 15:41 configfile.h
    -rwxrwxr-x. 1 bylee bylee  92904  8월 22 15:41 configure
    -rw-rw-r--. 1 bylee bylee   1934  8월 22 15:41 configure.in
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 contrib
    -rw-rw-r--. 1 bylee bylee   7022  8월 22 15:41 controldata.c
    -rw-rw-r--. 1 bylee bylee   8687  8월 22 15:41 controldata.h
    -rw-rw-r--. 1 bylee bylee 117307  8월 22 15:41 dbutils.c
    -rw-rw-r--. 1 bylee bylee  16971  8월 22 15:41 dbutils.h
    -rw-rw-r--. 1 bylee bylee   7971  8월 22 15:41 dirutil.c
    -rw-rw-r--. 1 bylee bylee   1276  8월 22 15:41 dirutil.h
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 doc
    -rw-rw-r--. 1 bylee bylee   1518  8월 22 15:41 errcode.h
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 expected
    -rw-rw-r--. 1 bylee bylee   8479  8월 22 15:41 log.c
    -rw-rw-r--. 1 bylee bylee   4570  8월 22 15:41 log.h
    -rw-rw-r--. 1 bylee bylee    136  8월 22 15:41 repmgr--4.0--4.1.sql
    -rw-rw-r--. 1 bylee bylee   5456  8월 22 15:41 repmgr--4.0.sql
    -rw-rw-r--. 1 bylee bylee    136  8월 22 15:41 repmgr--4.1--4.2.sql
    -rw-rw-r--. 1 bylee bylee   5456  8월 22 15:41 repmgr--4.1.sql
    -rw-rw-r--. 1 bylee bylee   5456  8월 22 15:41 repmgr--4.2.sql
    -rw-rw-r--. 1 bylee bylee   7685  8월 22 15:41 repmgr--unpackaged--4.0.sql
    -rw-rw-r--. 1 bylee bylee  14462  8월 22 15:41 repmgr-action-bdr.c
    -rw-rw-r--. 1 bylee bylee    928  8월 22 15:41 repmgr-action-bdr.h
    -rw-rw-r--. 1 bylee bylee  35578  8월 22 15:41 repmgr-action-cluster.c
    -rw-rw-r--. 1 bylee bylee   1343  8월 22 15:41 repmgr-action-cluster.h
    -rw-rw-r--. 1 bylee bylee  71293  8월 22 15:41 repmgr-action-node.c
    -rw-rw-r--. 1 bylee bylee    997  8월 22 15:41 repmgr-action-node.h
    -rw-rw-r--. 1 bylee bylee  15340  8월 22 15:41 repmgr-action-primary.c
    -rw-rw-r--. 1 bylee bylee    916  8월 22 15:41 repmgr-action-primary.h
    -rw-rw-r--. 1 bylee bylee 180406  8월 22 15:41 repmgr-action-standby.c
    -rw-rw-r--. 1 bylee bylee   1248  8월 22 15:41 repmgr-action-standby.h
    -rw-rw-r--. 1 bylee bylee  13191  8월 22 15:41 repmgr-action-witness.c
    -rw-rw-r--. 1 bylee bylee    955  8월 22 15:41 repmgr-action-witness.h
    -rw-rw-r--. 1 bylee bylee   6614  8월 22 15:41 repmgr-client-global.h
    -rw-rw-r--. 1 bylee bylee  73421  8월 22 15:41 repmgr-client.c
    -rw-rw-r--. 1 bylee bylee   7480  8월 22 15:41 repmgr-client.h
    -rw-rw-r--. 1 bylee bylee   9087  8월 22 15:41 repmgr.c
    -rw-rw-r--. 1 bylee bylee  17108  8월 22 15:41 repmgr.conf.sample
    -rw-rw-r--. 1 bylee bylee    163  8월 22 15:41 repmgr.control
    -rw-rw-r--. 1 bylee bylee   3112  8월 22 15:41 repmgr.h
    -rw-rw-r--. 1 bylee bylee     63  8월 22 15:41 repmgr_version.h.in
    -rw-rw-r--. 1 bylee bylee  17166  8월 22 15:41 repmgrd-bdr.c
    -rw-rw-r--. 1 bylee bylee    911  8월 22 15:41 repmgrd-bdr.h
    -rw-rw-r--. 1 bylee bylee  84400  8월 22 15:41 repmgrd-physical.c
    -rw-rw-r--. 1 bylee bylee   1017  8월 22 15:41 repmgrd-physical.h
    -rw-rw-r--. 1 bylee bylee  20025  8월 22 15:41 repmgrd.c
    -rw-rw-r--. 1 bylee bylee    756  8월 22 15:41 repmgrd.h
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 scripts
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 sql
    -rw-rw-r--. 1 bylee bylee   8902  8월 22 15:41 strutil.c
    -rw-rw-r--. 1 bylee bylee   4120  8월 22 15:41 strutil.h
    -rw-rw-r--. 1 bylee bylee    890  8월 22 15:41 voting.h
     
    --빌드
    [bylee@localhost repmgr]$ ./configure && make install
    checking for a sed that does not truncate output... /usr/bin/sed
    checking for pg_config... /home/bylee/install/agensgraph/bin/pg_config
    configure: building against PostgreSQL 10.3
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating Makefile.global
    config.status: creating doc/Makefile
    config.status: creating config.h
    Building against PostgreSQL 10
    (...)
    /usr/bin/mkdir -p '/home/bylee/install/agensgraph/lib/postgresql'
    /usr/bin/mkdir -p '/home/bylee/install/agensgraph/share/postgresql/extension'
    /usr/bin/mkdir -p '/home/bylee/install/agensgraph/share/postgresql/extension'
    /usr/bin/mkdir -p '/home/bylee/install/agensgraph/bin'
    /usr/bin/install -c -m 755  repmgr.so '/home/bylee/install/agensgraph/lib/postgresql/repmgr.so'
    /usr/bin/install -c -m 644 .//repmgr.control '/home/bylee/install/agensgraph/share/postgresql/extension/'
    /usr/bin/install -c -m 644 .//repmgr--unpackaged--4.0.sql .//repmgr--4.0.sql .//repmgr--4.0--4.1.sql .//repmgr--4.1.sql .//repmgr--4.1--4.2.sql .//repmgr--4.2.sql  '/home/bylee/install/agensgraph/share/postgresql/extension/'
    /usr/bin/install -c -m 755 repmgr repmgrd '/home/bylee/install/agensgraph/bin/'
    [bylee@localhost repmgr]$ ll
    합계 2924
    -rw-rw-r--. 1 bylee bylee   1286  8월 22 15:41 CONTRIBUTING.md
    -rw-rw-r--. 1 bylee bylee    692  8월 22 15:41 COPYRIGHT
    -rw-rw-r--. 1 bylee bylee    593  8월 22 15:41 CREDITS
    -rw-rw-r--. 1 bylee bylee    337  8월 22 15:41 FAQ.md
    -rw-rw-r--. 1 bylee bylee  24120  8월 22 15:41 HISTORY
    -rw-rw-r--. 1 bylee bylee  35148  8월 22 15:41 LICENSE
    -rw-rw-r--. 1 bylee bylee   2929  8월 22 15:46 Makefile
    -rw-rw-r--. 1 bylee bylee    707  8월 22 15:46 Makefile.global
    -rw-rw-r--. 1 bylee bylee    628  8월 22 15:41 Makefile.global.in
    -rw-rw-r--. 1 bylee bylee   2895  8월 22 15:41 Makefile.in
    -rw-rw-r--. 1 bylee bylee   5143  8월 22 15:41 PACKAGES.md
    -rw-rw-r--. 1 bylee bylee   2996  8월 22 15:41 README.md
    -rw-rw-r--. 1 bylee bylee    700  8월 22 15:41 TODO.md
    -rw-rw-r--. 1 bylee bylee   2786  8월 22 15:41 compat.c
    -rw-rw-r--. 1 bylee bylee   1037  8월 22 15:41 compat.h
    -rw-rw-r--. 1 bylee bylee   2792  8월 22 15:47 compat.o
    -rw-rw-r--. 1 bylee bylee    124  8월 22 15:46 config.h
    -rw-rw-r--. 1 bylee bylee     65  8월 22 15:41 config.h.in
    -rw-rw-r--. 1 bylee bylee   3745  8월 22 15:46 config.log
    -rwxrwxr-x. 1 bylee bylee  27015  8월 22 15:46 config.status
    -rw-rw-r--. 1 bylee bylee  53233  8월 22 15:41 configfile.c
    -rw-rw-r--. 1 bylee bylee   8360  8월 22 15:41 configfile.h
    -rw-rw-r--. 1 bylee bylee  85832  8월 22 15:47 configfile.o
    -rwxrwxr-x. 1 bylee bylee  92904  8월 22 15:41 configure
    -rw-rw-r--. 1 bylee bylee   1934  8월 22 15:41 configure.in
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 contrib
    -rw-rw-r--. 1 bylee bylee   7022  8월 22 15:41 controldata.c
    -rw-rw-r--. 1 bylee bylee   8687  8월 22 15:41 controldata.h
    -rw-rw-r--. 1 bylee bylee   6776  8월 22 15:47 controldata.o
    -rw-rw-r--. 1 bylee bylee 117307  8월 22 15:41 dbutils.c
    -rw-rw-r--. 1 bylee bylee  16971  8월 22 15:41 dbutils.h
    -rw-rw-r--. 1 bylee bylee 139400  8월 22 15:47 dbutils.o
    -rw-rw-r--. 1 bylee bylee   7971  8월 22 15:41 dirutil.c
    -rw-rw-r--. 1 bylee bylee   1276  8월 22 15:41 dirutil.h
    -rw-rw-r--. 1 bylee bylee   9904  8월 22 15:47 dirutil.o
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:46 doc
    -rw-rw-r--. 1 bylee bylee   1518  8월 22 15:41 errcode.h
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 expected
    -rw-rw-r--. 1 bylee bylee   8479  8월 22 15:41 log.c
    -rw-rw-r--. 1 bylee bylee   4570  8월 22 15:41 log.h
    -rw-rw-r--. 1 bylee bylee  10224  8월 22 15:47 log.o
    -rwxrwxr-x. 1 bylee bylee 440368  8월 22 15:47 repmgr
    -rw-rw-r--. 1 bylee bylee    136  8월 22 15:41 repmgr--4.0--4.1.sql
    -rw-rw-r--. 1 bylee bylee   5456  8월 22 15:41 repmgr--4.0.sql
    -rw-rw-r--. 1 bylee bylee    136  8월 22 15:41 repmgr--4.1--4.2.sql
    -rw-rw-r--. 1 bylee bylee   5456  8월 22 15:41 repmgr--4.1.sql
    -rw-rw-r--. 1 bylee bylee   5456  8월 22 15:41 repmgr--4.2.sql
    -rw-rw-r--. 1 bylee bylee   7685  8월 22 15:41 repmgr--unpackaged--4.0.sql
    -rw-rw-r--. 1 bylee bylee  14462  8월 22 15:41 repmgr-action-bdr.c
    -rw-rw-r--. 1 bylee bylee    928  8월 22 15:41 repmgr-action-bdr.h
    -rw-rw-r--. 1 bylee bylee  20752  8월 22 15:47 repmgr-action-bdr.o
    -rw-rw-r--. 1 bylee bylee  35578  8월 22 15:41 repmgr-action-cluster.c
    -rw-rw-r--. 1 bylee bylee   1343  8월 22 15:41 repmgr-action-cluster.h
    -rw-rw-r--. 1 bylee bylee  35776  8월 22 15:47 repmgr-action-cluster.o
    -rw-rw-r--. 1 bylee bylee  71293  8월 22 15:41 repmgr-action-node.c
    -rw-rw-r--. 1 bylee bylee    997  8월 22 15:41 repmgr-action-node.h
    -rw-rw-r--. 1 bylee bylee  85184  8월 22 15:47 repmgr-action-node.o
    -rw-rw-r--. 1 bylee bylee  15340  8월 22 15:41 repmgr-action-primary.c
    -rw-rw-r--. 1 bylee bylee    916  8월 22 15:41 repmgr-action-primary.h
    -rw-rw-r--. 1 bylee bylee  19936  8월 22 15:47 repmgr-action-primary.o
    -rw-rw-r--. 1 bylee bylee 180406  8월 22 15:41 repmgr-action-standby.c
    -rw-rw-r--. 1 bylee bylee   1248  8월 22 15:41 repmgr-action-standby.h
    -rw-rw-r--. 1 bylee bylee 193216  8월 22 15:47 repmgr-action-standby.o
    -rw-rw-r--. 1 bylee bylee  13191  8월 22 15:41 repmgr-action-witness.c
    -rw-rw-r--. 1 bylee bylee    955  8월 22 15:41 repmgr-action-witness.h
    -rw-rw-r--. 1 bylee bylee  18736  8월 22 15:47 repmgr-action-witness.o
    -rw-rw-r--. 1 bylee bylee   6614  8월 22 15:41 repmgr-client-global.h
    -rw-rw-r--. 1 bylee bylee  73421  8월 22 15:41 repmgr-client.c
    -rw-rw-r--. 1 bylee bylee   7480  8월 22 15:41 repmgr-client.h
    -rw-rw-r--. 1 bylee bylee 134688  8월 22 15:47 repmgr-client.o
    -rw-rw-r--. 1 bylee bylee   9087  8월 22 15:41 repmgr.c
    -rw-rw-r--. 1 bylee bylee  17108  8월 22 15:41 repmgr.conf.sample
    -rw-rw-r--. 1 bylee bylee    163  8월 22 15:41 repmgr.control
    -rw-rw-r--. 1 bylee bylee   3112  8월 22 15:41 repmgr.h
    -rw-rw-r--. 1 bylee bylee   8824  8월 22 15:46 repmgr.o
    -rwxrwxr-x. 1 bylee bylee  13816  8월 22 15:46 repmgr.so
    -rw-rw-r--. 1 bylee bylee     73  8월 22 15:46 repmgr_version.h
    -rw-rw-r--. 1 bylee bylee     63  8월 22 15:41 repmgr_version.h.in
    -rwxrwxr-x. 1 bylee bylee 279856  8월 22 15:47 repmgrd
    -rw-rw-r--. 1 bylee bylee  17166  8월 22 15:41 repmgrd-bdr.c
    -rw-rw-r--. 1 bylee bylee    911  8월 22 15:41 repmgrd-bdr.h
    -rw-rw-r--. 1 bylee bylee  24712  8월 22 15:47 repmgrd-bdr.o
    -rw-rw-r--. 1 bylee bylee  84400  8월 22 15:41 repmgrd-physical.c
    -rw-rw-r--. 1 bylee bylee   1017  8월 22 15:41 repmgrd-physical.h
    -rw-rw-r--. 1 bylee bylee  88824  8월 22 15:47 repmgrd-physical.o
    -rw-rw-r--. 1 bylee bylee  20025  8월 22 15:41 repmgrd.c
    -rw-rw-r--. 1 bylee bylee    756  8월 22 15:41 repmgrd.h
    -rw-rw-r--. 1 bylee bylee  66232  8월 22 15:47 repmgrd.o
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 scripts
    drwxrwxr-x. 2 bylee bylee   4096  8월 22 15:41 sql
    -rw-rw-r--. 1 bylee bylee   8902  8월 22 15:41 strutil.c
    -rw-rw-r--. 1 bylee bylee   4120  8월 22 15:41 strutil.h
    -rw-rw-r--. 1 bylee bylee  10232  8월 22 15:47 strutil.o
    -rw-rw-r--. 1 bylee bylee    890  8월 22 15:41 voting.h
     
    --빌드중 아래와 같이 오류가 발생하면 다음과 같이 PATH를 등록한다.
    [bylee@localhost repmgr]$ ./configure && make install
    checking for a sed that does not truncate output... /usr/bin/sed
    checking for pg_config... no
    configure: error: could not find pg_config, set PG_CONFIG or PATH
    [bylee@localhost repmgr]$ export PATH=/home/bylee/install/agensgraph/bin:$PATH
     
     
    --설치 확인
    [bylee@localhost repmgr]$ ./repmgr --help
    repmgr: replication management tool for PostgreSQL
     
    Usage:
        repmgr [OPTIONS] primary {register|unregister}
        repmgr [OPTIONS] standby {register|unregister|clone|promote|follow|switchover}
        repmgr [OPTIONS] bdr     {register|unregister}
        repmgr [OPTIONS] node    {status|check|rejoin|service}
        repmgr [OPTIONS] cluster {show|event|matrix|crosscheck|cleanup}
        repmgr [OPTIONS] witness {register|unregister}
     
      Execute "repmgr {primary|standby|bdr|node|cluster} --help" to see command-specific options
     
    General options:
      -?, --help                          show this help, then exit
      -V, --version                       output version information, then exit
     
    General configuration options:
      -b, --pg_bindir=PATH                path to PostgreSQL binaries (optional)
      -f, --config-file=PATH              path to the repmgr configuration file
      -F, --force                         force potentially dangerous operations to happen
     
    Database connection options:
      -d, --dbname=DBNAME                 database to connect to (default: "bylee")
      -h, --host=HOSTNAME                 database server host
      -p, --port=PORT                     database server port (default: "5432")
      -U, --username=USERNAME             database user name to connect as (default: "bylee")
      -S, --superuser=USERNAME            superuser to use, if repmgr user is not superuser
     
    Node-specific options:
      -D, --pgdata=DIR                    location of the node's data directory
      --node-id                           specify a node by id (only available for some operations)
      --node-name                         specify a node by name (only available for some operations)
     
    Logging options:
      --dry-run                           show what would happen for action, but don't execute it
      -L, --log-level                     set log level (overrides configuration file; default: NOTICE)
      --log-to-file                       log to file (or logging facility) defined in repmgr.conf
      -q, --quiet                         suppress all log output apart from errors
      -t, --terse                         don't display detail, hints and other non-critical output
      -v, --verbose                       display additional log output (useful for debugging)
     
    [bylee@localhost repmgr]$ ./repmgrd --help
    repmgrd: replication management daemon for PostgreSQL
     
    repmgrd monitors a cluster of servers and optionally performs failover.
     
    Usage:
      repmgrd [OPTIONS]
     
    Options:
     
    General options:
      -?, --help                show this help, then exit
      -V, --version             output version information, then exit
     
    General configuration options:
      -v, --verbose             output verbose activity information
      -f, --config-file=PATH    path to the configuration file
     
    Daemon configuration options:
      -d, --daemonize[=true/false]
                                detach process from foreground (default: true)
      -p, --pid-file=PATH       use the specified PID file
      -s, --show-pid-file       show PID file which would be used by the current configuration
      --no-pid-file             don't write a PID file
     
    --postgresql.conf 설정
    max_wal_senders = 10
    wal_level = 'hot_standby'
    hot_standby = on
    archive_mode = on
    archive_command = '/bin/true'
    wal_log_hints = on
     
    --DB start
    [bylee@localhost agensgraph]$ ag_ctl -D pdata start
    waiting for server to start.... done
    server started
     
    --계정 및 metadata용 데이터베이스 생성
    [bylee@localhost agensgraph]$ createuser -s repmgr
    [bylee@localhost agensgraph]$ createdb repmgr -O repm
     
    --repmgr.conf 설정
    [bylee@localhost config]$ vi repmgr-primary.conf
    node_id=1
    node_name=node1
    conninfo='host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2'
    data_directory='/home/bylee/install/agensgraph/pdata
     
    --repmgr.conf 설정 확인
    [bylee@localhost config]$ agens 'host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2'
    agens (AgensGraph 1.4devel, based on PostgreSQL 10.3)
    Type "help" for help.
     
    repmgr=# \q
     
    --primary server 등록
    [bylee@localhost repmgr]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf primary register
    INFO: connecting to primary database...
    NOTICE: attempting to install extension "repmgr"
    NOTICE: "repmgr" extension successfully installed
    NOTICE: primary node record (id: 1) registered
     
    --primary server 등록 확인1
    [bylee@localhost repmgr]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | * running |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     
    --primary server 등록 확인2
    [bylee@localhost agensgraph]$ agens -d repmgr -U repmgr
    agens (AgensGraph 1.4devel, based on PostgreSQL 10.3)
    Type "help" for help.
     
    repmgr=# SELECT * FROM repmgr.nodes;
     node_id | upstream_node_id | active | node_name |  type   | location | priority |                      
            conninfo                               | repluser | slot_name |                config_file      
              
    ---------+------------------+--------+-----------+---------+----------+----------+-----------------------
    -----------------------------------------------+----------+-----------+----------------------------------
    ---------
           1 |                  | t      | node1     | primary | default  |      100 | host=localhost port=54
    32 user=repmgr dbname=repmgr connect_timeout=2 | repmgr   |           | /home/bylee/ha/config/repmgr-prim
    ary.conf
    (1 row)
     
    repmgr=#
     
    -- --dry-run 옵션으로 구성 여부 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby clone --dry-run
    NOTICE: destination directory "/home/bylee/install/agensgraph/sdata" provided
    INFO: connecting to source node
    DETAIL: connection string is: host=localhost port=5432 user=repmgr dbname=repmgr
    DETAIL: current installation size is 31 MB
    NOTICE: standby will attach to upstream node 1
    HINT: consider using the -c/--fast-checkpoint option
    INFO: all prerequisites for "standby clone" are met
    [bylee@localhost config]$
     
    --primary를 복사
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby clone
    NOTICE: destination directory "/home/bylee/install/agensgraph/sdata" provided
    INFO: connecting to source node
    DETAIL: connection string is: host=localhost port=5432 user=repmgr dbname=repmgr
    DETAIL: current installation size is 31 MB
    INFO: creating directory "/home/bylee/install/agensgraph/sdata"...
    NOTICE: starting backup (using pg_basebackup)...
    HINT: this may take some time; consider using the -c/--fast-checkpoint option
    INFO: executing:
      pg_basebackup -l "repmgr base backup"  -D /home/bylee/install/agensgraph/sdata -h localhost -p 5432 -U repmgr -X stream
    NOTICE: standby clone (using pg_basebackup) complete
    NOTICE: you can now start your PostgreSQL server
    HINT: for example: pg_ctl -D /home/bylee/install/agensgraph/sdata start
    HINT: after starting the server, you need to register this standby with "repmgr standby register"
    [bylee@localhost config]$
     
    --port 변경 및 standby 시작
     [bylee@localhost sdata]$ vi postgresql.conf
     port = 5433
     
    [bylee@localhost agensgraph]$ ag_ctl -D sdata start
     
    --standby server 등록
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby register
    INFO: connecting to local node "node2" (ID: 2)
    INFO: connecting to primary database
    WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID 1)
    INFO: standby registration complete
    NOTICE: standby node "node2" (id: 2) successfully registered
     
    --standby server 등록 확인1
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | * running |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running | node1    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
    [bylee@localhost config]$
     
    --standby server 등록 확인2
     
    [bylee@localhost agensgraph]$ agens -d repmgr -U repmgr
    agens (AgensGraph 1.4devel, based on PostgreSQL 10.3)
    Type "help" for help.
     
    repmgr=# SELECT * FROM repmgr.nodes;
     node_id | upstream_node_id | active | node_name |  type   | location | priority |                      
            conninfo                               | repluser | slot_name |                config_file      
              
    ---------+------------------+--------+-----------+---------+----------+----------+-----------------------
    -----------------------------------------------+----------+-----------+----------------------------------
    ---------
           1 |                  | t      | node1     | primary | default  |      100 | host=localhost port=54
    32 user=repmgr dbname=repmgr connect_timeout=2 | repmgr   |           | /home/bylee/ha/config/repmgr-prim
    ary.conf
           2 |                1 | t      | node2     | standby | default  |      100 | host=localhost port=54
    33 user=repmgr dbname=repmgr connect_timeout=2 | repmgr   |           | /home/bylee/ha/config/repmgr-stan
    dby.conf
    (2 rows)
     
    --primary를 복사
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -h localhost -p 5432 -U repmgr -d repmgr -f /home/bylee/ha/config/repmgr-standby2.conf standby clone
    NOTICE: destination directory "/home/bylee/install/agensgraph/sdata2" provided
    INFO: connecting to source node
    DETAIL: connection string is: host=localhost port=5432 user=repmgr dbname=repmgr
    DETAIL: current installation size is 31 MB
    INFO: checking and correcting permissions on existing directory "/home/bylee/install/agensgraph/sdata2"
    NOTICE: starting backup (using pg_basebackup)...
    HINT: this may take some time; consider using the -c/--fast-checkpoint option
    INFO: executing:
      pg_basebackup -l "repmgr base backup"  -D /home/bylee/install/agensgraph/sdata2 -h localhost -p 5432 -U repmgr -X stream
    NOTICE: standby clone (using pg_basebackup) complete
    NOTICE: you can now start your PostgreSQL server
    HINT: for example: pg_ctl -D /home/bylee/install/agensgraph/sdata2 start
    HINT: after starting the server, you need to register this standby with "repmgr standby register"
     
    --port 변경 및 standby2 시작
     [bylee@localhost sdata]$ vi postgresql.conf
     port = 5434
     
    [bylee@localhost agensgraph]$ ag_ctl -D sdata2 start
     
    --standby2 server 등록
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf standby register
    INFO: connecting to local node "node3" (ID: 3)
    INFO: connecting to primary database
    WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID 1)
    INFO: standby registration complete
    NOTICE: standby node "node3" (id: 3) successfully registered
     
    --standby2 server 등록 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | * running |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running | node1    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | standby |   running | node1    | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
    [bylee@localhost config]$
     
    --primary에 vertex 추가
    [bylee@localhost agensgraph]$ agens -d postgres -p 5432
    agens (AgensGraph 1.4devel, based on PostgreSQL 10.3)
    Type "help" for help.
     
    postgres=# create graph repmgr_test;
    CREATE GRAPH
    postgres=# show graph_path;
     graph_path 
    -------------
     repmgr_test
    (1 row)
     
    postgres=# create (:V{name:'repmgr'});
    GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
    postgres=# match (n) return n;
                n            
    --------------------------
     v[3.1]{"name": "repmgr"}
    (1 row)
     
    postgres=# \q
     
    --standby에서 vertex 확인
    [bylee@localhost agensgraph]$ agens -d postgres -p 5433
    agens (AgensGraph 1.4devel, based on PostgreSQL 10.3)
    Type "help" for help.
     
    postgres=# show graph_path;
     graph_path
    ------------
      
    (1 row)
     
    postgres=# set graph_path to repmgr_test;
    SET
    postgres=# match (n) return n;
                n            
    --------------------------
     v[3.1]{"name": "repmgr"}
    (1 row)
     
    postgres=#
     
     
    --failover 테스트를 위해 primary server 중지
    [bylee@localhost agensgraph]$ ag_ctl -D /home/bylee/install/agensgraph/pdata -m fast stop
    waiting for server to shut down.... done
    server stopped
     
    --primary server 정지 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf cluster show
    ERROR: connection to database failed:
      could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
    could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
     
    DETAIL: attempted to connect using:
      user=repmgr connect_timeout=2 dbname=repmgr host=localhost port=5432 fallback_application_name=repmgr
     
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
     ID | Name  | Role    | Status        | Upstream | Location | Connection string                                                  
    ----+-------+---------+---------------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | ? unreachable |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running     | node1    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | standby |   running     | node1    | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
     
    WARNING: following issues were detected
      - when attempting to connect to node "node1" (ID: 1), following error encountered :
    "could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
    could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?"
      - node "node1" (ID: 1) is registered as an active primary but is unreachable
     
     
    --standby server에서 promoting
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf standby promote
    NOTICE: promoting standby to primary
    DETAIL: promoting server "node2" (ID: 2) using "pg_ctl  -w -D '/home/bylee/install/agensgraph/sdata' promote"
    DETAIL: waiting up to 60 seconds (parameter "promote_check_timeout") for promotion to complete
    waiting for server to promote.... done
    server promoted
    NOTICE: STANDBY PROMOTE successful
    DETAIL: server "node2" (ID: 2) was successfully promoted to primary
     
    --promoting 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | - failed  |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | primary | * running |          | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | standby |   running | node1    | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
     
    WARNING: following issues were detected
      - when attempting to connect to node "node1" (ID: 1), following error encountered :
    "could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
    could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?"
     
    --following
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf  standby follow
    NOTICE: setting node 3's primary to node 2
    NOTICE: stopping server using "pg_ctl  -D '/home/bylee/install/agensgraph/sdata2' -w -m fast stop"
    NOTICE: starting server using "pg_ctl  -w -D '/home/bylee/install/agensgraph/sdata2' start"
    NOTICE: STANDBY FOLLOW successful
    DETAIL: standby attached to upstream node "node2" (node ID: 2)
     
    --following 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | - failed  |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | primary | * running |          | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | standby |   running | node2    | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
     
    WARNING: following issues were detected
      - when attempting to connect to node "node1" (ID: 1), following error encountered :
    "could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
    could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?"
    [bylee@localhost config]$
     
     
    --failback 가능 여부 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr standby switchover -f /home/bylee/ha/config/repmgr-standby2.conf --siblings-follow --dry-run
    NOTICE: checking switchover on node "node3" (ID: 3) in --dry-run mode
    INFO: SSH connection to host "localhost" succeeded
    INFO: able to execute "repmgr" on remote host "localhost"
    INFO: demotion candidate is able to make replication connection to promotion candidate
    INFO: 0 pending archive files
    INFO: replication lag on this standby is 0 seconds
    WARNING: option "--sibling-nodes" specified, but no sibling nodes exist
    NOTICE: local node "node3" (ID: 3) would be promoted to primary; current primary "node2" (ID: 2) would be demoted to standby
    INFO: following shutdown command would be run on node "node2":
      "/home/bylee/install//agensgraph/bin/pg_ctl  -D '/home/bylee/install/agensgraph/sdata' -W -m fast stop"
    [bylee@localhost config]$
     
    --failback
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f  /home/bylee/ha/config/repmgr-standby2.conf standby switchover
    NOTICE: executing switchover on node "node3" (ID: 3)
    NOTICE: local node "node3" (ID: 3) will be promoted to primary; current primary "node2" (ID: 2) will be demoted to standby
    NOTICE: stopping current primary node "node2" (ID: 2)
    NOTICE: issuing CHECKPOINT
    DETAIL: executing server command "/home/bylee/install//agensgraph/bin/pg_ctl  -D '/home/bylee/install/agensgraph/sdata' -W -m fast stop"
    INFO: checking primary status; 1 of 6 attempts
    INFO: checking primary status; 2 of 6 attempts
    NOTICE: current primary has been cleanly shut down at location 0/7000028
    NOTICE: promoting standby to primary
    DETAIL: promoting server "node3" (ID: 3) using "/home/bylee/install//agensgraph/bin/pg_ctl  -w -D '/home/bylee/install/agensgraph/sdata2' promote"
    DETAIL: waiting up to 60 seconds (parameter "promote_check_timeout") for promotion to complete
    waiting for server to promote.... done
    server promoted
    NOTICE: STANDBY PROMOTE successful
    DETAIL: server "node3" (ID: 3) was successfully promoted to primary
    NOTICE: setting node 2's primary to node 3
    NOTICE: starting server using "/home/bylee/install//agensgraph/bin/pg_ctl  -w -D '/home/bylee/install/agensgraph/sdata' start"
    NOTICE: NODE REJOIN successful
    DETAIL: node 2 is now attached to node 3
    NOTICE: switchover was successful
    DETAIL: node "node3" is now primary and node "node2" is attached as standby
    NOTICE: STANDBY SWITCHOVER has completed successfully
     
    --failback 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | - failed  |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running | node3    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | primary | * running |          | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
     
    WARNING: following issues were detected
      - when attempting to connect to node "node1" (ID: 1), following error encountered :
    "could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
    could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?"
     
     
     
     
    --
    --번외 테스트
     
    --old primary server 시작
    [bylee@localhost agensgraph]$ ag_ctl -D /home/bylee/install/agensgraph/pdata start
    waiting for server to start.... done
    server started
    [bylee@localhost agensgraph]$
     
    --old primary server 시작 확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | ! running |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running | node3    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | primary | * running |          | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
     
    WARNING: following issues were detected
      - node "node1" (ID: 1) is running but the repmgr node record is inactive
     
    --old primary server를 standby server로 role 변경하기 위해서는 primary server clone하여 old primary server를 덮어쓰기 해야 한다.
    --primary server clone하기
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf --force  -h localhost -p 5434 -d repmgr -U repmgr --verbose standby clone
    NOTICE: using provided configuration file "/home/bylee/ha/config/repmgr-primary.conf"
    NOTICE: destination directory "/home/bylee/install/agensgraph/pdata" provided
    INFO: connecting to source node
    DETAIL: connection string is: host=localhost port=5434 user=repmgr dbname=repmgr
    NOTICE: checking for available walsenders on source node (2 required)
    INFO: sufficient walsenders available on source node (2 required)
    WARNING: directory "/home/bylee/install/agensgraph/pdata" exists but is not empty
    NOTICE: -F/--force provided - deleting existing data directory "/home/bylee/install/agensgraph/pdata"
    NOTICE: starting backup (using pg_basebackup)...
    HINT: this may take some time; consider using the -c/--fast-checkpoint option
    INFO: executing:
      /home/bylee/install//agensgraph/bin/pg_basebackup -l "repmgr base backup"  -D /home/bylee/install/agensgraph/pdata -h localhost -p 5434 -U repmgr -X stream
    NOTICE: standby clone (using pg_basebackup) complete
    NOTICE: you can now start your PostgreSQL server
    HINT: for example: pg_ctl -D /home/bylee/install/agensgraph/pdata start
     
    --port 변경 및 시작
    $ vi postgresql.conf
    port = 5432
     
    $  ag_ctl -D /home/bylee/install/agensgraph/pdata start
     
    --확인
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
     ID | Name  | Role    | Status               | Upstream | Location | Connection string                                                  
    ----+-------+---------+----------------------+----------+----------+----------------------------------------------------------------------
     1  | node1 | primary | ! running as standby |          | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running            | node3    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | primary | * running            |          | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
     
    WARNING: following issues were detected
      - node "node1" (ID: 1) is registered as an inactive primary but running as standby
     
    -- --force 추가하여 standby register 명령어 실행
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-primary.conf --force standby register
    INFO: connecting to local node "node1" (ID: 1)
    INFO: connecting to primary database
    INFO: standby registration complete
    NOTICE: standby node "node1" (id: 1) successfully registered
     
    [bylee@localhost config]$ /home/bylee/ha/repmgr/repmgr -f /home/bylee/ha/config/repmgr-standby2.conf cluster show
     ID | Name  | Role    | Status    | Upstream | Location | Connection string                                                  
    ----+-------+---------+-----------+----------+----------+----------------------------------------------------------------------
     1  | node1 | standby |   running | node3    | default  | host=localhost port=5432 user=repmgr dbname=repmgr connect_timeout=2
     2  | node2 | standby |   running | node3    | default  | host=localhost port=5433 user=repmgr dbname=repmgr connect_timeout=2
     3  | node3 | primary | * running |          | default  | host=localhost port=5434 user=repmgr dbname=repmgr connect_timeout=2
    [bylee@localhost config]$

    --부록

    repmgr.conf 예제

    failover=automatic
    promote_command='/path/to/repmgr standby promote -f /etc/repmgr.conf --log-to-file'
    follow_command='/path/to/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n'
    cluster=cluster1
    node_id=3
    node_name=node3
    conninfo='host=node3 user=repmgr dbname=repmgr'
    data_directory='/path/to/agensgraph/data'
    master_response_timeout=30
    pg_bindir=/home/bylee/install//agensgraph/bin
    service_start_command=ag_ctl -D /path/to/agensgraph/data start
    service_stop_command=ag_ctl -D /path/to/agensgraph/data stop
    service_restart_command=ag_ctl -D /path/to/agensgraph/data restart

    'PostgreSQL' 카테고리의 다른 글

    stolon 설치  (0) 2019.10.14
    patroni 설치  (0) 2019.10.14
    pgbouncer와 pgpool-II 비교  (0) 2019.10.11
    pgpool-II session failover  (0) 2019.10.11
    pgbouncer session failover  (0) 2019.10.11
Designed by Tistory.