Skip to content

Commit

Permalink
PG-1223 Updated etcd setup steps (15) (#703)
Browse files Browse the repository at this point in the history
new file:   snippets/check-etcd.md
        new file:   snippets/percona-release-apt.md
        new file:   snippets/percona-release-yum.md
  • Loading branch information
nastena1606 authored Dec 16, 2024
1 parent 172c7de commit 9f04628
Show file tree
Hide file tree
Showing 7 changed files with 479 additions and 352 deletions.
1 change: 1 addition & 0 deletions docs/css/design.css
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
vertical-align: baseline;
padding: 0 0.2em 0.1em;
border-radius: 0.15em;
white-space: pre-wrap; /* Ensure long lines wrap */
}
.md-typeset .highlight code span,
.md-typeset code,
Expand Down
366 changes: 191 additions & 175 deletions docs/solutions/ha-setup-apt.md

Large diffs are not rendered by default.

371 changes: 195 additions & 176 deletions docs/solutions/ha-setup-yum.md

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion docs/solutions/high-availability.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ There are several methods to achieve high availability in PostgreSQL. This solut

## Patroni

[Patroni :octicons-link-external-16:](https://patroni.readthedocs.io/en/latest/) is a template for you to create your own customized, high-availability solution using Python and - for maximum accessibility - a distributed configuration store like ZooKeeper, etcd, Consul or Kubernetes.
[Patroni :octicons-link-external-16:](https://patroni.readthedocs.io/en/latest/) is a Patroni is an open-source tool that helps to deploy, manage, and monitor highly available PostgreSQL clusters using physical streaming replication. Patroni relies on a distributed configuration store like ZooKeeper, etcd, Consul or Kubernetes to store the cluster configuration.

### Key benefits of Patroni:

Expand All @@ -50,6 +50,21 @@ There are several methods to achieve high availability in PostgreSQL. This solut
* Distributed consensus for every action and configuration.
* Integration with Linux watchdog for avoiding split-brain syndrome.

## etcd

As stated before, Patroni uses a distributed configuration store to store the cluster configuration, health and status.The most popular implementation of the distributed configuration store is etcd due to its simplicity, consistency and reliability. Etcd not only stores the cluster data, it also handles the election of a new primary node (a leader in ETCD terminology).

etcd is deployed as a cluster for fault-tolerance. An etcd cluster needs a majority of nodes, a quorum, to agree on updates to the cluster state.

The recommended approach is to deploy an odd-sized cluster (e.g. 3, 5 or 7 nodes). The odd number of nodes ensures that there is always a majority of nodes available to make decisions and keep the cluster running smoothly. This majority is crucial for maintaining consistency and availability, even if one node fails. For a cluster with n members, the majority is (n/2)+1.

To better illustrate this concept, let's take an example of clusters with 3 nodes and 4 nodes.

In a 3-node cluster, if one node fails, the remaining 2 nodes still form a majority (2 out of 3), and the cluster can continue to operate.

In a 4-nodes cluster, if one node fails, there are only 3 nodes left, which is not enough to form a majority (3 out of 4). The cluster stops functioning.

In this solution we use a 3-nodes etcd cluster that resides on the same hosts with PostgreSQL and Patroni. Though

!!! admonition "See also"

Expand Down
47 changes: 47 additions & 0 deletions snippets/check-etcd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
3. Check the etcd cluster members. Use `etcdctl` for this purpose. Ensure that `etcdctl` interacts with etcd using API version 3 and knows which nodes, or endpoints, to communicate with. For this, we will define the required information as environment variables. Run the following commands on one of the nodes:

```
export ETCDCTL_API=3
HOST_1=10.104.0.1
HOST_2=10.104.0.2
HOST_3=10.104.0.3
ENDPOINTS=$HOST_1:2379,$HOST_2:2379,$HOST_3:2379
```
4. Now, list the cluster members and output the result as a table as follows:
```{.bash data-prompt="$"}
$ sudo etcdctl --endpoints=$ENDPOINTS -w table member list
```
??? example "Sample output"
```
+------------------+---------+-------+------------------------+----------------------------+------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
+------------------+---------+-------+------------------------+----------------------------+------------+
| 4788684035f976d3 | started | node2 | http://10.104.0.2:2380 | http://192.168.56.102:2379 | false |
| 67684e355c833ffa | started | node3 | http://10.104.0.3:2380 | http://192.168.56.103:2379 | false |
| 9d2e318af9306c67 | started | node1 | http://10.104.0.1:2380 | http://192.168.56.101:2379 | false |
+------------------+---------+-------+------------------------+----------------------------+------------+
```
5. To check what node is currently the leader, use the following command
```{.bash data-prompt="$"}
$ sudo etcdctl --endpoints=$ENDPOINTS -w table endpoint status
```
??? example "Sample output"
```{.text .no-copy}
+-----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 10.104.0.1:2379 | 9d2e318af9306c67 | 3.5.16 | 20 kB | true | false | 2 | 10 | 10 | |
| 10.104.0.2:2379 | 4788684035f976d3 | 3.5.16 | 20 kB | false | false | 2 | 10 | 10 | |
| 10.104.0.3:2379 | 67684e355c833ffa | 3.5.16 | 20 kB | false | false | 2 | 10 | 10 | |
+-----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
```
24 changes: 24 additions & 0 deletions snippets/percona-release-apt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
1. Install the `curl` download utility if it's not installed already:

```{.bash data-prompt="$"}
$ sudo apt update
$ sudo apt install curl
```

2. Download the `percona-release` repository package:

```{.bash data-prompt="$"}
$ curl -O https://repo.percona.com/apt/percona-release_latest.generic_all.deb
```

3. Install the downloaded repository package and its dependencies using `apt`:

```{.bash data-prompt="$"}
$ sudo apt install gnupg2 lsb-release ./percona-release_latest.generic_all.deb
```

4. Refresh the local cache to update the package information:

```{.bash data-prompt="$"}
$ sudo apt update
```
5 changes: 5 additions & 0 deletions snippets/percona-release-yum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Run the following command as the `root` user or with `sudo` privileges:

```{.bash data-prompt="$"}
$ sudo yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
```

0 comments on commit 9f04628

Please sign in to comment.