Skip to content

Instantly share code, notes, and snippets.

@CHERTS
Last active June 20, 2024 12:10
Show Gist options
  • Save CHERTS/2735a4db93ffa18ee997bfb627a208f2 to your computer and use it in GitHub Desktop.
Save CHERTS/2735a4db93ffa18ee997bfb627a208f2 to your computer and use it in GitHub Desktop.
Create Debezium heartbeat table in PostgreSQL
CREATE SCHEMA debezium;
CREATE TABLE debezium.debezium_signal(id VARCHAR(42) PRIMARY KEY, type VARCHAR(32) NOT NULL, data VARCHAR(2048) NULL);
CREATE TABLE debezium.pg_heartbeat(id SERIAL, last_update TIMESTAMP DEFAULT current_timestamp, PRIMARY KEY (id));
--INSERT INTO debezium.pg_heartbeat(id) VALUES (0);
GRANT USAGE ON SCHEMA debezium TO debezium_dwh;
GRANT SELECT, INSERT, UPDATE, DELETE ON debezium.debezium_signal TO debezium_dwh;
GRANT SELECT, INSERT, UPDATE, DELETE ON debezium.pg_heartbeat TO debezium_dwh;
ALTER PUBLICATION dbz_publication ADD TABLE debezium.debezium_signal;
ALTER PUBLICATION dbz_publication ADD TABLE debezium.pg_heartbeat;
ALTER TABLE debezium.debezium_signal REPLICA IDENTITY FULL;
ALTER TABLE debezium.pg_heartbeat REPLICA IDENTITY FULL;
-- Add the below config in the Kafka debezium connector configuration
-- heartbeat.interval.ms: 10000
-- heartbeat.action.query: "UPDATE debezium.pg_heartbeat SET last_update=now() WHERE id=0;"
-- See docs: https://debezium.io/documentation/reference/stable/connectors/postgresql.html#postgresql-property-heartbeat-interval-ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment