ADB to ADB Connector usage examples
This article describes how to transfer data between two ADB clusters via ADB to ADB Connector. The following prerequisites are met:
-
The local ADB cluster is installed according to the Online installation guide.
-
The remote ADB cluster is installed according to the Online installation guide. Master host is called
bds-mdw-ext. -
The
adbdatabase exists in both clusters. -
The
adb_to_adbuser with password123exists in the remote cluster. -
The
adb_to_adbuser can access the remoteadbdatabase from the local cluster. For this purpose, change the pg_hba.conf file according to the ADB to ADB connector configuration article:host all adb_to_adb 10.92.17.84/32 passwordwhere
10.92.17.84/32is IP address of the master host in the local ADB cluster (with a subnet number). -
ADB to ADB Connector is installed in the local and remote clusters according to the ADB to ADB connector installation guide.
Select data
To check that the remote ADB cluster data can be read from the local cluster, follow the steps:
-
Connect to the
adbdatabase in the remote ADB cluster under thegpadminuser (for example, viapsql). Create theauthortable:CREATE TABLE author(id INT NOT NULL, name TEXT NOT NULL) WITH (appendoptimized=true) DISTRIBUTED BY(id); -
Insert some data into the
authortable (on the remote cluster side):INSERT INTO author(id, name) VALUES (1,'Virginia Woolf'), (2,'J.R.R. Tolkien'), (3,'Harper Lee'), (4,'J.D. Salinger'), (5,'George Orwell'), (6,'John Steinbeck'), (7,'Margaret Mitchell'), (8,'Alan Moore'), (9,'Jack Kerouac'), (10,'Ernest Hemingway'); -
Grant necessary permissions on the new table
authorto theadb_to_adbuser (on the remote cluster side):GRANT SELECT, INSERT ON public.author TO adb_to_adb; -
Connect to the
adbdatabase in the local ADB cluster under thegpadminuser (for example, viapsql). Create the following objects in the given order.-
The
test_serverserver:CREATE SERVER test_server FOREIGN DATA WRAPPER adb_fdw OPTIONS ( host 'bds-mdw-ext', port '5432', dbname 'adb', use_remote_estimate 'true'); -
The user mapping for the
gpadminuser:CREATE USER MAPPING FOR gpadmin SERVER test_server OPTIONS (user 'adb_to_adb', password '123'); -
The
test_tableforeign table:CREATE FOREIGN TABLE test_table (id INT, name TEXT) SERVER test_server OPTIONS (table_name 'author');
-
-
Select data from the
test_table. Ensure that the data added on the remote cluster side is available in the local cluster:SELECT * FROM test_table ORDER BY id;Result:
id | name ----+------------------- 1 | Virginia Woolf 2 | J.R.R. Tolkien 3 | Harper Lee 4 | J.D. Salinger 5 | George Orwell 6 | John Steinbeck 7 | Margaret Mitchell 8 | Alan Moore 9 | Jack Kerouac 10 | Ernest Hemingway (10 rows)
Insert data
To check that you can add data to the remote ADB database from the local cluster, follow the steps:
-
Perform steps 1—4 that are listed above (if you have not passed them yet).
-
Connect to the
adbdatabase in the local ADB cluster under thegpadminuser (for example, viapsql). Add some data to thetest_tableforeign table:INSERT INTO test_table(id, name) VALUES (11, 'Fyodor Dostoevsky'), (12, 'Alexander Pushkin'), (13, 'Mikhail Bulgakov'); -
Connect to the
adbdatabase in the remote ADB cluster under thegpadminuser (for example, viapsql). Check the presence of new tuples in theauthortable:SELECT * FROM author ORDER BY id;The result contains new data received from the source ADB cluster:
id | name ----+------------------- 1 | Virginia Woolf 2 | J.R.R. Tolkien 3 | Harper Lee 4 | J.D. Salinger 5 | George Orwell 6 | John Steinbeck 7 | Margaret Mitchell 8 | Alan Moore 9 | Jack Kerouac 10 | Ernest Hemingway 11 | Fyodor Dostoevsky 12 | Alexander Pushkin 13 | Mikhail Bulgakov (13 rows)