mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 01:53:41 +08:00
A new health check function _timescaledb_internal.health() returns the health and status of the database instance, including any configured data nodes (in case the instance is an access node). Since the function returns also the health of the data nodes, it tries hard to avoid throwing errors. An error will fail the whole function and therefore not return any node statuses, although some of the nodes might be healthy. The health check on the data nodes is a recursive (remote) call to the same function on those nodes. Unfortunately, the check will fail with an error if a connection cannot be established to a node (or an error occurs on the connection), which means the whole function call will fail. This will be addressed in a future change by returning the error in the function result instead.
57 lines
2.1 KiB
PL/PgSQL
57 lines
2.1 KiB
PL/PgSQL
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
|
|
--documentation of these function located in chunk_index.h
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_index_clone(chunk_index_oid OID) RETURNS OID
|
|
AS '@MODULE_PATHNAME@', 'ts_chunk_index_clone' LANGUAGE C VOLATILE STRICT;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_index_replace(chunk_index_oid_old OID, chunk_index_oid_new OID) RETURNS VOID
|
|
AS '@MODULE_PATHNAME@', 'ts_chunk_index_replace' LANGUAGE C VOLATILE STRICT;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.create_chunk_replica_table(
|
|
chunk REGCLASS,
|
|
data_node_name NAME
|
|
) RETURNS VOID AS '@MODULE_PATHNAME@', 'ts_chunk_create_replica_table' LANGUAGE C VOLATILE;
|
|
|
|
-- Drop the specified chunk replica on the specified data node
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.chunk_drop_replica(
|
|
chunk REGCLASS,
|
|
node_name NAME
|
|
) RETURNS VOID
|
|
AS '@MODULE_PATHNAME@', 'ts_chunk_drop_replica' LANGUAGE C VOLATILE;
|
|
|
|
CREATE OR REPLACE PROCEDURE _timescaledb_internal.wait_subscription_sync(
|
|
schema_name NAME,
|
|
table_name NAME,
|
|
retry_count INT DEFAULT 18000,
|
|
retry_delay_ms NUMERIC DEFAULT 0.200
|
|
)
|
|
LANGUAGE PLPGSQL AS
|
|
$BODY$
|
|
DECLARE
|
|
in_sync BOOLEAN;
|
|
BEGIN
|
|
FOR i in 1 .. retry_count
|
|
LOOP
|
|
SELECT pgs.srsubstate = 'r'
|
|
INTO in_sync
|
|
FROM pg_subscription_rel pgs
|
|
JOIN pg_class pgc ON relname = table_name
|
|
JOIN pg_namespace n ON (n.OID = pgc.relnamespace)
|
|
WHERE pgs.srrelid = pgc.oid AND schema_name = n.nspname;
|
|
|
|
if (in_sync IS NULL OR NOT in_sync) THEN
|
|
PERFORM pg_sleep(retry_delay_ms);
|
|
ELSE
|
|
RETURN;
|
|
END IF;
|
|
END LOOP;
|
|
RAISE 'subscription sync wait timedout';
|
|
END
|
|
$BODY$ SET search_path TO pg_catalog, pg_temp;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.health() RETURNS
|
|
TABLE (node_name NAME, healthy BOOL, in_recovery BOOL, error TEXT)
|
|
AS '@MODULE_PATHNAME@', 'ts_health_check' LANGUAGE C VOLATILE;
|