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)
本文档介绍了 PXF 访问 S3 的方式,并给出示例。
Platform Extension Framework(PXF)使用 Foreign Data Wrapper(FDW)的机制访问存储在 YMatrix 数据库外部源中的数据。有关 PXF 的详细介绍可以参考 PXF 中文文档。
在 Master 上,使用 mxadmin 用户编辑 PXF 访问 S3 服务的配置文件 s3-site.xml
,路径为 /usr/local/pxfconf/servers/s3server_online/s3-site.xml
。
$ vim /usr/local/pxfconf/servers/s3server_online/s3-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property>
<name>fs.s3a.endpoint</name>
<value>http:xxx</value>
</property>
<property>
<name>fs.s3a.access.key</name>
<value>xxx</value>
</property>
<property>
<name>fs.s3a.secret.key</name>
<value>xxx</value>
</property>
<property>
<name>fs.s3a.fast.upload</name>
<value>true</value>
</property>
</configuration>
参数说明:
注意!
此部分步骤均需在 Master 上使用 mxadmin 用户执行。
同步 PXF 配置文件到集群所有节点上。
$ pxf cluster sync
如下,说明 PXF 配置文件已经同步成功。
Syncing PXF configuration files from master host to 2 segment hosts...
PXF configs synced successfully on 2 out of 2 hosts
注意!
需要查看其它节点对应目录,检查其配置文件是否同步成功。
重启 PXF 服务。
$ pxf cluster restart
如下,说明 PXF 重启成功。
Restarting PXF on 2 segment hosts...
PXF restarted successfully on 2 out of 2 hosts
PXF 实例需要单独重新启动。
$ pxf restart
如下,说明 PXF 实例重启成功。
Using CATALINA_BASE: /usr/local/pxf-matrixdb4/pxf-service
Using CATALINA_HOME: /usr/local/pxf-matrixdb4/pxf-service
Using CATALINA_TMPDIR: /usr/local/pxf-matrixdb4/pxf-service/temp
Using JRE_HOME: /usr/local/jdk1805/jre
Using CLASSPATH: /usr/local/pxf-matrixdb4/pxf-service/bin/bootstrap.jar:/usr/local/pxf-matrixdb4/pxf-service/bin/tomcat-juli.jar
Using CATALINA_PID: /usr/local/pxf-matrixdb4/run/catalina.pid
Tomcat stopped.
Using CATALINA_BASE: /usr/local/pxf-matrixdb4/pxf-service
Using CATALINA_HOME: /usr/local/pxf-matrixdb4/pxf-service
Using CATALINA_TMPDIR: /usr/local/pxf-matrixdb4/pxf-service/temp
Using JRE_HOME: /usr/local/jdk1805/jre
Using CLASSPATH: /usr/local/pxf-matrixdb4/pxf-service/bin/bootstrap.jar:/usr/local/pxf-matrixdb4/pxf-service/bin/tomcat-juli.jar
Using CATALINA_PID: /usr/local/pxf-matrixdb4/run/catalina.pid
Tomcat started.
Checking if tomcat is up and running...
Server: PXF Server
Checking if PXF webapp is up and running...
PXF webapp is listening on port 5888
在 Master 上使用 mxadmin 用户连接 psql 客户端进入数据库。
$ psql <databasename>
创建 pxf_fdw
扩展。
注意!
YMatrix 创建扩展需要用户具有超级用户权限。
=# CREATE EXTENSION pxf_fdw;
在此给出两种创建方式,任选其一即可。
config
需要和上文创建的文件夹 s3server_online
相对应。=# CREATE SERVER s3server_online FOREIGN DATA WRAPPER s3_pxf_fdw OPTIONS(config 's3server_online');
注意!
执行 GRANT 命令需要用户具有超级用户权限。
=# GRANT usage ON FOREIGN DATA WRAPPER s3_pxf_fdw TO <role_name>;
config
需要和上文创建的文件夹 s3server_online
相对应。
=# CREATE SERVER s3server_online FOREIGN DATA WRAPPER s3_pxf_fdw OPTIONS(config 's3server_online');
创建用户映射。
=# CREATE USER MAPPING FOR mxadmin server s3server_online;
创建外部表。
=# CREATE FOREIGN TABLE public.test (
c1 jsonb,
c2 text,
c3 text,
c4 text,
c5 text,
c6 jsonb,
c7 jsonb
)
SERVER s3server_online
OPTIONS (
format 'csv',
resource '/<bucket_name>/<prefix>/<filename.csv>',
JSONIFY_ARRAY 'TRUE',
JSONIFY_MAP 'TRUE',
JSONIFY_RECORD 'TRUE'
);
参数说明:
CSV
、TXT
、Parquet
、ORC
、Avro
等。