From c387f441289f6e2895108802d8f6bc5fe6e6ec07 Mon Sep 17 00:00:00 2001 From: "kuroda.hayato%40jp.fujitsu.com" Date: Wed, 21 Sep 2022 06:47:55 +0000 Subject: [PATCH v16 3/4] add doc This patch adds descriptions about postgres_fdw.health_check_interval --- doc/src/sgml/fdwhandler.sgml | 75 ++++++++++++++++++++++++++++++++++ doc/src/sgml/postgres-fdw.sgml | 26 ++++++++++++ 2 files changed, 101 insertions(+) diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml index d0b5951019..4c1c252bc1 100644 --- a/doc/src/sgml/fdwhandler.sgml +++ b/doc/src/sgml/fdwhandler.sgml @@ -2136,4 +2136,79 @@ GetForeignServerByName(const char *name, bool missing_ok); + + Health check of Foreign servers + + + Additionally, the FDW author can implement a function to check health of + foreign servers. PostgreSQL has a mechanism to call callback functions + registered by FDW, and they will be done when flags are set. To enable the + feature, FDW authors must 1) implement health check function, 2) register + the implemented function as health check callback function, and + 3) set flags in arbitrary ways. + + + + Implement health check function + + + The health check function must be defined as following datatype. + +typedef void (*CheckingRemoteServersCallback) (void *arg); + + + + + When FDW finds disconnections to foreign servers, the function must set + an error message and send SIGINT signal to its backend process. To fill + and check the message following APIs can be used, which are declared in + tcop/tcopprot.h. + + +extern bool TrySetQueryCancelMessage(char *message); +extern bool HasQueryCancelMessage(void); + + + Note that the message will be duplicated to the transactional memory + context. The message does not have to be allocated memory by FDW author. + + + + + + Register a callback + + + Authors needs to register the callback function via following API. + + +void +RegisterCheckingRemoteServersCallback(CheckingRemoteServersCallback callback, + void *arg) + + + + + + + Set flags in arbitrary ways + + + Finally, authors must implement a mechanism to fire the health check + callbacks. It can be done by setting flags CheckingRemoteServersTimeoutPending + and InterruptPending to true. They are declared in miscadmin.h. + + +volatile sig_atomic_t InterruptPending = false; +volatile sig_atomic_t CheckingRemoteServersTimeoutPending = false; + + + Typically, the timeout mechanism can be used to set these flags. The + detailed description and usage are written in src/backend/utils/misc/timeout.c. + + + + + + diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml index bfd344cdc0..44e4f07dd9 100644 --- a/doc/src/sgml/postgres-fdw.sgml +++ b/doc/src/sgml/postgres-fdw.sgml @@ -1078,6 +1078,32 @@ postgres=# SELECT postgres_fdw_disconnect_all(); + + + postgres_fdw.health_check_interval (integer) + + postgres_fdw.health_check_interval configuration parameter + + + + + Sets the time interval between optional checks that remote servers + are still alive. When losing a remote connection is detected, + the running transaction is aborted. This feature is performed + by polling the socket. + + + This option relies on kernel events exposed by Linux, macOS, + illumos and the BSD family of operating systems, and is not currently available + on other systems. + + + If the value is specified without units, it is taken as milliseconds. + The default value is 0, which disables connection + checks. + + + -- 2.27.0