Postgresql Replication slot error postgresql
I use Posgtresql 10.
I want to replicate 2 tables from database "db" to same two tables with same columns in database "destination".
changed wal_level value to logical in postgresql.conf and max_replication_slots to 10
no firewall
I created the publication in database "db"
ALTER ROLE my_user WITH REPLICATION LOGIN PASSWORD 'my_password';
CREATE PUBLICATION my_publication;
ALTER PUBLICATION my_publication ADD TABLE table1;
ALTER PUBLICATION my_publication ADD TABLE table2;
I created a subsription in database "destination" with a slot cause i want to replicate in the same server :
SELECT pg_create_logical_replication_slot('test_slot_v1', 'pgoutput');
CREATE SUBSCRIPTION my_subscription CONNECTION 'host=localhost port=5432 password=my_password user=my_user dbname=db' PUBLICATION my_publication WITH (slot_name=test_slot_v1, create_slot=false);
alter subscription my_subscription refresh publication ;
First replication works. Then when i change the value of one varchar entry (not a FK), the value is not replicated and I have the following error in postgres logs :
2020-04-12 16: 16: 57.886 CEST [720474] LOG: the logical replication apply process for the subscription "my_subscription" has started 2020-04-12 16: 16: 57.888 CEST [720475] ERROR: the replication slot "test_slot_v1" was not created in this database 2020-04-12 16: 16: 57.889 CEST [720474] ERROR: could not receive data from the WAL stream: ERROR: the replication slot "test_slot_v1" was not created in this database 2020-04-12 16: 16: 57.890 CEST [712133] LOG: work process: logical replication worker for subscription 245251 (PID 720474) exit with exit code 1
I'm sure I created the slot in the database "destination" that holds the subscription.
Any ideas ? Thank you in advance.
I'll answer my question : Postgresql wants the slot to be created in the database "db" where I created my publication and not in the database "destination" where I created the subscription.
What I did :
psql
\c destination
drop subscription my_subscription;
\q
psql
\c db
SELECT pg_create_logical_replication_slot('test_slot_v1', 'pgoutput');
\q
psql
\c destination
CREATE SUBSCRIPTION my_subscription CONNECTION 'host=localhost port=5432 password=my_password user=my_user dbname=db' PUBLICATION my_publication WITH (slot_name=test_slot_v1, create_slot=false);
It seems that this command is not needed : alter subscription my_subscription refresh publication ;