timescaledb/sql/ddl_internal.sql
Sven Klemm b2a91494a1 Move ddl_internal functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint)
- chunk_drop_replica(regclass,name)
- chunk_index_clone(oid)
- chunk_index_replace(oid,oid)
- create_chunk_replica_table(regclass,name)
- drop_stale_chunks(name,integer[])
- health()
- hypertable_constraint_add_table_fk_constraint(name,name,name,integer)
- process_ddl_event()
- wait_subscription_sync(name,name,integer,numeric)
2023-08-29 11:15:39 +02:00

63 lines
2.3 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_functions.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_functions.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_functions.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_functions.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_functions.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_functions.health() RETURNS
TABLE (node_name NAME, healthy BOOL, in_recovery BOOL, error TEXT)
AS '@MODULE_PATHNAME@', 'ts_health_check' LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION _timescaledb_functions.drop_stale_chunks(
node_name NAME,
chunks integer[] = NULL
) RETURNS VOID
AS '@MODULE_PATHNAME@', 'ts_chunks_drop_stale' LANGUAGE C VOLATILE;