0

PostgreSQL has a replication feature which is called logical replication. In earliest versions there is a native extension called pgoutput for logical decoding.

Logical Replication consist of a publisher and a subscriber which result into 1-1 replication. My question is, if I can create my own subscriber though a PostgreSQL function in order to stream changes and make lightweight modification before applied to the destination table.

For instance, there is the way of test_decoding

SELECT * FROM pg_create_logical_replication_slot('test_slot', 'test_decoding');

DROP PUBLICATION PUB;
CREATE PUBLICATION PUB FOR ALL TABLES;

SELECT * FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'stream-changes', '1');

But this way I have to sent select queries again and again and this is not exactly streaming....

Any ideas?

Stavros Koureas
  • 1,126
  • 12
  • 34
  • That *is* streaming if you do the SELECT in a loop. Someone has to implement that loop. If you decide to implement this yourself, than that someone is you. – jjanes Nov 14 '22 at 14:07
  • So you mean to implement the SELECT statement into a procedure nested in WHILE(TRUE) to always get the new changes? But this has to be executed though a db_link and therefore there will be thousands of calls even there are no new changes.... does not seem right to me..... – Stavros Koureas Nov 15 '22 at 08:41

0 Answers0