PostgreSQL Heartbeats

Setup PostgreSQL heartbeats for low volume databases

For low volume PostgreSQL sources, it is possible that the log becomes stale due to a lack of change events. As a result, events may not be captured by the Connector.

To address this, the heartbeat process involves writing an insert or update to a heartbeat table every 1 second to generate a change event.

πŸ“˜

The heartbeat table must exist in a schema called streamkap

Setup MySQL Heartbeats

-- Create the streamkap schema
CREATE SCHEMA IF NOT EXISTS streamkap;

-- Switch to the streamkap schema
SET search_path TO streamkap;

-- Create the heartbeat table with id, text, and last_update fields
CREATE TABLE streamkap_heartbeat (
    id SERIAL PRIMARY KEY,
    text TEXT,
    last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Grant permission to the Streamkap user
GRANT INSERT, UPDATE ON TABLE streamkap_heartbeat TO STREAMKAP_USER;

-- Insert the first row into the heartbeat table
INSERT INTO streamkap_heartbeat (text) VALUES ('test_heartbeat');

πŸ“˜

Heartbeat tables and PostgreSQL publications

If the streamkap_pub publication was created to included specific tables e.g. CREATE PUBLICATION streamkap_pub FOR TABLE table1, table2, table3, ...; instead of FOR ALL TABLES;, you must add the heartbeat table to the publication also ALTER PUBLICATION streamkap_pub ADD TABLE streamkap.streamkap_heartbeat;

Verify

  • Look for entries in the heartbeat table to verify this is working with an updated timestamp