https://github.com/artemtech/flask-pgsqlcheck
flask version of xinetd for pgsqlcheck
https://github.com/artemtech/flask-pgsqlcheck
Last synced: about 2 months ago
JSON representation
flask version of xinetd for pgsqlcheck
- Host: GitHub
- URL: https://github.com/artemtech/flask-pgsqlcheck
- Owner: artemtech
- Created: 2023-02-02T08:16:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-18T07:36:34.000Z (about 2 years ago)
- Last Synced: 2025-01-01T13:41:57.746Z (over 1 year ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# flask-pgsqlcheck
flask version of xinetd for pgsqlcheck.
The idea is we run query to postgres `select pg_is_in_recovery()`. This query will return true or false.
So, if it is true, then our instance is standby node, otherwise it is primary node. If the node is unreachable, then it will marked as DOWN.
This script is suitable for creating high-availability postgresql behind haproxy.
## Build docker image
```
docker build -t flask-pgsqlcheck ./
```
## Usage
```bash
# set environment variable
nano .env
POSTGRESQL_HOST=
POSTGRESQL_DB=
POSTGRESQL_USER=
POSTGRESQL_PASS=
POSTGRESQL_PORT=
# run docker image
docker run -dti --name flask-pgsqlcheck --network-mode host flask-pgsqlcheck
# test hit
curl http://localhost:25432/
```
## Usage for haproxy check
```
...
frontend db-primary
bind *:5432
default_backend db-backend-primary
frontend db-standby
bind *:5433
default_backend db-backend-standby
backend db-backend-primary
option httpchk GET / HTTP/1.1
http-check expect status 200
server db-01 1.2.3.4:5432 check port 25432
server db-02 1.2.3.4:5432 check port 25432
backend db-backend-standby
option httpchk GET / HTTP/1.1
http-check expect status 206
server db-01 1.2.3.4:5432 check port 25432
server db-02 1.2.3.4:5432 check port 25432
```