PostgreSQL使用clickhouse_fdw访问ClickHouse

Postgres

  • postgres版本:16(测试可用)
  • docker 安装

插件安装

  • clickhouse_fdw: https://github.com/ildus/clickhouse_fdw

安装命令

git clone git@github.com:ildus/clickhouse_fdw.git
cd clickhouse_fdw
mkdir build && cd build
cmake ..
make && make install

deb12换源

cat > /etc/apt/sources.list << EOF
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
EOF
apt update

安装编译器

docker镜像里没有必要的编译工具,make 执行不了
make 过程中陆陆续续提示缺少依赖,按提示安装包即可
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
大概安装了以下包,仅供参考

apt-get install devscripts build-essential cmake unixodbc-dev postgresql-server-dev-16 pkg-config libcurl libcurl4-openssl-dev uuid-dev

最终,make install 会把编译好的插件发送到指定位置,直接连接pg加载即可

加载插件

CREATE EXTENSION clickhouse_fdw;  -- 加载插件 

导入外部表

CREATE SERVER clickhouse_svr FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(host '192.168.30.101', port '8123', dbname 'my_ch_db', driver 'http');  -- 连接clickhouse

CREATE USER MAPPING FOR CURRENT_USER SERVER clickhouse_svr OPTIONS (user 'default', password '');  -- 用户映射,clickhouse的连接密码
IMPORT FOREIGN SCHEMA "my_ch_db" FROM SERVER clickhouse_svr INTO public;  -- 把clickhouse模式导入pg

注意IMPORT SCHEMA会加载clickhouse库名<my_ch_db>下的所有表到postgres的public模式
可以在pg的外表中查看到
在这里插入图片描述

删除外部表

drop FOREIGN table if exists "soc_filtered"; -- 删除所有外部表
drop user mapping FOR CURRENT_USER server clickhouse_svr;  -- 删除用户映射
drop server clickhouse_svr;  -- 删除链接

查询外部表

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颹蕭蕭

白嫖?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值