PostgreSQL logical replication - create subscription hangs

核能气质少年 提交于 2019-12-11 17:55:43

问题


I am trying to set logical replication between 2 cloud instances both with Debian 9 and PG 11.1. The command CREATE PUBLICATION on master was successful, but when I start the command CREATE SUBSCRIPTION on the intended logical replica, the command hangs indefinitely.

On the master I can see that the replication slot was created and is active and I can see a new walsender process created and "waiting" and in the log on the master I see these these lines:

2019-01-14 14:20:39.924 UTC [8349] repl_user@db LOG:  logical decoding found initial starting point at 7B0/6C777D10
2019-01-14 14:20:39.924 UTC [8349] repl_user@db DETAIL:  Waiting for transactions (approximately 2) older than 827339177 to end.

But that is all. The command CREATE SUBSCRIPTION never ends.

Master is a db with heavy inserts, like 100s per minute, but they are all always committed. So there should not be any long time uncommitted transactions.

I tried to google for this problem but did not find anything. What am I missing?


回答1:


Since the databases are “in the cloud”, so you don't know where they really are.

Odds are that they are actually in the same database cluster, which would explain the deadlock you see: CREATE SUBSCRIPTION waits until all concurrent transactions on the cluster that contains the replication source database are finished before it can create its replication slot, but since both databases are in the same cluster, it waits for itself to finish, which obviously won't happen.

The solution is to explicitly create a logical replication slot in the source database and to use that existing slot when you create the subscription.



来源:https://stackoverflow.com/questions/54185023/postgresql-logical-replication-create-subscription-hangs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!