Giter Site home page Giter Site logo

k-ta-yamada / postgres-ha Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 92 KB

itamae: PostgreSQL High availability configuration by pgpool-II with watchdog.

Shell 5.60% Ruby 14.25% HTML 80.15%
postgresql streaming-replication pgpool2 pgpool-ii pgpool-cluster watchdog itamae self-study high-availability

postgres-ha's Introduction

PostgreSQL HA

PostgreSQL High availability configuration by pgpool-II with watchdog.

NOTE: This repository is for self-study.

Usage

Server setup

# vagrant up
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-proxyconf # if you needed
vagrant up
vagrant reload # to reflect SELINUX setting change, reload.

Using itamae

# install itamae
# NOTE: in the following command example omit "bundle exec"
bundle install --path vendor/bundle

# Primary node `pg1`: PostgreSQL and pgpool-II
itamae ssh -h pg1 -y node/develop.yml roles/db_master.rb
itamae ssh -h pg1 -y node/develop.yml roles/pgpool.rb

# Standby node `pg2`: PostgreSQL and pgpool-II
itamae ssh -h pg2 -y node/develop.yml roles/db_slave.rb
itamae ssh -h pg2 -y node/develop.yml roles/pgpool.rb

Remaining 3 Task

1. ssh postgres@pg[1|2] for pcp_recovery_node

Set up so that ssh connection without passphrase can be connected with postgres user from both servers.

Note: host names used for the connection are backend-pg1 and backend-pg2.
because Streaming Replication and pg_basebackup use the backend network.
ref: ./cookbooks/postgresql/templates/var/lib/pgsql/9.6/data/recovery_1st_stage.sh.erb#L18
ref: ./cookbooks/pgpool-II/templates/etc/pgpool-II/pgpool.conf.erb#L65
please check common.backend_prefix and common.hostnames of node/xxx.yml for the actual host name.

  1. generate key: ssh-keygen on both servers.
  2. copy the contents of the public key to ~/.ssh/authorized_keys of the other server
  3. and copy the contents of the public key to ~/.ssh/authorized_keys of the self
    • cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  4. connect by postgres user
    • primary node: pg1
      1. su - postgres
      2. ssh backend-pg1
      3. ssh backend-pg2
    • standby node: pg2
      1. su - postgres
      2. ssh backend-pg1
      3. ssh backend-pg2

2. Start up primary node and standby node(only pgpool)

NOTE: Start up PostgreSQL with pg_ctl instead of systemctl.

primary node

ssh pg1
systemctl start postgresql-9.6.service
systemctl start pgpool.service

standby node

ssh pg2
systemctl start pgpool.service

and check node status

pcp_watchdog_info -h pool -U pgpool -v
Password:
Watchdog Cluster Information
Total Nodes          : 2
Remote Nodes         : 1
Quorum state         : QUORUM EXIST
Alive Remote Nodes   : 1
VIP up on local node : YES
Master Node Name     : backend-pool1:9999 Linux pg1
Master Host Name     : backend-pool1

Watchdog Node Information
Node Name      : backend-pool1:9999 Linux pg1
Host Name      : backend-pool1
Delegate IP    : 192.168.1.200
Pgpool port    : 9999
Watchdog port  : 9000
Node priority  : 1
Status         : 4
Status Name    : MASTER

Node Name      : backend-pool2:9999 Linux pg2
Host Name      : backend-pool2
Delegate IP    : 192.168.1.200
Pgpool port    : 9999
Watchdog port  : 9000
Node priority  : 1
Status         : 7
Status Name    : STANDBY
pcp_node_info -h pool -U pgpool -v 0
Password:
Hostname   : backend-pg1
Port       : 5432
Status     : 1
Weight     : 0.500000
Status Name: waiting
pcp_node_info -h pool -U pgpool -v 1
Password:
Hostname   : backend-pg2
Port       : 5432
Status     : 3
Weight     : 0.500000
Status Name: down

3. Start up standby node

for start streaming replication.

pcp_recovery_node -h pool -U pgpool -n 1

Troubleshoot

If the execution of pcp_recovery_node fails, if the host OS is windows,
check recovery_1st_stage.sh.erb or recovery_1st_stage.sh on the server.

In the case of windows

file cookbooks\postgresql\templates\var\lib\pgsql\9.6\data\recovery_1st_stage.sh.erb

On the server

file /var/lib/pgsql/9.6/data/recovery_1st_stage.sh

change CRLF to LF sample

sed -i "s/\r//g" /var/lib/pgsql/9.6/data/recovery_1st_stage.sh

todo


refs:

postgres-ha's People

Contributors

k-ta-yamada avatar

Watchers

 avatar  avatar

Forkers

pritraj90

postgres-ha's Issues

PGDATA directory is not created for db_slave node

PGDATA directory is not created for db_slave node.

It is cookbooks/postgresql/initdb.rb which creates the PGDATA directory, but cookbooks/postgresql/initdb.rb is not executed in roles/db_slave.rb.

use replication slot or Adjust wal_keep_segments

PostgreSQL本体のレプリケーション機能強化 (3/4)

  • postgresql.conf
    • standby node
      • hot_standby = on
      • hot_standby_feedback = on
    • master node
      • wal_level = hot_standbyreplica
      • max_wal_senders = 2
      • max_replication_slots = 2
  • create(on master node)
    • SELECT * FROM pg_create_physical_replication_slot('a_slot');
  • recovery.conf(on standby node)
    • primary_slot_name = 'a_slot'
  • check
    • SELECT slot_name, active FROM pg_replication_slots;
  • delete
    • SELECT pg_drop_replication_slot('a_slot');

19.6.1. 送出サーバ群

  • max_replication_slots (integer)
  • wal_keep_segments (integer)

26.2.6. レプリケーションスロット

pcp_recovery_node error

pcp_recovery_node -U postgres -h pool -n 1
Password:
ERROR:  executing recovery, execution of command failed at "1st stage"
DETAIL:  command:"recovery_1st_stage.sh"

xxx_dir = /tmp

pgpool-II

  • socket_dir
  • pcp_socket_dir
  • logdir
  • wd_ipc_socket_dir

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.