400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
YMatrix 文档
关于 YMatrix
标准集群部署
数据写入
数据迁移
数据查询
运维监控
参考指南
工具指南
数据类型
存储引擎
执行引擎
流计算引擎
灾难恢复
系统配置参数
索引
扩展
SQL 参考
常见问题(FAQ)
PostgreSQL 环境:
Host: 127.0.0.1
Port: 5432
User: pg
Database: postgres
现在,创建一张测试表:
postgres=# CREATE TABLE test(c1 int, c2 int);
CREATE TABLE
然后,插入几条测试数据:
postgres=# INSERT INTO test VALUES(0,0),(1,1),(2,2);
INSERT 0 3
下面登录 YMatrix,使用 postgres_fdw 连接刚才创建的 PostgreSQL 数据表:
首先,创建 postgres_fdw 扩展:
mxadmin=# CREATE EXTENSION postgres_fdw;
CREATE EXTENSION
创建 PostgreSQL 服务器定义:
mxadmin=# CREATE SERVER server_pg FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '127.0.0.1', port '5432', dbname 'postgres');
CREATE SERVER
创建用户映射:
mxadmin=# CREATE USER MAPPING FOR mxadmin SERVER server_pg OPTIONS (user 'pg');
CREATE USER MAPPING
创建外部表:
mxadmin=# CREATE FOREIGN TABLE ext_pg (c1 int, c2 int) SERVER server_pg OPTIONS (table_name 'test');
CREATE FOREIGN TABLE
外部表创建成功后,下面就可以通过直接读写外部表来实现对 PostgreSQL 中的 test 表的操作。
通过如下查询可以看到,外部表数据和原表相同:
mxadmin=# SELECT * FROM ext_pg;
c1 | c2
----+----
0 | 0
1 | 1
2 | 2
(3 rows)
向外部表插入数据:
mxadmin=# INSERT INTO ext_pg VALUES(3,3);
INSERT 0 1
插入数据后,连接 PostgreSQL 查看数据:
postgres=# SELECT * FROM test;
c1 | c2
----+----
0 | 0
1 | 1
2 | 2
3 | 3
(4 rows)
可以看到,数据已经写入到了 PostgreSQL 的 test 表中。