Require host parameter in add_data_node

Change `add_data_node` so that host parameter is required. If the host
parameter is not provided, or is `NULL`, an error will be printed.

Also change logic for how the default value for `port` is picked. Now
it will by default use the port given in the configuration file.

The commit update all the result files, add the `host` parameter to all
calls of `add_data_node` and add a few tests to check that an error is
given when `host` is not provided.
This commit is contained in:
Mats Kindahl 2019-08-30 11:22:35 +02:00 committed by Erik Nordström
parent abd5a9a939
commit 6e9f644714
24 changed files with 200 additions and 160 deletions

View File

@ -160,8 +160,8 @@ AS '@MODULE_PATHNAME@', 'ts_tablespace_show' LANGUAGE C VOLATILE STRICT;
-- Add a data node to a TimescaleDB distributed database.
CREATE OR REPLACE FUNCTION add_data_node(
node_name NAME,
host TEXT = NULL,
database NAME = current_database(),
host TEXT,
database NAME = NULL,
port INTEGER = NULL,
if_not_exists BOOLEAN = FALSE,
bootstrap_database NAME = 'postgres',

View File

@ -529,16 +529,21 @@ data_node_add_internal(PG_FUNCTION_ARGS, bool set_distid)
Oid userid = GetUserId();
const char *username = GetUserNameFromId(userid, false);
const char *node_name = PG_ARGISNULL(0) ? NULL : PG_GETARG_CSTRING(0);
const char *host =
PG_ARGISNULL(1) ? TS_DEFAULT_POSTGRES_HOST : TextDatumGetCString(PG_GETARG_DATUM(1));
const char *host = PG_ARGISNULL(1) ? NULL : TextDatumGetCString(PG_GETARG_DATUM(1));
const char *dbname = PG_ARGISNULL(2) ? get_database_name(MyDatabaseId) : PG_GETARG_CSTRING(2);
long port = PG_ARGISNULL(3) ? get_server_port() : PG_GETARG_INT32(3);
bool if_not_exists = PG_ARGISNULL(4) ? false : PG_GETARG_BOOL(4);
const char *bootstrap_database = PG_ARGISNULL(5) ? dbname : PG_GETARG_CSTRING(5);
const char *bootstrap_user = PG_ARGISNULL(6) ? username : PG_GETARG_CSTRING(6);
bool server_created = false;
bool database_created = false;
bool extension_created = false;
long port;
if (host == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
(errmsg("a host needs to be specified"),
errhint("Provide a host name or IP address of a data node to add."))));
if (set_distid && dist_util_membership() == DIST_MEMBER_DATA_NODE)
ereport(ERROR,
@ -554,21 +559,6 @@ data_node_add_internal(PG_FUNCTION_ARGS, bool set_distid)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errmsg("invalid data node name"))));
/*
* - If a port was provided, use that.
*
* - If a port was not provided, but a host was provided, use default Postgres port.
*
* - If neither port nor host were provided, use the port of the server
* (which is not the same as the default Postgres port).
*/
if (!PG_ARGISNULL(3))
port = PG_GETARG_INT32(3);
else if (!PG_ARGISNULL(1))
port = TS_DEFAULT_POSTGRES_PORT;
else
port = get_server_port();
if (port < 1 || port > PG_UINT16_MAX)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

View File

@ -14,14 +14,16 @@ SET ROLE :ROLE_1;
-- Add data nodes using TimescaleDB data_node management API. NOTE that the
-- extension won't be created since it is installed in the template1
-- database
SELECT * FROM add_data_node('data_node_1', database => 'data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
@ -30,11 +32,20 @@ SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
\set ON_ERROR_STOP 0
-- Add again
SELECT * FROM add_data_node('data_node_2');
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
ERROR: server "data_node_2" already exists
-- Add NULL data_node
-- No host provided
SELECT * FROM add_data_node('data_node_99');
ERROR: function add_data_node(unknown) does not exist at character 15
SELECT * FROM add_data_node(NULL);
ERROR: function add_data_node(unknown) does not exist at character 15
-- Add NULL data_node
SELECT * FROM add_data_node(NULL, host => 'localhost');
ERROR: invalid data node name
SELECT * FROM add_data_node(NULL, NULL);
ERROR: a host needs to be specified
-- Adding a data node via ADD SERVER is blocked
CREATE SERVER data_node_4 FOREIGN DATA WRAPPER timescaledb_fdw
OPTIONS (host 'localhost', port '15432', dbname 'data_node_4');
@ -44,7 +55,7 @@ DROP SERVER data_node_1, data_node_2;
ERROR: operation not supported on a TimescaleDB data node
\set ON_ERROR_STOP 1
-- Should not generate error with if_not_exists option
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
if_not_exists => true);
NOTICE: data node "data_node_2" already exists, skipping
@ -54,9 +65,8 @@ NOTICE: database "data_node_2" already exists on data node, not creating it
data_node_2 | localhost | 15432 | data_node_2 | f | f | f
(1 row)
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
if_not_exists => true);
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_3 | localhost | 15432 | data_node_3 | t | t | t
@ -145,22 +155,21 @@ DROP DATABASE IF EXISTS data_node_2;
DROP DATABASE IF EXISTS data_node_3;
SET client_min_messages TO INFO;
SET ROLE :ROLE_1;
-- Add new data nodes
SELECT * FROM add_data_node('data_node_1', database => 'data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
@ -611,7 +620,7 @@ AND column_name = 'device';
device | 1
(1 row)
SELECT * FROM add_data_node('data_node_4', database => 'data_node_4',
SELECT * FROM add_data_node('data_node_4', host => 'localhost', database => 'data_node_4',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
if_not_exists => true);
node_name | host | port | database | node_created | database_created | extension_created
@ -690,7 +699,7 @@ NOTICE: adding not-null constraint to column "time"
ERROR: no data nodes can be assigned to "disttable"
\set ON_ERROR_STOP 1
DROP DATABASE IF EXISTS data_node_3;
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
@ -734,21 +743,21 @@ SELECT * FROM timescaledb_information.data_node;
(0 rows)
-- let's add some
SELECT * FROM add_data_node('data_node_1', database => 'data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
@ -1104,14 +1113,14 @@ WARNING: new data for hypertable "disttable" will be under-replicated due to de
(1 row)
-- Let's add more data nodes
SELECT * FROM add_data_node('data_node_4', database => 'data_node_4',
SELECT * FROM add_data_node('data_node_4', host => 'localhost', database => 'data_node_4',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
data_node_4 | localhost | 15432 | data_node_4 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_5', database => 'data_node_5',
SELECT * FROM add_data_node('data_node_5', host => 'localhost', database => 'data_node_5',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
@ -1202,7 +1211,7 @@ WARNING: new data for hypertable "disttable_4" will be under-replicated due to
-- Test case for missing pgpass user password
GRANT USAGE ON FOREIGN DATA WRAPPER timescaledb_fdw TO :ROLE_2;
SET ROLE :ROLE_2;
SELECT * FROM add_data_node('data_node_6', database => 'data_node_6',
SELECT * FROM add_data_node('data_node_6', host => 'localhost', database => 'data_node_6',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-------------+--------------+------------------+-------------------
@ -1216,6 +1225,11 @@ SELECT * FROM _timescaledb_internal.ping_data_node('data_node_6');
f
(1 row)
\set ON_ERROR_STOP 0
-- Should fail because host has to be provided.
SELECT * FROM add_data_node('data_node_7');
ERROR: function add_data_node(unknown) does not exist at character 15
\set ON_ERROR_STOP 1
RESET ROLE;
DROP DATABASE data_node_1;
DROP DATABASE data_node_2;

View File

@ -18,7 +18,7 @@ SET ROLE :ROLE_DEFAULT_PERM_USER;
-- bootstrap_user = :ROLE_DEFAULT_PERM_USER
-- bootstrap_database = 'postgres'
\set ON_ERROR_STOP 0
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
ERROR: [bootstrap_test]: permission denied to create database
\set ON_ERROR_STOP 1
SELECT * FROM show_data_nodes();
@ -31,7 +31,7 @@ SELECT * FROM show_data_nodes();
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
RESET ROLE;
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
node_name | host | port | database | node_created | database_created | extension_created
----------------+-----------+-------+----------------+--------------+------------------+-------------------
bootstrap_test | localhost | 15432 | bootstrap_test | t | t | t
@ -83,7 +83,8 @@ WHERE e.extnamespace = n.oid;
--
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => false);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => false);
NOTICE: database "bootstrap_test" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
----------------+-----------+-------+----------------+--------------+------------------+-------------------
@ -97,14 +98,16 @@ SELECT * FROM show_data_nodes();
(1 row)
\set ON_ERROR_STOP 0
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => false);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => false);
ERROR: server "bootstrap_test" already exists
\set ON_ERROR_STOP 1
-- Test if_not_exists functionality (no local server, but remote database and extension exists)
--
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => true);
NOTICE: data node "bootstrap_test" already exists, skipping
NOTICE: database "bootstrap_test" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
@ -142,7 +145,8 @@ WHERE e.extnamespace = n.oid;
(1 row)
\c :TEST_DBNAME :ROLE_SUPERUSER;
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => true);
NOTICE: data node "bootstrap_test" already exists, skipping
NOTICE: database "bootstrap_test" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
@ -185,7 +189,7 @@ WHERE e.extnamespace = n.oid;
timescaledb | bootstrap_schema
(2 rows)
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
node_name | host | port | database | node_created | database_created | extension_created
----------------+-----------+-------+----------------+--------------+------------------+-------------------
bootstrap_test | localhost | 15432 | bootstrap_test | t | t | t
@ -202,7 +206,8 @@ WHERE e.extnamespace = n.oid;
(2 rows)
\c bootstrap_schema_test :ROLE_SUPERUSER;
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => true);
NOTICE: data node "bootstrap_test" already exists, skipping
NOTICE: database "bootstrap_test" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
@ -218,7 +223,10 @@ SET ROLE :ROLE_1;
--
-- bootstrap_user = :ROLE_CLUSTER_SUPERUSER
-- bootstrap_database = 'template1'
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', bootstrap_user => :'ROLE_CLUSTER_SUPERUSER', bootstrap_database => 'template1');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
bootstrap_database => 'template1');
node_name | host | port | database | node_created | database_created | extension_created
----------------+-----------+-------+----------------+--------------+------------------+-------------------
bootstrap_test | localhost | 15432 | bootstrap_test | t | t | t
@ -244,7 +252,7 @@ SELECT * FROM delete_data_node('bootstrap_test');
-- Test for ongoing transaction
BEGIN;
\set ON_ERROR_STOP 0
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
ERROR: add_data_node cannot run inside a transaction block
\set ON_ERROR_STOP 1
COMMIT;
@ -258,13 +266,14 @@ DROP DATABASE bootstrap_test;
--
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
SELECT true FROM add_data_node('bootstrap_test1', database => 'Unusual Name');
SELECT true FROM add_data_node('bootstrap_test1', host => 'localhost', database => 'Unusual Name');
bool
------
t
(1 row)
SELECT true FROM add_data_node('bootstrap_test1', database => 'Unusual Name', if_not_exists => true);
SELECT true FROM add_data_node('bootstrap_test1', host => 'localhost',
database => 'Unusual Name', if_not_exists => true);
NOTICE: data node "bootstrap_test1" already exists, skipping
NOTICE: database "Unusual Name" already exists on data node, not creating it
bool
@ -272,13 +281,15 @@ NOTICE: database "Unusual Name" already exists on data node, not creating it
t
(1 row)
SELECT true FROM add_data_node('bootstrap_test2', database => U&'\0441\043B\043E\043D');
SELECT true FROM add_data_node('bootstrap_test2', host => 'localhost',
database => U&'\0441\043B\043E\043D');
bool
------
t
(1 row)
SELECT true FROM add_data_node('bootstrap_test2', database => U&'\0441\043B\043E\043D', if_not_exists => true);
SELECT true FROM add_data_node('bootstrap_test2', host => 'localhost',
database => U&'\0441\043B\043E\043D', if_not_exists => true);
NOTICE: data node "bootstrap_test2" already exists, skipping
NOTICE: database "слон" already exists on data node, not creating it
bool
@ -289,13 +300,13 @@ NOTICE: database "слон" already exists on data node, not creating it
-- Testing that the check for database privileges does not croak on a
-- strange database name. The check is executed when a database
-- already exists.
SELECT true FROM add_data_node('bootstrap_test3', database => 'dat''abase');
SELECT true FROM add_data_node('bootstrap_test3', host => 'localhost', database => 'dat''abase');
bool
------
t
(1 row)
SELECT true FROM add_data_node('bootstrap_test4', database => 'dat''abase');
SELECT true FROM add_data_node('bootstrap_test4', host => 'localhost', database => 'dat''abase');
NOTICE: database "dat'abase" already exists on data node, not creating it
bool
------

View File

@ -7,7 +7,7 @@
psql:include/remote_exec.sql:5: NOTICE: schema "test" already exists, skipping
psql:include/filter_exec.sql:5: NOTICE: schema "test" already exists, skipping
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -15,7 +15,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -23,7 +23,7 @@ SELECT * FROM add_data_node('data_node_2',
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -14,7 +14,7 @@ DROP DATABASE IF EXISTS data_node_2;
DROP DATABASE IF EXISTS data_node_3;
SET client_min_messages TO NOTICE;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -22,7 +22,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -30,7 +30,7 @@ SELECT * FROM add_data_node('data_node_2',
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -43,7 +43,7 @@ CREATE TABLE :TEST_TABLE (
good_life boolean
);
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -51,7 +51,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -59,7 +59,7 @@ SELECT * FROM add_data_node('data_node_2',
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -25,7 +25,7 @@ SET client_min_messages TO ERROR;
DROP DATABASE IF EXISTS data_node_1;
DROP DATABASE IF EXISTS data_node_2;
DROP DATABASE IF EXISTS data_node_3;
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -33,7 +33,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -41,7 +41,7 @@ SELECT * FROM add_data_node('data_node_2',
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -45,7 +45,7 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
uuid | 87c235e9-d857-4f16-b59f-7fbac9b87664 | t
(1 row)
SELECT * FROM add_data_node('data_node_1', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'backend_3', if_not_exists => true);
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-----------+--------------+------------------+-------------------
data_node_1 | localhost | 15432 | backend_3 | t | f | f
@ -68,7 +68,7 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
uuid | 77348176-09da-4a80-bc78-e31bdf5e63ec | t
(1 row)
SELECT * FROM add_data_node('data_node_1', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'backend_1', if_not_exists => true);
NOTICE: database "backend_1" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-----------+--------------+------------------+-------------------
@ -86,17 +86,17 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
-- Let's try some invalid configurations
\set ON_ERROR_STOP 0
-- Adding frontend as backend to a different frontend
SELECT * FROM add_data_node('frontend_b', database => 'frontend_b', if_not_exists => true);
SELECT * FROM add_data_node('frontend_b', host => 'localhost', database => 'frontend_b', if_not_exists => true);
NOTICE: database "frontend_b" already exists on data node, not creating it
ERROR: [frontend_b]: database is already a member of a distributed database
-- Adding backend from a different group as a backend
SELECT * FROM add_data_node('data_node_b', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_b', host => 'localhost', database => 'backend_3', if_not_exists => true);
NOTICE: database "backend_3" already exists on data node, not creating it
ERROR: [data_node_b]: database is already a member of a distributed database
-- Adding a valid backend target but to an existing backend
\c backend_1
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_2', database => 'backend_2', if_not_exists => true);
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'backend_2', if_not_exists => true);
ERROR: unable to assign data nodes from an existing distributed database
\c backend_2
GRANT USAGE ON FOREIGN DATA WRAPPER timescaledb_fdw TO :ROLE_1;
@ -107,7 +107,7 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
(0 rows)
-- Adding a frontend as a backend to a nondistributed node
SELECT * FROM add_data_node('frontend_b', database => 'frontend_b', if_not_exists => true);
SELECT * FROM add_data_node('frontend_b', host => 'localhost', database => 'frontend_b', if_not_exists => true);
NOTICE: database "frontend_b" already exists on data node, not creating it
ERROR: [frontend_b]: database is already a member of a distributed database
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
@ -126,7 +126,7 @@ END
$BODY$;
\c :TEST_DBNAME :ROLE_SUPERUSER;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('invalid_data_node', database => 'backend_2', if_not_exists => true);
SELECT * FROM add_data_node('invalid_data_node', host => 'localhost', database => 'backend_2', if_not_exists => true);
NOTICE: database "backend_2" already exists on data node, not creating it
ERROR: could not add data node invalid_data_node
-- Restore original validation function
@ -137,7 +137,7 @@ AS :MODULE_PATHNAME, 'ts_dist_validate_as_data_node' LANGUAGE C VOLATILE STRICT;
-- Add a second backend to TEST_DB
\c :TEST_DBNAME :ROLE_SUPERUSER;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_2', database => 'backend_2', if_not_exists => true);
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'backend_2', if_not_exists => true);
NOTICE: database "backend_2" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-----------+--------------+------------------+-------------------
@ -187,7 +187,7 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
dist_uuid | 87c235e9-d857-4f16-b59f-7fbac9b87664 | t
(2 rows)
SELECT * FROM add_data_node('data_node_2', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'backend_1', if_not_exists => true);
NOTICE: database "backend_1" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-----------+--------------+------------------+-------------------
@ -225,21 +225,21 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
\c :TEST_DBNAME :ROLE_SUPERUSER;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_1', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'backend_1', if_not_exists => true);
NOTICE: database "backend_1" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-----------+--------------+------------------+-------------------
data_node_1 | localhost | 15432 | backend_1 | t | f | f
(1 row)
SELECT * FROM add_data_node('data_node_3', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'backend_3', if_not_exists => true);
NOTICE: database "backend_3" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+-----------+--------------+------------------+-------------------
data_node_3 | localhost | 15432 | backend_3 | t | f | f
(1 row)
SELECT * FROM add_data_node('data_node_4', database => 'frontend_b', if_not_exists => true);
SELECT * FROM add_data_node('data_node_4', host => 'localhost', database => 'frontend_b', if_not_exists => true);
NOTICE: database "frontend_b" already exists on data node, not creating it
node_name | host | port | database | node_created | database_created | extension_created
-------------+-----------+-------+------------+--------------+------------------+-------------------

View File

@ -25,7 +25,7 @@ DROP DATABASE IF EXISTS data_node_2;
DROP DATABASE IF EXISTS data_node_3;
SET client_min_messages TO NOTICE;
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -33,7 +33,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -41,7 +41,7 @@ SELECT * FROM add_data_node('data_node_2',
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -34,7 +34,7 @@ OPTIONS (user :'ROLE_3', password :'ROLE_3_PASS');
CREATE USER MAPPING IF NOT EXISTS FOR :ROLE_3 server server_pg2
OPTIONS (user :'ROLE_3', password :'ROLE_3_PASS');
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -42,7 +42,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -12,10 +12,10 @@ AS :TSL_MODULE_PATHNAME, 'tsl_test_alter_data_node'
LANGUAGE C STRICT;
DO $d$
BEGIN
EXECUTE $$SELECT add_data_node('loopback_1',
EXECUTE $$SELECT add_data_node('loopback_1', host => 'localhost',
database => 'loopback_1',
port => current_setting('port')::int)$$;
EXECUTE $$SELECT add_data_node('loopback_2',
EXECUTE $$SELECT add_data_node('loopback_2', host => 'localhost',
database => 'loopback_2',
port => current_setting('port')::int)$$;
END;

View File

@ -10,7 +10,7 @@ DROP DATABASE IF EXISTS data_node_3;
SET client_min_messages TO NOTICE;
SET ROLE :ROLE_1;
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -18,7 +18,7 @@ SELECT * FROM add_data_node('data_node_1',
data_node_1 | localhost | 15432 | data_node_1 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created
@ -26,7 +26,7 @@ SELECT * FROM add_data_node('data_node_2',
data_node_2 | localhost | 15432 | data_node_2 | t | t | t
(1 row)
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
node_name | host | port | database | node_created | database_created | extension_created

View File

@ -21,16 +21,24 @@ SET ROLE :ROLE_1;
-- Add data nodes using TimescaleDB data_node management API. NOTE that the
-- extension won't be created since it is installed in the template1
-- database
SELECT * FROM add_data_node('data_node_1', database => 'data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
\set ON_ERROR_STOP 0
-- Add again
SELECT * FROM add_data_node('data_node_2');
-- Add NULL data_node
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
-- No host provided
SELECT * FROM add_data_node('data_node_99');
SELECT * FROM add_data_node(NULL);
-- Add NULL data_node
SELECT * FROM add_data_node(NULL, host => 'localhost');
SELECT * FROM add_data_node(NULL, NULL);
-- Adding a data node via ADD SERVER is blocked
CREATE SERVER data_node_4 FOREIGN DATA WRAPPER timescaledb_fdw
OPTIONS (host 'localhost', port '15432', dbname 'data_node_4');
@ -39,13 +47,13 @@ DROP SERVER data_node_1, data_node_2;
\set ON_ERROR_STOP 1
-- Should not generate error with if_not_exists option
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
if_not_exists => true);
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
if_not_exists => true);
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
-- Test altering server command is blocked
\set ON_ERROR_STOP 0
@ -90,12 +98,11 @@ DROP DATABASE IF EXISTS data_node_3;
SET client_min_messages TO INFO;
SET ROLE :ROLE_1;
-- Add new data nodes
SELECT * FROM add_data_node('data_node_1', database => 'data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM timescaledb_information.data_node;
@ -299,7 +306,7 @@ FROM _timescaledb_catalog.dimension
WHERE num_slices IS NOT NULL
AND column_name = 'device';
SELECT * FROM add_data_node('data_node_4', database => 'data_node_4',
SELECT * FROM add_data_node('data_node_4', host => 'localhost', database => 'data_node_4',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
if_not_exists => true);
SELECT * FROM attach_data_node('data_node_4', 'disttable');
@ -336,7 +343,7 @@ SELECT * FROM create_distributed_hypertable('disttable', 'time');
\set ON_ERROR_STOP 1
DROP DATABASE IF EXISTS data_node_3;
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
-- These data nodes have been deleted, so safe to remove their databases.
@ -363,11 +370,11 @@ SELECT delete_data_node('data_node_3', force => true);
SELECT * FROM timescaledb_information.data_node;
-- let's add some
SELECT * FROM add_data_node('data_node_1', database => 'data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2', database => 'data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3', database => 'data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
DROP TABLE disttable;
@ -509,9 +516,9 @@ ORDER BY foreign_table_name;
SELECT * FROM detach_data_node('data_node_2', 'disttable', true);
-- Let's add more data nodes
SELECT * FROM add_data_node('data_node_4', database => 'data_node_4',
SELECT * FROM add_data_node('data_node_4', host => 'localhost', database => 'data_node_4',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_5', database => 'data_node_5',
SELECT * FROM add_data_node('data_node_5', host => 'localhost', database => 'data_node_5',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SET ROLE :ROLE_CLUSTER_SUPERUSER;
-- Create table as super user
@ -553,11 +560,16 @@ SELECT * FROM delete_data_node('data_node_5', force =>true);
-- Test case for missing pgpass user password
GRANT USAGE ON FOREIGN DATA WRAPPER timescaledb_fdw TO :ROLE_2;
SET ROLE :ROLE_2;
SELECT * FROM add_data_node('data_node_6', database => 'data_node_6',
SELECT * FROM add_data_node('data_node_6', host => 'localhost', database => 'data_node_6',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
-- Must return false
SELECT * FROM _timescaledb_internal.ping_data_node('data_node_6');
\set ON_ERROR_STOP 0
-- Should fail because host has to be provided.
SELECT * FROM add_data_node('data_node_7');
\set ON_ERROR_STOP 1
RESET ROLE;
DROP DATABASE data_node_1;

View File

@ -23,7 +23,7 @@ SET ROLE :ROLE_DEFAULT_PERM_USER;
-- bootstrap_user = :ROLE_DEFAULT_PERM_USER
-- bootstrap_database = 'postgres'
\set ON_ERROR_STOP 0
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
\set ON_ERROR_STOP 1
SELECT * FROM show_data_nodes();
@ -32,7 +32,7 @@ SELECT * FROM show_data_nodes();
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
RESET ROLE;
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
SET ROLE :ROLE_DEFAULT_PERM_USER;
SELECT * FROM show_data_nodes();
@ -56,17 +56,20 @@ WHERE e.extnamespace = n.oid;
--
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => false);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => false);
SELECT * FROM show_data_nodes();
\set ON_ERROR_STOP 0
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => false);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => false);
\set ON_ERROR_STOP 1
-- Test if_not_exists functionality (no local server, but remote database and extension exists)
--
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM show_data_nodes();
-- Test if_not_exists functionality (has local server, has database database but no extension installed)
@ -85,7 +88,8 @@ FROM pg_extension e, pg_namespace n
WHERE e.extnamespace = n.oid;
\c :TEST_DBNAME :ROLE_SUPERUSER;
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => true);
\c bootstrap_test :ROLE_SUPERUSER;
SELECT extname, nspname
@ -106,11 +110,13 @@ SET client_min_messages TO error;
CREATE EXTENSION timescaledb WITH SCHEMA bootstrap_schema;
SET client_min_messages TO NOTICE;
SELECT extname, nspname
FROM pg_extension e, pg_namespace n
WHERE e.extnamespace = n.oid;
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
\c bootstrap_test :ROLE_SUPERUSER;
SELECT extname, nspname
@ -118,7 +124,8 @@ FROM pg_extension e, pg_namespace n
WHERE e.extnamespace = n.oid;
\c bootstrap_schema_test :ROLE_SUPERUSER;
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', database => 'bootstrap_test', if_not_exists => true);
SELECT * FROM bootstrap_schema.add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test', if_not_exists => true);
\c :TEST_DBNAME :ROLE_SUPERUSER;
DROP DATABASE bootstrap_schema_test;
DROP DATABASE bootstrap_test;
@ -128,7 +135,10 @@ SET ROLE :ROLE_1;
--
-- bootstrap_user = :ROLE_CLUSTER_SUPERUSER
-- bootstrap_database = 'template1'
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test', bootstrap_user => :'ROLE_CLUSTER_SUPERUSER', bootstrap_database => 'template1');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost',
database => 'bootstrap_test',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
bootstrap_database => 'template1');
\c bootstrap_test :ROLE_DEFAULT_PERM_USER;
SELECT extname, nspname
@ -141,7 +151,7 @@ SELECT * FROM delete_data_node('bootstrap_test');
-- Test for ongoing transaction
BEGIN;
\set ON_ERROR_STOP 0
SELECT * FROM add_data_node('bootstrap_test', database => 'bootstrap_test');
SELECT * FROM add_data_node('bootstrap_test', host => 'localhost', database => 'bootstrap_test');
\set ON_ERROR_STOP 1
COMMIT;
SELECT * FROM show_data_nodes();
@ -152,17 +162,20 @@ DROP DATABASE bootstrap_test;
--
-- bootstrap_user = :ROLE_SUPERUSER
-- bootstrap_database = 'postgres'
SELECT true FROM add_data_node('bootstrap_test1', database => 'Unusual Name');
SELECT true FROM add_data_node('bootstrap_test1', database => 'Unusual Name', if_not_exists => true);
SELECT true FROM add_data_node('bootstrap_test1', host => 'localhost', database => 'Unusual Name');
SELECT true FROM add_data_node('bootstrap_test1', host => 'localhost',
database => 'Unusual Name', if_not_exists => true);
SELECT true FROM add_data_node('bootstrap_test2', database => U&'\0441\043B\043E\043D');
SELECT true FROM add_data_node('bootstrap_test2', database => U&'\0441\043B\043E\043D', if_not_exists => true);
SELECT true FROM add_data_node('bootstrap_test2', host => 'localhost',
database => U&'\0441\043B\043E\043D');
SELECT true FROM add_data_node('bootstrap_test2', host => 'localhost',
database => U&'\0441\043B\043E\043D', if_not_exists => true);
-- Testing that the check for database privileges does not croak on a
-- strange database name. The check is executed when a database
-- already exists.
SELECT true FROM add_data_node('bootstrap_test3', database => 'dat''abase');
SELECT true FROM add_data_node('bootstrap_test4', database => 'dat''abase');
SELECT true FROM add_data_node('bootstrap_test3', host => 'localhost', database => 'dat''abase');
SELECT true FROM add_data_node('bootstrap_test4', host => 'localhost', database => 'dat''abase');
SELECT count(*) FROM show_data_nodes();
SELECT true FROM pg_database WHERE datname = 'Unusual Name';

View File

@ -14,13 +14,13 @@
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');

View File

@ -22,13 +22,13 @@ SET client_min_messages TO NOTICE;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');

View File

@ -18,13 +18,13 @@ SET client_min_messages TO NOTICE;
\ir 'include/aggregate_table_create.sql'
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');

View File

@ -45,7 +45,7 @@ GRANT ALL ON _timescaledb_catalog.metadata TO :ROLE_1;
SET ROLE :ROLE_1;
INSERT INTO _timescaledb_catalog.metadata VALUES ('uuid', '87c235e9-d857-4f16-b59f-7fbac9b87664', true) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'dist_uuid';
SELECT * FROM add_data_node('data_node_1', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'backend_3', if_not_exists => true);
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'dist_uuid';
-- Connect back to our original database and add a backend to it
@ -53,29 +53,29 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
SET ROLE :ROLE_1;
INSERT INTO _timescaledb_catalog.metadata VALUES ('uuid', '77348176-09da-4a80-bc78-e31bdf5e63ec', true) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'dist_uuid';
SELECT * FROM add_data_node('data_node_1', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'backend_1', if_not_exists => true);
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'dist_uuid';
-- We now have two frontends with one backend each and one undistributed database
-- Let's try some invalid configurations
\set ON_ERROR_STOP 0
-- Adding frontend as backend to a different frontend
SELECT * FROM add_data_node('frontend_b', database => 'frontend_b', if_not_exists => true);
SELECT * FROM add_data_node('frontend_b', host => 'localhost', database => 'frontend_b', if_not_exists => true);
-- Adding backend from a different group as a backend
SELECT * FROM add_data_node('data_node_b', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_b', host => 'localhost', database => 'backend_3', if_not_exists => true);
-- Adding a valid backend target but to an existing backend
\c backend_1
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_2', database => 'backend_2', if_not_exists => true);
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'backend_2', if_not_exists => true);
\c backend_2
GRANT USAGE ON FOREIGN DATA WRAPPER timescaledb_fdw TO :ROLE_1;
SET ROLE :ROLE_1;
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
-- Adding a frontend as a backend to a nondistributed node
SELECT * FROM add_data_node('frontend_b', database => 'frontend_b', if_not_exists => true);
SELECT * FROM add_data_node('frontend_b', host => 'localhost', database => 'frontend_b', if_not_exists => true);
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
-- Mocking a data node validation failure
@ -90,7 +90,7 @@ $BODY$;
\c :TEST_DBNAME :ROLE_SUPERUSER;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('invalid_data_node', database => 'backend_2', if_not_exists => true);
SELECT * FROM add_data_node('invalid_data_node', host => 'localhost', database => 'backend_2', if_not_exists => true);
-- Restore original validation function
\c backend_2
@ -101,7 +101,7 @@ AS :MODULE_PATHNAME, 'ts_dist_validate_as_data_node' LANGUAGE C VOLATILE STRICT;
-- Add a second backend to TEST_DB
\c :TEST_DBNAME :ROLE_SUPERUSER;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_2', database => 'backend_2', if_not_exists => true);
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'backend_2', if_not_exists => true);
\c backend_2
SET ROLE :ROLE_1;
@ -122,7 +122,7 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
\c frontend_b
SET ROLE :ROLE_1;
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'dist_uuid';
SELECT * FROM add_data_node('data_node_2', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_2', host => 'localhost', database => 'backend_1', if_not_exists => true);
\c backend_1
SET ROLE :ROLE_1;
SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
@ -136,9 +136,9 @@ SELECT * FROM _timescaledb_catalog.metadata WHERE key LIKE 'uuid' OR key LIKE 'd
\c :TEST_DBNAME :ROLE_SUPERUSER;
SET ROLE :ROLE_1;
SELECT * FROM add_data_node('data_node_1', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_3', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_4', database => 'frontend_b', if_not_exists => true);
SELECT * FROM add_data_node('data_node_1', host => 'localhost', database => 'backend_1', if_not_exists => true);
SELECT * FROM add_data_node('data_node_3', host => 'localhost', database => 'backend_3', if_not_exists => true);
SELECT * FROM add_data_node('data_node_4', host => 'localhost', database => 'frontend_b', if_not_exists => true);
\c frontend_b
SET ROLE :ROLE_1;

View File

@ -23,13 +23,13 @@ DROP DATABASE IF EXISTS data_node_3;
SET client_min_messages TO NOTICE;
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');

View File

@ -8,13 +8,13 @@ DROP DATABASE IF EXISTS data_node_1;
DROP DATABASE IF EXISTS data_node_2;
DROP DATABASE IF EXISTS data_node_3;
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');

View File

@ -30,10 +30,10 @@ CREATE USER MAPPING IF NOT EXISTS FOR :ROLE_3 server server_pg2
OPTIONS (user :'ROLE_3', password :'ROLE_3_PASS');
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');

View File

@ -16,10 +16,10 @@ LANGUAGE C STRICT;
DO $d$
BEGIN
EXECUTE $$SELECT add_data_node('loopback_1',
EXECUTE $$SELECT add_data_node('loopback_1', host => 'localhost',
database => 'loopback_1',
port => current_setting('port')::int)$$;
EXECUTE $$SELECT add_data_node('loopback_2',
EXECUTE $$SELECT add_data_node('loopback_2', host => 'localhost',
database => 'loopback_2',
port => current_setting('port')::int)$$;
END;

View File

@ -14,13 +14,13 @@ SET client_min_messages TO NOTICE;
SET ROLE :ROLE_1;
-- Add data nodes using the TimescaleDB node management API
SELECT * FROM add_data_node('data_node_1',
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
database => 'data_node_1',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_2',
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
database => 'data_node_2',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');
SELECT * FROM add_data_node('data_node_3',
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
database => 'data_node_3',
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER');