Postgresql – Postgres Logical Replication For Specific tables

postgresqlreplication

I'm using logical replication to move data from postgres to a search engine via some background process, but I am only concerned with a small set of tables. Is there a way to specify which tables a replication slot is concerned with

I have a replication user set up and am able to receive the changes just fine.
I've implemented little script to handle the binary protocol and forward to my search engine with:

START_REPLICATION SLOT <SLOT NAME> LOGICAL 0/00000000

But this gives me every change for every table.
I see that this is possible between postgres servers via publications and subscriptions, but this doesn't seem to work from an application client. Maybe I am missing something?

Is there a way to whitelist tables for replication slots this way?

Best Answer

Have you tried specifing the list of tables to be logically replicated while creating the publisher?

Create publisher pub_1 for table table_a;
Create subscription sub_1 publication pub_1;

This will send the changes only for table_a to the subscriber. This is the way to whitelist a selected set of tables to replicate.

ALTER PUBLICATION name ADD TABLE table_b;

This Alter publication command can be used to add/remove any tables after creating a publication.

I dont think there is a way to do this with replication slots.