Data streaming from postgresql to clickhouse via logical replication mechanism
Data streaming from postgresql to clickhouse via logical replication mechanism
Continuous data transfer from PostgreSQL to ClickHouse using logical replication mechanism.
Currently pg2ch tool is in active testing stage, as for now it is not for production use
Get:
go get -u github.com/mkabilov/pg2chRun:
pg2ch --config {path to the config file (default config.yaml)}…localhost:5432wal_level in the postgresql config file to logicalmax_replication_slots to at least 2localhost:9000 e.g. in the dockerpg2ch_test in PostgreSQL: CREATE DATABASE pg2ch_test;pgbench -U postgres -d pg2ch_test -ipgbench_accounts table to FULL, so that we'll receive old values of the updated rows: ALTER TABLE pgbench_accounts REPLICA IDENTITY FULL;pgbench_accounts table: CREATE PUBLICATION pg2ch_pub FOR TABLE pgbench_accounts;SELECT * FROM pg_create_logical_replication_slot('pg2ch_slot', 'pgoutput');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 tableconfig.yaml file with the following content:… pg2ch --config config.yamlpgbench to have some test load: pgbench -U postgres -d pg2ch_test --time 30 --client 10 inactivity_merge_timeout period (in our case 10 seconds) so that data in the memory gets flushed to the table in ClickHouseabalance column both on ClickHouse and PostgreSQL:SELECT SUM(abalance * sign), SUM(sign) FROM pgbench_accounts (why multiply by sign column?) SELECT SUM(abalance), COUNT(*) FROM pgbench_accountsNo open issues yet, or sync has not completed.