pgspider cstore fdw docker 镜像试用

cstore_fdw 是citus 团队开源的pg 列式存储扩展,可以加速我们的数据分析,关于列式存储以及行式存储的比较
可以参考下边连接的动图(来自clickhouse 官方网站)
https://clickhouse.tech/docs/en/

以下是关于cstore fdw 的简单使用

环境准备

  • docker-compose 文件
 
version: '3'
services:
  pgspider-cstore:
    image: dalongrong/pgspider:cstore
    ports: 
    - "5433:5432"
    environment: 
    - "POSTGRES_PASSWORD=dalong"
  • 启动&&初始化数据
启动docker-compose 服务
docker-compose up -d
下载demo 数据
wget http://examples.citusdata.com/customer_reviews_1998.csv.gz
wget http://examples.citusdata.com/customer_reviews_1999.csv.gz
加压文件:
gzip -d customer_reviews_1998.csv.gz
gzip -d customer_reviews_1999.csv.gz
copy 数据到容器,使用docker cp 命令

使用cstore fdw

  • 启用扩展
CREATE EXTENSION cstore_fdw;
  • 创建server
CREATE SERVER cstore_server FOREIGN DATA WRAPPER cstore_fdw;
  • 创建外部表
CREATE FOREIGN TABLE customer_reviews
(
    customer_id TEXT,
    review_date DATE,
    review_rating INTEGER,
    review_votes INTEGER,
    review_helpful_votes INTEGER,
    product_id CHAR(10),
    product_title TEXT,
    product_sales_rank BIGINT,
    product_group TEXT,
    product_category TEXT,
    product_subcategory TEXT,
    similar_product_ids CHAR(10)[]
)
SERVER cstore_server
OPTIONS(compression 'pglz');
  • 导入数据

    容器内部

导入数据:
\COPY customer_reviews FROM 'customer_reviews_1998.csv' WITH CSV;
\COPY customer_reviews FROM 'customer_reviews_1999.csv' WITH CSV;
  • 查询
SELECT
    customer_id, review_date, review_rating, product_id, product_title
FROM
    customer_reviews
WHERE
    customer_id ='A27T7HVDXA3K2A' AND
    product_title LIKE '%Dune%' AND
    review_date >= '1998-01-01' AND
    review_date <= '1998-12-31';
  • 效果

 

 

说明

实际如果为了生成cstore的列式数据,我们可以通过pg_cron 扩展,集成起来都是很不错的

参考资料

https://github.com/citusdata/cstore_fdw
https://github.com/citusdata/pg_cron
https://github.com/rongfengliang/pgspider-docker

posted on   荣锋亮  阅读(433)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-02-24 Optimizing Docker Images for Rust Projects
2019-02-24 bloom-server 基于 rust 编写的 rest api cache 中间件
2016-02-24 Collection+JSON 文档

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示