PG外部数据源的列式存储

1 安装软件

yum -y install protobuf protobuf-c protobuf-c-devel openssl openssl-devel

2 安装cstore_fdw

--下载源码
git clone https://github.com/citusdata/cstore_fdw.git


--修改Makefile中的PG_CONFIG值为pg_config所在的目录
--执行make && make install	

3 修改数据库配置文件postgresql.conf并重启数据库服务
shared_preload_libraries = ‘cstore_fdw’
4 登录数据库创建扩展和服务

create extension cstore_fdw;
create server cstore_server foreign data wrapper cstore_fdw ;	

5 创建普通表和外部表

--普通表
CREATE TABLE customer
(
    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)[]
);
--外部表
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');	

6 拷贝数据到普通表

copy customer to '/home/highgo/customer_data.csv' with csv;	

7 向外部表中插入同样的数据

insert into customer_reviews select * from customer;	

8 查询普通表所占磁盘大小

select pg_size_pretty(pg_relation_size('customer'));	

在这里插入图片描述

9 查询经过列式存储的表占磁盘的大小

cd /home/highgo/highgo/database/4.5/xudata/cstore_fdw/14507
ll -h

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值