[MINOR] checks: add PostgreSQL health check
I have written a small patch to enable a correct PostgreSQL health check
It works similar to mysql-check with the very same parameters.
E.g.:
listen pgsql 127.0.0.1:5432
mode tcp
option pgsql-check user pgsql
server masterdb pgsql.server.com:5432 check inter 10000
diff --git a/src/checks.c b/src/checks.c
index a23fd41..ee0b97b 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -747,6 +747,7 @@
(s->proxy->options & PR_O_SMTP_CHK) ||
(s->proxy->options2 & PR_O2_SSL3_CHK) ||
(s->proxy->options2 & PR_O2_MYSQL_CHK) ||
+ (s->proxy->options2 & PR_O2_PGSQL_CHK) ||
(s->proxy->options2 & PR_O2_LDAP_CHK)) {
int ret;
const char *check_req = s->proxy->check_req;
@@ -1001,6 +1002,22 @@
else
set_server_check_status(s, HCHK_STATUS_L7STS, desc);
}
+ else if (s->proxy->options2 & PR_O2_PGSQL_CHK) {
+ if (!done && s->check_data_len < 9)
+ goto wait_more_data;
+
+ if (s->check_data[0] == 'R') {
+ set_server_check_status(s, HCHK_STATUS_L7OKD, "PostgreSQL server is ok");
+ }
+ else {
+ if ((s->check_data[0] == 'E') && (s->check_data[5]!=0) && (s->check_data[6]!=0))
+ desc = &s->check_data[6];
+ else
+ desc = "PostgreSQL unknown error";
+
+ set_server_check_status(s, HCHK_STATUS_L7STS, desc);
+ }
+ }
else if (s->proxy->options2 & PR_O2_MYSQL_CHK) {
if (!done && s->check_data_len < 5)
goto wait_more_data;