ON THIS PAGE
Check PostgresDB
Purpose
Confirm the health of the PostgresDB database by listing the states of the leaders and replicas. You must have, at a minimum, one leader in running state and two replicas in streaming state for PostgresDB to be considered healthy. If any replica is in a non-streaming state (such as stopped, starting, and so on), you can reinitalize the replica.
Action
Log in to an atom-db
pod using the kubectl exec -it -n common
atom-db-0 -- bash
command. List the cluster
name,
and all the replicas and leaders using the patronictl list
command.
If any replica is not in streaming state, reinitialize the replica using the
patronictl reinit atom-db atom-db-2
command.
Sample Output
root@pa1:~# kubectl exec -it -n common atom-db-0 -- bash Defaulted container "postgres" out of: postgres, exporter ____ _ _ / ___| _ __ (_) | ___ \___ \| '_ \| | |/ _ \ ___) | |_) | | | (_) | |____/| .__/|_|_|\___/ |_| This container is managed by runit, when stopping/starting services use sv Examples: sv stop cron sv restart patroni Current status: (sv status /etc/service/*) run: /etc/service/patroni: (pid 32) 589651s run: /etc/service/pgqd: (pid 33) 589651s root@atom-db-0:/home/postgres# patronictl list + Cluster: atom-db (7464654262273740859) ----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +-----------+----------------+---------+-----------+----+-----------+ | atom-db-0 | 10.1.2.37 | Leader | running | 1 | | | atom-db-1 | 10.1.3.46 | Replica | streaming | 1 | 0 | | atom-db-2 | 10.1.4.51 | Replica | streaming | 1 | 0 | +-----------+----------------+---------+-----------+----+-----------+
root@atom-db-0:/home/postgres# patronictl reinit atom-db atom-db-2 + Cluster: atom-db (7464654262273740859) ----------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +-----------+----------------+---------+-----------+----+-----------+ | atom-db-0 | 10.1.2.37 | Leader | running | 1 | | | atom-db-1 | 10.1.3.46 | Replica | streaming | 1 | 0 | | atom-db-2 | 10.1.4.51 | Replica | stopped | 1 | 0 | +-----------+----------------+---------+-----------+----+-----------+ Are you sure you want to reinitialize members atom-db-2? [y/N]: y Success: reinitialize for member atom-db-2
Where, atom-db
is the cluster name, and atom-db-2
is the
replica that you want to reinitialize.
Meaning
You must have at least one leader in the running state and two replicas in the streaming state for PostgresDB to be considered healthy.