外连postgre
可以配置“外部表”的方式在gp中直接访问pg表,有2种方式:(gp自带)
- dblink方式:
SELECT dblink_connect('pg207','host=192.168.200.207 port=5432 dbname=mdmaster_tenant_instance user=leyishang_dev password=密码');
SELECT * FROM dblink('pg207', 'SELECT brand_code from tenant_1000000457_rst.dim_class_longtype') AS dbltab(brand_code text);
小郁闷:dblink_connect的名称不知道怎么保存,select是临时查询的。
- fdw方式:
create server fdw_pg207
foreign data wrapper postgres_fdw options(host '192.168.200.207',port '5432',dbname 'mdmaster_tenant_instance')
;
create user mapping for gpadmin server fdw_pg207 options(user 'leyishang_dev',password '密码');
;
create foreign table testdb.rst_ra_extra_allot_detail
(
brand_code varchar
)server fdw_pg207 options (schema_name 'tenant_1000000457_rst',table_name 'rst_ra_extra_allot_detail')
;
select count(*) from testdb.rst_ra_extra_allot_detail
;