Function to retrieve remote PG server ver
This commit is contained in:
parent
efd757ffa3
commit
8730292097
@ -2,22 +2,53 @@
|
||||
-- Private functions
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Server_Version_PG(server_internal name)
|
||||
--
|
||||
-- Get the version of a remote PG server
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Foreign_Server_Version_PG(server_internal name)
|
||||
RETURNS text
|
||||
AS $$
|
||||
DECLARE
|
||||
-- Import pg_settings from pg_catalog
|
||||
remote_schema name := 'pg_catalog';
|
||||
remote_table name := 'pg_settings';
|
||||
local_schema name := @extschema@.__CDB_FS_Create_Schema(server_internal, remote_schema);
|
||||
role_name name := @extschema@.__CDB_FS_Generate_Server_Role_Name(server_internal);
|
||||
remote_server_version text;
|
||||
BEGIN
|
||||
-- TODO Implement
|
||||
RETURN '14.0';
|
||||
-- Import the foreign pg_settings table
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM pg_class
|
||||
WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = local_schema)
|
||||
AND relname = remote_table
|
||||
) THEN
|
||||
EXECUTE format('IMPORT FOREIGN SCHEMA %I LIMIT TO (%I) FROM SERVER %I INTO %I',
|
||||
remote_schema, remote_table, server_internal, local_schema);
|
||||
END IF;
|
||||
|
||||
BEGIN
|
||||
EXECUTE format('
|
||||
SELECT setting FROM %I.%I WHERE name = ''server_version'';
|
||||
', local_schema, remote_table) INTO remote_server_version;
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
RAISE EXCEPTION 'Not enough permissions to access the server "%"',
|
||||
@extschema@.__CDB_FS_Extract_Server_Name(server_internal);
|
||||
END;
|
||||
|
||||
RETURN remote_server_version;
|
||||
END
|
||||
$$
|
||||
LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
|
||||
--
|
||||
-- Collect and return diagnostics info from a remote PG into a jsonb
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Server_Diagnostics_PG(server_internal name)
|
||||
RETURNS jsonb
|
||||
AS $$
|
||||
DECLARE
|
||||
remote_server_version text := @extschema@.__CDB_FS_Server_Version_PG(server_internal);
|
||||
remote_server_version text := @extschema@.__CDB_FS_Foreign_Server_Version_PG(server_internal);
|
||||
BEGIN
|
||||
RETURN jsonb_build_object('server_version', remote_server_version);
|
||||
END
|
||||
@ -31,7 +62,7 @@ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
--
|
||||
-- TODO: function documentation
|
||||
-- Collect and return diagnostics info from a remote PG into a jsonb
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION @extschema@.CDB_Federated_Server_Diagnostics(server TEXT)
|
||||
RETURNS jsonb
|
||||
|
@ -44,6 +44,8 @@ SELECT '1.3', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @>
|
||||
-- ===================================================================
|
||||
\set QUIET on
|
||||
SELECT 'D1', cartodb.CDB_Federated_Server_Unregister(server => 'loopback'::text);
|
||||
-- Reconnect, using a new session in order to close FDW connections
|
||||
\connect
|
||||
DROP DATABASE cdb_fs_tester;
|
||||
|
||||
-- Drop role
|
||||
|
Loading…
Reference in New Issue
Block a user