#!/usr/bin/env bash # What "logical replication" gives Debezium: a replication slot, a publication, and a decoded stream of row changes. set -eu . "$(dirname "$0")/lib.sh" OUT=output/01-logical-replication.txt mkdir -p output { echo "### Server settings that make CDC possible" sqlp -c "select split_part(version(), ',', 1) as postgres" -c "show wal_level" -c "show max_replication_slots" -c "show max_wal_senders" echo echo "### Before any connector: no slots, no publications" sqlp -c "select count(*) as slots from pg_replication_slots" -c "select count(*) as publications from pg_publication" echo echo "### What logical decoding produces, read with the built-in test_decoding plugin on a throwaway slot" sql -c "select pg_create_logical_replication_slot('peek', 'test_decoding')" >/dev/null sql -c "insert into noise(payload) values ('hello')" -c "update noise set payload = 'hello again' where payload = 'hello'" -c "delete from noise where payload = 'hello again'" sqlp -c "select data from pg_logical_slot_get_changes('peek', null, null)" sql -c "select pg_drop_replication_slot('peek')" >/dev/null echo echo "### Register the Debezium connector (Kafka Connect, pgoutput) and wait for it" register connect/orders-connector.json wait_running orders-connector echo "connector: $(connector_state orders-connector)" echo echo "### What the connector created inside Postgres" sqlp -c "select slot_name, plugin, slot_type, active from pg_replication_slots" sqlp -c "select pubname, puballtables, pubinsert, pubupdate, pubdelete, pubtruncate from pg_publication" sqlp -c "select pubname, schemaname, tablename from pg_publication_tables" } 2>&1 | tee "$OUT"