Skip to content

Commit

Permalink
Merge pull request #2498 from EnterpriseDB/2022-03-28
Browse files Browse the repository at this point in the history
Production Release: 2022-03-28
  • Loading branch information
drothery-edb authored Mar 28, 2022
2 parents 7ae0e05 + cc0935f commit f57544a
Show file tree
Hide file tree
Showing 36 changed files with 634 additions and 652 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ redirects:
This example shows how to connect using virtual network peering.

!!! Note
The IP ranges of two peered virtual networks can't overlap. BigAnimal VNets use the 10.240.0.0/16 address space and cannot be peered with VNets using this same space.
The IP ranges of two peered virtual networks can't overlap. BigAnimal VNets use the 10.0.0.0/8 address space and cannot be peered with VNets using this same space.

Assume that your cluster is on a subscription called `development` and is being accessed from a Linux client VM on another subscription called `test` with the following properties:

Expand Down
78 changes: 39 additions & 39 deletions product_docs/docs/efm/4/efm_deploy_arch/05_efm_pgbouncer.mdx
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
---
title: "Failover Manager with PgBouncer"
title: "Failover Manager with EDB PgBouncer"
redirects:
- ../../efm_pgpool_ha_guide/05_efm_pgbouncer
---

You can use Failover Manager and PgBouncer to provide high availability
in an on-premises setup as well as in a cloud setup. PgBouncer is a popular
You can use Failover Manager and EDB PgBouncer to provide high availability
in an on-premises setup as well as in a cloud setup. EDB PgBouncer is a popular
connection pooler, but it is not enough to achieve PostgreSQL high
availability by itself as it doesn't have multi-host configuration,
failover, or detection.

## Failover Manager with PgBouncer on premises
## Failover Manager with EDB PgBouncer on premises

For an on-premises setup, use the connection libraries to provide high
availability by using a connection string with multiple hosts.

![Failover Manager using pgBouncer on-premises architecture diagram](images/efm_with_pgbouncer_on_premises.png)

<div style="text-align: center">Figure 3: Failover Manager's traffic routing using PgBouncer on-premises</div>
<div style="text-align: center">Figure 3: Failover Manager's traffic routing using EDB PgBouncer on-premises</div>

## Failover Manager with PgBouncer in the cloud
## Failover Manager with EDB PgBouncer in the cloud

For a cloud setup, use a network load balancer (NLB) to balance the traffic on both instances of PgBouncer.
For a cloud setup, use a network load balancer (NLB) to balance the traffic on both instances of EDB PgBouncer.

![Failover Manager with PgBouncer cloud architecture diagram](images/efm_with_pgbouncer_on_cloud.png)

<div style="text-align: center">Figure 4: Failover Manager's traffic routing using PgBouncer in cloud</div>
<div style="text-align: center">Figure 4: Failover Manager's traffic routing using EDB PgBouncer in cloud</div>

EDB does not support this architecture
with PgBouncer and Failover Manager/PostgreSQL running on the same
with EDB PgBouncer and Failover Manager/PostgreSQL running on the same
machines:

- A restriction with cloud network load balancers [Azure](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-troubleshoot-backend-traffic#cause-4-accessing-the-internal-load-balancer-frontend-from-the-participating-load-balancer-backend-pool-vm)
doesn't route traffic properly when source and destination reside
on the same machines.

- In a mixed architecture, traffic between PgBouncer and Postgres can
- In a mixed architecture, traffic between EDB PgBouncer and Postgres can
become unbalanced (sometimes local, sometimes networked).

- PgBouncer and PostgreSQL compete for resources.
- EDB PgBouncer and PostgreSQL compete for resources.

- A master failure impacts both routing (PgBouncer) and database
- A master failure impacts both routing (EDB PgBouncer) and database
when these two components are combined on the same machines.


## Using Failover Manager with PgBouncer

### Installing

Install and configure Advanced Server database, Failover Manager, and PgBouncer on AWS virtual machines as follows:
Install and configure Advanced Server database, Failover Manager, and EDB PgBouncer on AWS virtual machines as follows:


Systems | Components
--------------------| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PgDB srv 1, 2, 3 | Primary / standby node running Advanced Server 13 and Failover Manager 4.2
PgBouncer srv 1, 2 | PgBouncer node running PgBouncer 1.15. Register these two nodes as targets in the target group. Two is the minimum and is sufficient for most cases.
PgBouncer srv 1, 2 | PgBouncer node running EDB PgBouncer 1.15. Register these two nodes as targets in the target group. Two is the minimum and is sufficient for most cases.


### Configuring Failover Manager
Expand All @@ -64,8 +64,8 @@ to configure Failover Manager. Perform the following steps in addition
to those instructions:

1. Create an integration script that connects to every (remote)
PgBouncer host and runs the redirect script. Locate the script at `/usr/edb/efm-4.2/bin/efm_pgbouncer_functions`. Make sure the user
efm can execute the script, which has the following contents. The user efm runs ssh as enterpriseDB to run the script.
EDB PgBouncer host and runs the redirect script. Locate the script at `/usr/edb/efm-4.2/bin/efm_pgbouncer_functions`. Make sure the user
efm can execute the script, which has the following contents:

``` text
Expand Down Expand Up @@ -101,10 +101,10 @@ efm can execute the script, which has the following contents. The user efm runs
During normal operation, traffic is balanced across both PgBouncer instances, and both open connections to PostgreSQL.
Therefore, make sure that in PostgreSQL the `max_connections` parameter is compensated to accept enough connections from both instances.

### Configuring PgBouncer
### Configuring EDB PgBouncer

You can use the instructions provided in the [PgBouncer documentation](/pgbouncer/latest/02_configuration_and_usage/)
to configure PgBouncer. Perform the following steps in addition to those instructions:
You can use the instructions provided in the [EDB PgBouncer documentation](/pgbouncer/latest/02_configuration_and_usage/)
to configure EDB PgBouncer. Perform the following steps in addition to those instructions:

1. Append the following line to the `edb-pgbouncer-1.15.ini` file:

Expand Down Expand Up @@ -154,14 +154,14 @@ by root and that user/group/other (0755) has read and execute access. The script

### Configuring passwordless ssh

For the PgBouncer integration, passwordless `ssh` access is required. There are multiple ways
For the EDB PgBouncer integration, passwordless `ssh` access is required. There are multiple ways
to configure `ssh`. Follow your organization's recommended process to
configure the passwordless `ssh`. For a quick start, you can also follow this example for configuring passwordless `ssh`.
The user efm user must be able to ssh as the user running PgBouncer; for example, enterprisedb.

#### Configure on PgBouncer hosts
#### Configure on EDB PgBouncer hosts

1. On every PgBouncer host, temporarily set a password for the enterprisedb user. As root, run `passwd enterprisedb` and enter
1. On every EDB PgBouncer host, temporarily set a password for the enterprisedb user. As root, run `passwd enterprisedb` and enter
the temporary password twice.

2. Make sure that passwordless `ssh` is enabled. You can check with the following command:
Expand All @@ -180,33 +180,33 @@ On every Failover Manager/postgres host, as the efm user:
``` text
ssh-keygen -P "" -f ~/.ssh/id_rsa
```
2. For every PgBouncer host, copy the `ssh` key with the following command:
2. For every EDB PgBouncer host, copy the `ssh` key with the following command:
``` text
ssh-copy-id enterprisedb@<pgbouncerhost>
```
The default home directory for the `enterprisedb` user is `/var/lib/edb`. If this directory is not already present, create it manually.
As a sudo user, run the following commands on each PgBouncer host:
As a sudo user, run the following commands on each EDB PgBouncer host:
``` text
mkdir -p /var/lib/edb
chown -R enterprisedb:enterprisedb /var/lib/edb
```

#### Resetting temporary passwords on PgBouncer hosts
#### Resetting temporary passwords on EDB PgBouncer hosts

You can reset the temporary password for the enterprisedb user on every
PgBouncer host by running the following command as root:
EDB PgBouncer host by running the following command as root:
``` text
passwd -d enterprisedb
```
### Configuring the network load balancer

For the Failover Manager PgBouncer integration using a network load balancer in AWS or Azure, you need to perform additional steps.
For the Failover Manager \ EDB PgBouncer integration using a network load balancer in AWS or Azure, you need to perform additional steps.

Add the following rules to the security groups to be used by the PgBouncer and database instances.
Add the following rules to the security groups to be used by the EDB PgBouncer and database instances.

<div id="sg_rules_pgbouncer" class="registered_link"></div>

- Rules for the security group to be used by the PgBouncer instances
- Rules for the security group to be used by the EDB PgBouncer instances
(SG PgBouncer).


Expand All @@ -229,7 +229,7 @@ Add the following rules to the security groups to be used by the PgBouncer and d
Custom TCP | TCP | 22 | Entire Subnet | ssh


These rules ensure that the ports required to run the database, Failover Manager, and PgBouncer are open for communication between the nodes
These rules ensure that the ports required to run the database, Failover Manager, and EDB PgBouncer are open for communication between the nodes
and the load balancer for traffic routing and health monitoring.

In addition to these rules, add the rules for SSH and Ping as per your requirement.
Expand All @@ -241,10 +241,10 @@ If you are using AWS, see [Configuring NLB in AWS](#config_nlb_aws).
After configuring the rules described in [Creating rules for security groups](#sg_rules_pgbouncer), follow the Azure documentation to:

- Create a backend pool consisting of the two virtual machines running
the PgBouncer instances. Use the private IPs of the virtual machines
the EDB PgBouncer instances. Use the private IPs of the virtual machines
to create the backend pool.

- Add a health probe to check if the PgBouncer instance is available
- Add a health probe to check if the EDB PgBouncer instance is available
on the virtual machines. Select `TCP` as the protocol and
`6432` as the port.

Expand All @@ -257,10 +257,10 @@ After configuring the rules described in [Creating rules for security groups](#s
After completing these configurations, you can connect to the database
on the IP address of the network load balancer using port 6432. If a
failure occurs on the primary database server, Failover Manager
promotes a new primary and then reconfigures PgBouncer to redistribute
traffic. If any of the PgBouncer processes is not available to
promotes a new primary and then reconfigures EDB PgBouncer to redistribute
traffic. If any of the EDB PgBouncer processes is not available to
accept traffic, the network load balancer redistributes all
the traffic to the remaining PgBouncer processes. Make sure that the
the traffic to the remaining EDB PgBouncer processes. Make sure that the
`max_client_conn` parameter is tuned to compensate for the higher number
of connections in case of failover.

Expand Down Expand Up @@ -289,7 +289,7 @@ After configuring the rules described in [Creating rules for security groups](#s

Leave the rest of the settings (**Health check TCP** and **Advanced health check** settings) as default.

Register the created target groups with the instances that are running PgBouncer.
Register the created target groups with the instances that are running EDB PgBouncer.

- Create a load balancer with the following details:

Expand All @@ -301,9 +301,9 @@ After configuring the rules described in [Creating rules for security groups](#s
After completing the configurations, you can connect to the database on
the IP address of the network load balancer on port 6432. If a failure
occurs on the primary database server, Failover Manager promotes a new
primary and then reconfigures PgBouncer to redistribute traffic. If any
of the PgBouncer processes is not available to accept traffic, the network
primary and then reconfigures EDB PgBouncer to redistribute traffic. If any
of the EDB PgBouncer processes is not available to accept traffic, the network
load balancer redistributes all the traffic to
the remaining PgBouncer processes. Make sure that the `max_client_conn`
the remaining EDB PgBouncer processes. Make sure that the `max_client_conn`
parameter is tuned to compensate for the higher number of connections in
case of failover.
Loading

0 comments on commit f57544a

Please sign in to comment.