|
| 1 | +--- |
| 2 | +title: "Implementing High Availability with Pgpool" |
| 3 | + |
| 4 | +legacyRedirectsGenerated: |
| 5 | + # This list is generated by a script. If you need add entries, use the `legacyRedirects` key. |
| 6 | + - "/edb-docs/d/edb-postgres-failover-manager/user-guides/high-availability-scalability-guide/3.10/components_ha_pgpool.html" |
| 7 | +--- |
| 8 | + |
| 9 | +Failover Manager monitors the health of Postgres nodes; in the event of a database failure, Failover Manager performs an automatic failover to a Standby node. Note that Pgpool does not monitor the health of backend nodes and will not perform failover to any Standby nodes. |
| 10 | + |
| 11 | +## Configuring Failover Manager |
| 12 | + |
| 13 | +Failover Manager provides functionality that will remove failed database nodes from Pgpool load balancing; it can also re-attach nodes to Pgpool when returned to the Failover Manager cluster. To configure EFM for high availability using Pgpool, you must set the following properties in the cluster properties file: |
| 14 | + |
| 15 | +pgpool.enable =<true/false> |
| 16 | + |
| 17 | +'pcp.user' = <User that would be invoking PCP commands> |
| 18 | + |
| 19 | +'pcp.host' = <Virtual IP that would be used by pgpool. Same as pgpool parameter 'delegate_IP’> |
| 20 | + |
| 21 | +'pcp.port' = <The port on which pgpool listens for pcp commands> |
| 22 | + |
| 23 | +'pcp.pass.file' = <Absolute path of PCPPASSFILE> |
| 24 | + |
| 25 | +'pgpool.bin' = <Absolute path of pgpool bin directory> |
| 26 | + |
| 27 | +## Configuring Pgpool |
| 28 | + |
| 29 | +The section lists the configuration of some important parameters in the `pgpool.conf` file to integrate the Pgpool-II with EFM. |
| 30 | + |
| 31 | +**Backend node setting** |
| 32 | + |
| 33 | +There are three PostgreSQL backend nodes, one Primary and two Standby nodes. Configure using `backend_*` configuration parameters in `pgpool.conf`, and use the equal backend weights for all nodes. This will make the read queries to be distributed equally among all nodes. |
| 34 | + |
| 35 | +```text |
| 36 | +backend_hostname0 = ‘server1_IP' |
| 37 | +backend_port0 = 5444 |
| 38 | +backend_weight0 = 1 |
| 39 | +backend_flag0 = 'DISALLOW_TO_FAILOVER' |
| 40 | +
|
| 41 | +backend_hostname1 = ‘server2_IP' |
| 42 | +backend_port1 = 5444 |
| 43 | +backend_weight1 = 1 |
| 44 | +backend_flag1 = 'DISALLOW_TO_FAILOVER' |
| 45 | +
|
| 46 | +backend_hostname2 = ‘server3_IP' |
| 47 | +backend_port2 = 5444 |
| 48 | +backend_weight2 = 1 |
| 49 | +backend_flag2 = 'DISALLOW_TO_FAILOVER' |
| 50 | +``` |
| 51 | + |
| 52 | +**Enable Load-balancing and streaming replication mode** |
| 53 | + |
| 54 | +Set the following configuration parameter in the `pgpool.conf` file to enable load balancing and streaming replication mode |
| 55 | + |
| 56 | +```text |
| 57 | +master_slave_mode = on |
| 58 | +master_slave_sub_mode = 'stream' |
| 59 | +load_balance_mode = on |
| 60 | +``` |
| 61 | + |
| 62 | +**Disable health-checking and failover** |
| 63 | + |
| 64 | +Health-checking and failover must be handled by EFM and hence, these must be disabled on Pgpool-II side. To disable the health-check and failover on pgpool-II side, assign the following values: |
| 65 | + |
| 66 | +```text |
| 67 | +health_check_period = 0 |
| 68 | +fail_over_on_backend_error = off |
| 69 | +failover_if_affected_tuples_mismatch = off |
| 70 | +failover_command = ‘’ |
| 71 | +failback_command = ‘’ |
| 72 | +``` |
| 73 | + |
| 74 | +Ensure the following while setting up the values in the `pgpool.conf` file: |
| 75 | + |
| 76 | +- Keep the value of wd_priority in pgpool.conf different on each node. The node with the highest value gets the highest priority. |
| 77 | +- The properties backend_hostname0 , backend_hostname1, backend_hostname2 and so on are shared properties (in EFM terms) and should hold the same value for all the nodes in pgpool.conf file. |
| 78 | +- Update the correct interface value in *if\_* \* and arping cmd props in the pgpool.conf file. |
| 79 | +- Add the properties heartbeat_destination0, heartbeat_destination1, heartbeat_destination2 etc. as per the number of nodes in pgpool.conf file on every node. Here heartbeat_destination0 should be the ip/hostname of the local node. |
| 80 | + |
| 81 | +**Setting up PCP** |
| 82 | + |
| 83 | +Script uses the PCP interface, So we need to set up the PCP and .PCPPASS file to allow PCP connections without password prompt. |
| 84 | + |
| 85 | +setup PCP: <http://www.pgpool.net/docs/latest/en/html/configuring-pcp-conf.html> |
| 86 | + |
| 87 | +setup PCPPASS: <https://www.pgpool.net/docs/latest/en/html/pcp-commands.html> |
| 88 | + |
| 89 | +Note that the load-balancing is turned on to ensure read scalability by distributing read traffic across the standby nodes |
| 90 | + |
| 91 | +The health checking and error-triggered backend failover have been turned off, as Failover Manager will be responsible for performing health checks and triggering failover. It is not advisable for Pgpool to perform health checking in this case, so as not to create a conflict with Failover Manager, or prematurely perform failover. |
| 92 | + |
| 93 | +Finally, `search_primary_node_timeout` has been set to a low value to ensure prompt recovery of Pgpool services upon an Failover Manager-triggered failover. |
| 94 | + |
| 95 | +## Virtual IP Addresses |
| 96 | + |
| 97 | +Both Pgpool-II and Failover Manager provide functionality to employ a virtual IP for seamless failover. While both provide this capability, the pgpool-II leader is the process that receives the Application connections through the Virtual IP. As in this design, such Virtual IP management is performed by the Pgpool-II watchdog system. EFM VIP has no beneficial effect in this design and it must be disabled. |
| 98 | + |
| 99 | +Note that in a failure situation of the active instance of Pgpool (The Primary Pgpool Server in our sample architecture), the next available Standby Pgpool instance (according to watchdog priority) will be activated and takes charge as the leader Pgpool instance. |
| 100 | + |
| 101 | +## Configuring Pgpool-II Watchdog |
| 102 | + |
| 103 | +Watchdog provides the high availability of Pgpool-II nodes. This section lists the configuration required for watchdog on each Pgpool-II node. |
| 104 | + |
| 105 | +**Common watchdog configurations on all Pgpool nodes** |
| 106 | + |
| 107 | +The following configuration parameters enable and configure the watchdog. The interval and retry values can be adjusted depending upon the requirements and testing results. |
| 108 | + |
| 109 | +```text |
| 110 | +use_watchdog = on # enable watchdog |
| 111 | +wd_port = 9000 # watchdog port, can be changed |
| 112 | +delegate_IP = ‘Virtual IP address’ |
| 113 | +wd_lifecheck_method = 'heartbeat' |
| 114 | +wd_interval = 10 # we can lower this value for quick detection |
| 115 | +wd_life_point = 3 |
| 116 | +# virtual IP control |
| 117 | +ifconfig_path = '/sbin' # ifconfig command path |
| 118 | +if_up_cmd = 'ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0' |
| 119 | + # startup delegate IP command |
| 120 | +if_down_cmd = 'ifconfig eth0:0 down' # shutdown delegate IP command |
| 121 | +arping_path = '/usr/sbin' # arping command path |
| 122 | +``` |
| 123 | + |
| 124 | +!!! Note |
| 125 | + Replace the value of eth0 with the network interface on your system. See [Chapter 5](05_appendix_b/#configuration-for-number-of-connections-and-pooling) for tuning the number of connections, and pooling configuration. |
| 126 | + |
| 127 | +**Watchdog configurations on server 2** |
| 128 | + |
| 129 | +```text |
| 130 | +other_pgpool_hostname0 = 'server 3 IP/hostname' |
| 131 | +other_pgpool_port0 = 9999 |
| 132 | +other_wd_port0 = 9000 |
| 133 | +other_pgpool_hostname1 = 'server 4 IP/hostname' |
| 134 | +other_pgpool_port1 = 9999 |
| 135 | +other_wd_port1 = 9000 |
| 136 | +wd_priority = 1 |
| 137 | +``` |
| 138 | + |
| 139 | +**Watchdog configurations on server 3** |
| 140 | + |
| 141 | +```text |
| 142 | +other_pgpool_hostname0 = 'server 2 IP/hostname' |
| 143 | +other_pgpool_port0 = 9999 |
| 144 | +other_wd_port0 = 9000 |
| 145 | +other_pgpool_hostname1 = 'server 4 IP/hostname' |
| 146 | +other_pgpool_port1 = 9999 |
| 147 | +other_wd_port1 = 9000 |
| 148 | +wd_priority = 3 |
| 149 | +``` |
| 150 | + |
| 151 | +**Watchdog configurations on server 4** |
| 152 | + |
| 153 | +```text |
| 154 | +other_pgpool_hostname0 = 'server 2 IP/hostname' |
| 155 | +other_pgpool_port0 = 9999 |
| 156 | +other_wd_port0 = 9000 |
| 157 | +other_pgpool_hostname1 = 'server 3 IP/hostname' |
| 158 | +other_pgpool_port1 = 9999 |
| 159 | +other_wd_port1 = 9000 |
| 160 | +wd_priority = 5 # use high watchdog priority on server 4 |
| 161 | +``` |
0 commit comments