百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

pg2ch

> 数据库
开源

通过逻辑复制机制将数据从 PostgreSQL 传输到 clickhouse

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

通过逻辑复制机制将数据从 PostgreSQL 传输到 clickhouse

PostgreSQL to ClickHouse

Continuous data transfer from PostgreSQL to ClickHouse using logical replication mechanism.

Status of the project

Currently pg2ch tool is in active testing stage, as for now it is not for production use

Getting and running

Get:

    go get -u github.com/mkabilov/pg2ch

Run:

    pg2ch --config {path to the config file (default config.yaml)}

Config file

…

Sample setup:

  • make sure you have PostgreSQL server running on localhost:5432
    • set wal_level in the postgresql config file to logical
    • set max_replication_slots to at least 2
  • make sure you have ClickHouse server running on localhost:9000 e.g. in the docker
  • create database pg2ch_test in PostgreSQL: CREATE DATABASE pg2ch_test;
  • create a set of tables using pgbench command: pgbench -U postgres -d pg2ch_test -i
  • change replica identity for the pgbench_accounts table to FULL, so that we'll receive old values of the updated rows: ALTER TABLE pgbench_accounts REPLICA IDENTITY FULL;
  • create PostgreSQL publication for the pgbench_accounts table: CREATE PUBLICATION pg2ch_pub FOR TABLE pgbench_accounts;
  • create PostgreSQL logical replication slot: SELECT * FROM pg_create_logical_replication_slot('pg2ch_slot', 'pgoutput');
  • create tables on the ClickHouse side:
sql
CREATE TABLE pgbench_accounts (aid Int32, abalance Int32, sign Int8) ENGINE = CollapsingMergeTree(sign) ORDER BY aid
-- our target table

CREATE TABLE pgbench_accounts_buf (aid Int32, abalance Int32, sign Int8, row_id UInt64) ENGINE = Memory()
-- will be used as a buffer table
  • create config.yaml file with the following content:
…
  • run pg2ch to start replication:
bash
    pg2ch --config config.yaml
  • run pgbench to have some test load:
bash
    pgbench -U postgres -d pg2ch_test --time 30 --client 10 
  • wait for inactivity_merge_timeout period (in our case 10 seconds) so that data in the memory gets flushed to the table in ClickHouse
  • check the sums of the abalance column both on ClickHouse and PostgreSQL:
    • ClickHouse: SELECT SUM(abalance * sign), SUM(sign) FROM pgbench_accounts (why multiply by sign column?)
    • PostgreSQL: SELECT SUM(abalance), COUNT(*) FROM pgbench_accounts
  • numbers must match; if not, please open an issue.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goclickhousegogolanglogical-replication

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库