YMatrix 文档
集群部署
SQL参考
- ABORT
- ALTER_DATABASE
- ALTER_EXTENSION
- ALTER_EXTERNAL_TABLE
- ALTER_FOREIGN_DATA_WRAPPER
- ALTER_FOREIGN_TABLE
- ALTER_FUNCTION
- ALTER_INDEX
- ALTER_RESOURCE_GROUP
- ALTER_RESOURCE_QUEUE
- ALTER_ROLE
- ALTER_RULE
- ALTER_SCHEMA
- ALTER_SEQUENCE
- ALTER_SERVER
- ALTER_TABLE
- ALTER_TABLESPACE
- ALTER_TYPE
- ALTER_USER_MAPPING
- ALTER_VIEW
- ANALYZE
- BEGIN
- CHECKPOINT
- COMMIT
- COPY
- CREATE_DATABASE
- CREATE_EXTENSION
- CREATE_EXTERNAL_TABLE
- CREATE_FOREIGN_DATA_WRAPPER
- CREATE_FOREIGN_TABLE
- CREATE_FUNCTION
- CREATE_INDEX
- CREATE_RESOURCE_GROUP
- CREATE_RESOURCE_QUEUE
- CREATE_ROLE
- CREATE_RULE
- CREATE_SCHEMA
- CREATE_SEQUENCE
- CREATE_SERVER
- CREATE_TABLE
- CREATE_TABLE_AS
- CREATE_TABLESPACE
- CREATE_TYPE
- CREATE_USER_MAPPING
- CREATE_VIEW
- DELETE
- DROP_DATABASE
- DROP_EXTENSION
- DROP_EXTERNAL_TABLE
- DROP_FOREIGN_DATA_WRAPPER
- DROP_FOREIGN_TABLE
- DROP_FUNCTION
- DROP_INDEX
- DROP_RESOURCE_GROUP
- DROP_RESOURCE_QUEUE
- DROP_ROLE
- DROP_RULE
- DROP_SCHEMA
- DROP_SEQUENCE
- DROP_SERVER
- DROP_TABLE
- DROP_TABLESPACE
- DROP_TYPE
- DROP_USER_MAPPING
- DROP_VIEW
- END
- EXPLAIN
- GRANT
- INSERT
- LOAD
- LOCK
- REINDEX
- RELEASE_SAVEPOINT
- RESET
- REVOKE
- ROLLBACK_TO_SAVEPOINT
- ROLLBACK
- SAVEPOINT
- SELECT INTO
- SET ROLE
- SET TRANSACTION
- SET
- SHOW
- START TRANSACTION
- TRUNCATE
- UPDATE
- VACUUM
工具指南
FDW for PostgreSQL
1. 准备PostgreSQL环境
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
2. 在MatrixDB中创建FDW
下面登录MatrixDB,使用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
3. 使用postgres_fdw读写数据表
外部表创建成功后,下面就可以通过直接读写外部表来实现对PostgreSQL中的test表的操作。
3.1 查询数据
通过如下查询可以看到,外部表数据和原表相同:
mxadmin=# select * from ext_pg;
c1 | c2
----+----
0 | 0
1 | 1
2 | 2
(3 rows)
3.2 写入数据
向外部表插入数据:
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表中。