Home:ALL Converter>Postgresql 10 logical replication not working

Postgresql 10 logical replication not working

Ask Time:2017-10-17T17:50:17         Author:Manish Yadav

Json Formatter

I install postgresql 10 using scripts:

$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib

On Master server : xx.xxx.xxx.xx-:

And after that in postgresql.conf:

set wal_level = logical

On Slave server -:

in postgresql.conf:

set wal_level = logical

And after all i use below query on master server:

create table t1 (id integer primary key, val text);
create user replicant with replication;
grant select on t1 to replicant;
insert into t1 (id, val) values (10, 'ten'), (20, 'twenty'), (30, 'thirty');
create publication pub1 for table t1;

And at Slave server:

create table t1 (id integer primary key, val text, val2 text);
 create subscription sub1 connection 'dbname=dbsrc user=replicant' publication pub1;

But the problem which is i am facing is table are not syncing and as per logical replication when i insert new row on master server, slave server not getting that row.

I am new to postgresql please help me.

Thanks for your precious time.

Now here is my postgresql log for Master server:

2017-10-17 11:06:16.644 UTC [10713] replicant@postgres LOG:  starting logical decoding for slot "sub_1"
2017-10-17 11:06:16.644 UTC [10713] replicant@postgres DETAIL:  streaming transactions committing after 1/F45EB0C8, reading WAL from 1/F45EB0C8
2017-10-17 11:06:16.645 UTC [10713] replicant@postgres LOG:  logical decoding found consistent point at 1/F45EB0C8
2017-10-17 11:06:16.645 UTC [10713] replicant@postgres DETAIL:  There are no running transactions.

Here is my slave server postgresql log:

2017-10-17 19:14:45.622 CST [7820] WARNING:  out of logical replication worker slots
2017-10-17 19:14:45.622 CST [7820] HINT:  You might need to increase max_logical_replication_workers.
2017-10-17 19:14:45.670 CST [7821] WARNING:  out of logical replication worker slots
2017-10-17 19:14:45.670 CST [7821] HINT:  You might need to increase max_logical_replication_workers.
2017-10-17 19:14:45.680 CST [7822] WARNING:  out of logical replication worker slots
2017-10-17 19:14:45.680 CST [7822] HINT:  You might need to increase max_logical_replication_workers.
2017-10-17 19:14:50.865 CST [7820] WARNING:  out of logical replication worker slots
2017-10-17 19:14:50.865 CST [7820] HINT:  You might need to increase max_logical_replication_workers.
2017-10-17 19:14:50.917 CST [7821] WARNING:  out of logical replication worker slots
2017-10-17 19:14:50.917 CST [7821] HINT:  You might need to increase max_logical_replication_workers.
2017-10-17 19:14:50.928 CST [7822] WARNING:  out of logical replication worker slots
2017-10-17 19:14:50.928 CST [7822] HINT:  You might need to increase max_logical_replication_workers.
2017-10-17 19:14:55.871 CST [7820] WARNING:  out of logical replication worker slots
2017-10-17 19:14:55.871 CST [7820] HINT:  You might need to increase max_logical_replication_workers.

And after increasing the max_logical_replication_workers i am getting this:

2017-10-17 19:44:45.898 CST [7987] LOG:  logical replication table synchronization worker for subscription "sub2", table "t1" has started
2017-10-17 19:44:45.982 CST [7988] LOG:  logical replication table synchronization worker for subscription "myadav_test", table "test_replication" h$
2017-10-17 19:44:45.994 CST [7989] LOG:  logical replication table synchronization worker for subscription "sub3", table "t1" has started
2017-10-17 19:44:48.621 CST [7987] ERROR:  could not start initial contents copy for table "staging.t1": ERROR:  permission denied for schema staging
2017-10-17 19:44:48.623 CST [7962] LOG:  worker process: logical replication worker for subscription 20037 sync 20027 (PID 7987) exited with exit co$
2017-10-17 19:44:48.705 CST [7988] ERROR:  could not start initial contents copy for table "staging.test_replication": ERROR:  permission denied for$
2017-10-17 19:44:48.707 CST [7962] LOG:  worker process: logical replication worker for subscription 20025 sync 20016 (PID 7988) exited with exit co$
2017-10-17 19:44:48.717 CST [7989] ERROR:  duplicate key value violates unique constraint "t1_pkey"
2017-10-17 19:44:48.717 CST [7989] DETAIL:  Key (id)=(10) already exists.
2017-10-17 19:44:48.717 CST [7989] CONTEXT:  COPY t1, line 1
2017-10-17 19:44:48.718 CST [7962] LOG:  worker process: logical replication worker for subscription 20038 sync 20027 (PID 7989) exited with exit co$
2017-10-17 19:44:51.629 CST [8008] LOG:  logical replication table synchronization worker for subscription "sub2", table "t1" has started
2017-10-17 19:44:51.712 CST [8009] LOG:  logical replication table synchronization worker for subscription "myadav_test", table "test_replication" h$
2017-10-17 19:44:51.722 CST [8010] LOG:  logical replication table synchronization worker for subscription "sub3", table "t1" has started

Now i finally realize that logical replication is working for postgres database but not for my other database on same server. I am getting permission issue on schema that is is log.

Author:Manish Yadav,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/46787297/postgresql-10-logical-replication-not-working
yy