From d23c7c15e47c36e9c508a344cebff5f8db7bac64 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Wed, 10 Jan 2024 12:58:17 +0100 Subject: [PATCH] Make extension state available through function The extension state is not easily accessible in release builds, which makes debugging issue with the loader very difficult. This commit introduces a new schema `timescaledb_debug` and makes the function `ts_extension_get_state` available also in release builds as `timescaledb_debug.extension_state`. See #1682 --- sql/debug_utils.sql | 3 +++ sql/pre_install/schemas.sql | 12 +++++++++++- sql/updates/latest-dev.sql | 3 +++ sql/updates/reverse-dev.sql | 2 ++ src/extension.c | 16 +++++++--------- tsl/test/shared/expected/extension.out | 1 + 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/sql/debug_utils.sql b/sql/debug_utils.sql index 30f3f3019be..87a27b73eec 100644 --- a/sql/debug_utils.sql +++ b/sql/debug_utils.sql @@ -13,3 +13,6 @@ AS '@MODULE_PATHNAME@', 'ts_debug_point_release'; CREATE OR REPLACE FUNCTION debug_waitpoint_id(TEXT) RETURNS BIGINT LANGUAGE C VOLATILE STRICT AS '@MODULE_PATHNAME@', 'ts_debug_point_id'; + +CREATE OR REPLACE FUNCTION timescaledb_debug.extension_state() RETURNS TEXT +AS '@MODULE_PATHNAME@', 'ts_extension_get_state' LANGUAGE C; diff --git a/sql/pre_install/schemas.sql b/sql/pre_install/schemas.sql index 4f55c8f0994..5e62d3045aa 100644 --- a/sql/pre_install/schemas.sql +++ b/sql/pre_install/schemas.sql @@ -11,6 +11,16 @@ CREATE SCHEMA _timescaledb_cache; CREATE SCHEMA _timescaledb_config; CREATE SCHEMA timescaledb_experimental; CREATE SCHEMA timescaledb_information; +CREATE SCHEMA timescaledb_debug; -GRANT USAGE ON SCHEMA _timescaledb_cache, _timescaledb_catalog, _timescaledb_functions, _timescaledb_internal, _timescaledb_config, timescaledb_information, timescaledb_experimental TO PUBLIC; +GRANT USAGE ON SCHEMA + _timescaledb_cache, + _timescaledb_catalog, + _timescaledb_functions, + _timescaledb_internal, + _timescaledb_config, + timescaledb_debug, + timescaledb_information, + timescaledb_experimental +TO PUBLIC; diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql index 113c7418b63..d1c14736aae 100644 --- a/sql/updates/latest-dev.sql +++ b/sql/updates/latest-dev.sql @@ -316,3 +316,6 @@ ALTER TABLE _timescaledb_catalog.dimension ADD CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; ALTER TABLE _timescaledb_catalog.tablespace ADD CONSTRAINT tablespace_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; + +CREATE SCHEMA timescaledb_debug; +GRANT USAGE ON SCHEMA timescaledb_debug TO PUBLIC; diff --git a/sql/updates/reverse-dev.sql b/sql/updates/reverse-dev.sql index e8ede2f9882..36904117066 100644 --- a/sql/updates/reverse-dev.sql +++ b/sql/updates/reverse-dev.sql @@ -623,3 +623,5 @@ ALTER TABLE _timescaledb_catalog.hypertable_data_node ALTER TABLE _timescaledb_catalog.tablespace ADD CONSTRAINT tablespace_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE; +DROP FUNCTION IF EXISTS timescaledb_debug.extension_state; +DROP SCHEMA IF EXISTS timescaledb_debug; diff --git a/src/extension.c b/src/extension.c index 209928c9a25..ce8b8e9d9f0 100644 --- a/src/extension.c +++ b/src/extension.c @@ -66,6 +66,13 @@ static enum ExtensionState extstate = EXTENSION_STATE_UNKNOWN; */ static Oid ts_extension_oid = InvalidOid; +static const char *extstate_str[] = { + [EXTENSION_STATE_UNKNOWN] = "unknown", + [EXTENSION_STATE_TRANSITIONING] = "transitioning", + [EXTENSION_STATE_CREATED] = "created", + [EXTENSION_STATE_NOT_INSTALLED] = "not installed", +}; + static bool extension_loader_present() { @@ -334,14 +341,6 @@ ts_extension_is_proxy_table_relid(Oid relid) return relid == extension_proxy_oid; } -#ifdef TS_DEBUG -static const char *extstate_str[] = { - [EXTENSION_STATE_UNKNOWN] = "unknown", - [EXTENSION_STATE_TRANSITIONING] = "transitioning", - [EXTENSION_STATE_CREATED] = "created", - [EXTENSION_STATE_NOT_INSTALLED] = "not installed", -}; - TS_FUNCTION_INFO_V1(ts_extension_get_state); Datum @@ -349,4 +348,3 @@ ts_extension_get_state(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(cstring_to_text(extstate_str[extstate])); } -#endif diff --git a/tsl/test/shared/expected/extension.out b/tsl/test/shared/expected/extension.out index 30829be878f..6657cba45b5 100644 --- a/tsl/test/shared/expected/extension.out +++ b/tsl/test/shared/expected/extension.out @@ -296,6 +296,7 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text time_bucket_gapfill(smallint,smallint,smallint,smallint) timescaledb_post_restore() timescaledb_pre_restore() + timescaledb_debug.extension_state() timescaledb_experimental.add_policies(regclass,boolean,"any","any","any","any") timescaledb_experimental.alter_policies(regclass,boolean,"any","any","any","any") timescaledb_experimental.remove_all_policies(regclass,boolean)