2019-11-09 00:14:43 +08:00
|
|
|
-- ===================================================================
|
|
|
|
-- create FDW objects
|
|
|
|
-- ===================================================================
|
|
|
|
\set QUIET on
|
|
|
|
SET client_min_messages TO error;
|
|
|
|
\set VERBOSITY terse
|
|
|
|
CREATE EXTENSION postgres_fdw;
|
|
|
|
|
|
|
|
CREATE ROLE cdb_fs_tester LOGIN PASSWORD 'cdb_fs_passwd';
|
|
|
|
GRANT CONNECT ON DATABASE contrib_regression TO cdb_fs_tester;
|
|
|
|
|
|
|
|
-- Create database to be used as remote
|
|
|
|
CREATE DATABASE cdb_fs_tester OWNER cdb_fs_tester;
|
|
|
|
|
|
|
|
SELECT 'C1', cartodb.CDB_Federated_Server_Register_PG(server => 'loopback'::text, config => '{
|
|
|
|
"server": {
|
|
|
|
"host": "localhost",
|
|
|
|
"port": @@PGPORT@@
|
|
|
|
},
|
|
|
|
"credentials": {
|
|
|
|
"username": "cdb_fs_tester",
|
|
|
|
"password": "cdb_fs_passwd"
|
|
|
|
}
|
|
|
|
}'::jsonb);
|
2019-11-09 03:02:51 +08:00
|
|
|
|
|
|
|
\c cdb_fs_tester postgres
|
|
|
|
CREATE EXTENSION postgis;
|
|
|
|
\c contrib_regression postgres
|
2019-11-09 00:14:43 +08:00
|
|
|
\set QUIET off
|
|
|
|
|
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Test server diagnostics function(s)
|
|
|
|
-- ===================================================================
|
2019-11-08 22:25:57 +08:00
|
|
|
\echo '%% It raises an error if the server does not exist'
|
|
|
|
SELECT '1.1', cartodb.CDB_Federated_Server_Diagnostics(server => 'doesNotExist');
|
2019-11-09 00:14:43 +08:00
|
|
|
|
|
|
|
\echo '%% It returns a jsonb object'
|
|
|
|
SELECT '1.2', pg_typeof(cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback'));
|
|
|
|
|
2019-11-09 01:09:22 +08:00
|
|
|
\echo '%% It returns the server version'
|
2019-11-09 01:18:28 +08:00
|
|
|
SELECT '1.3', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @> format('{"server_version": "%s"}', setting)::jsonb
|
|
|
|
FROM pg_settings WHERE name = 'server_version';
|
2019-11-09 01:09:22 +08:00
|
|
|
|
2019-11-09 02:49:16 +08:00
|
|
|
\echo '%% It returns the postgis version'
|
|
|
|
SELECT '1.4', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @> format('{"postgis_version": "%s"}', extversion)::jsonb
|
|
|
|
FROM pg_extension WHERE extname = 'postgis';
|
|
|
|
|
2019-11-09 03:27:24 +08:00
|
|
|
\echo '%% It returns null as the postgis version if it is not installed'
|
|
|
|
\set QUIET on
|
|
|
|
\c cdb_fs_tester postgres
|
|
|
|
DROP EXTENSION postgis;
|
|
|
|
\c contrib_regression postgres
|
|
|
|
\set QUIET off
|
|
|
|
SELECT '1.5', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @> '{"postgis_version": null}'::jsonb;
|
|
|
|
|
2019-11-11 22:56:17 +08:00
|
|
|
\echo '%% It returns the remote server options'
|
2019-11-12 17:32:25 +08:00
|
|
|
SELECT '1.6', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @> '{"server_options": {"host": "localhost", "port": "@@PGPORT@@", "updatable": "false", "extensions": "postgis", "fetch_size": "1000", "use_remote_estimate": "true"}}'::jsonb;
|
2019-11-11 22:56:17 +08:00
|
|
|
|
2019-11-09 00:14:43 +08:00
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Cleanup
|
|
|
|
-- ===================================================================
|
|
|
|
\set QUIET on
|
|
|
|
SELECT 'D1', cartodb.CDB_Federated_Server_Unregister(server => 'loopback'::text);
|
2019-11-09 02:20:08 +08:00
|
|
|
-- Reconnect, using a new session in order to close FDW connections
|
|
|
|
\connect
|
2019-11-09 00:14:43 +08:00
|
|
|
DROP DATABASE cdb_fs_tester;
|
|
|
|
|
|
|
|
-- Drop role
|
|
|
|
REVOKE CONNECT ON DATABASE contrib_regression FROM cdb_fs_tester;
|
|
|
|
DROP ROLE cdb_fs_tester;
|
|
|
|
|
|
|
|
DROP EXTENSION postgres_fdw;
|
|
|
|
\set QUIET off
|