首页 > 数据库 > > 跨集群访问其他数据平台-配置访问远端MPPDB
当GaussDB 200需要访问远端MPPDB数据库数据时或者需要数据互操作时,可以通过配置"对接MPPDB"使用该功能。
说明:GaussDB 200支持两种方式访问远端MPPDB数据库集群,包括通过FusionInsight Manager配置方式和创建Foreign Table的方式,Foreign Table的方式请参见配置访问远端MPPDB(Foreign Table方式)。
支持最多可配置20组远端MPPDB配置。
参数 | 描述 | 建议填写值 |
|---|---|---|
remote_connect_mppdb_database | MPPDB数据库的名称。 | - |
remote_connect_mppdb_driver | mppdb odbc driver名称,用户可以根据实际情况自定义名称,以mppdb_开头,只允许由字母数字下划线组成,不能超过64个字符。 注意:
| mppdb_Driver |
remote_connect_mppdb_dsn | 该组配置的DSN标识,以mppdb_开头,只允许由字母数字下划线组成,不能超过64个字符。 注意:
| mppdb_DSN |
remote_connect_mppdb_fetch | 使用服务器游标时,每次从远端拿到的数据量。 注意:
| 10000 |
remote_connect_mppdb_host | MPPDB数据库的主机IP地址。 | - |
remote_connect_mppdb_port | MPPDB数据库的端口号。 | 25308 |
remote_connect_mppdb_sslmode | 开启SSL模式。 | allow |
postgres=# CREATE DATA SOURCE ds_mppdb type 'MPPDB' OPTIONS (DSN 'mppdb_DSN', USERNAME 'mppdb_user', PASSWORD 'mppdb_pwd', ENCODING 'UTF8');假设Data Source对象ds_mppdb已经创建好,使用exec_on_extension函数进行连接,比如查询远端MPPDB数据库中一张表a (c1 int):
postgres=# SELECT * FROM exec_on_extension('ds_mppdb', 'select * from a;') AS (c1 int);示例
-- 创建Data Source
postgres=# CREATE DATA SOURCE ds_mppdb OPTIONS (dsn 'mppdb_DSN', username 'mppdb_user', password 'mppdb_pwd',ENCODING 'UTF8');
-- 建远程表、插入数据
postgres=# SELECT * FROM exec_on_extension('ds_mppdb', 'create table a (c1 int);') AS (c1 text);
c1
----
( rows)
postgres=# SELECT * FROM exec_on_extension('ds_mppdb', 'insert into a values (911);') AS (c1 text);
c1
----
( rows)
-- 执行计划,如果计划在目标库是多列显示则此处需要以对应的列数返回
-- 此处远端MPPDB数据库中参数 explain_perf_mode=normal
postgres=# SELECT * FROM exec_on_extension('ds_mppdb', 'explain select * from a;') AS (c1 text);
QUERY PLAN
--------------------------------------------------
Data Node Scan (cost=.00..0.00 rows= width=)
Node/s: All datanodes
(2 rows)
postgres=# SELECT * FROM exec_on_extension('ds_mppdb', 'select * from a;') AS (c1 int);
c1
-----
911
(1 row)
-- 此处发送的SQL语句返回两列,但函数exec_on_extension只返回一列,注意靠前匹配原则
postgres=# SELECT * FROM exec_on_extension('ds_mppdb', 'select * from a a1 inner join a a2 on a1.c1=a2.c1;') AS (c1 int);
c1
-----
911
911
(2 rows)
-- 与本地表关联
postgres=# CREATE TABLE b AS SELECT * FROM exec_on_extension('ds_mppdb', 'select * from a;') AS (c1 int);
NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using 'c1' as the distribution column by default.
HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
INSERT 1
postgres=# INSERT INTO b SELECT * FROM exec_on_extension('ds_mppdb', 'select * from a;') AS (c1 int);
INSERT 1
postgres=# SELECT * FROM b WHERE b.c1 in (SELECT * FROM exec_on_extension('ds_mppdb', 'select * from a;') AS (c1 int));
c1
-----
911
911
(2 rows)来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3127184/ ,如需转载,请注明出处,否则将追究法律责任。