Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nR6Av-0003PF-Io for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Mar 2022 05:44:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nR6At-0003ox-Vs for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Mar 2022 05:44:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nR6At-0003oo-Kq for pgsql-hackers@lists.postgresql.org; Mon, 07 Mar 2022 05:44:51 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nR6An-0001ms-0g for pgsql-hackers@lists.postgresql.org; Mon, 07 Mar 2022 05:44:50 +0000 Received: by mail-ed1-x535.google.com with SMTP id g20so18313382edw.6 for ; Sun, 06 Mar 2022 21:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nRdWyc+j0VYBTkRhSHsH3m+aoGB9LeEuiXRsJ1AwZ6E=; b=qioDn+81WDJl7LpLrC+pL30PVh60UsYt8g4TtOdGtzXwtild09WJPiB/XrSOvU0q7B 4A/HWYOVKEK2A3lwktKTnnA0IIpG3dMrxoezttIfGYObokZleFeXud3/o7lPeqy9Gpp6 tQ3yFiKrikL1XwN6pprY/q0th7NSa1lOEgyjj0SD03VCN9+tgZEr3FNDqwY9MFPPz0+h Ye1fuiEiVBIG6Imw+Q2sR7wDAl3CU2lyJbMVPo5KjNz78JZ5izjWGKk+DQ97CotrNOqo 3i8Yf8P5IMAOsn1x7jO6o3ODNAtMaqDIuQ5HTEs+GDcOQaO4ma1QWYcWu7kuOhHkLnTk OtPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nRdWyc+j0VYBTkRhSHsH3m+aoGB9LeEuiXRsJ1AwZ6E=; b=SvU5hUu/Lyuqer193HOpeyRPK1MibG2aWHnL7ThH3BY6PA10H4kDRATvoeKiTjvADe ojAyc8YJvFxqUkAge3rWWFvWZY44gLpLdrpQ2GGEGKKoP4eLveo4+leN7CZes/Zkijeo s3DpnAGqeFnzw21+SuYk7wOEdeDLcGquKGC5IIoz2ty5ExiqEF2M53guYwQcDXS3jaOS 87yUlKv3JrZxV2Qp6wFWziY3OMQbUFhKPMKzyipBIaHUp3xssZEUyY9NkvMymjPrNV8T 3n+4wGSbdhoN9gGAf/MVSlDeOJTqhxHUYiO1kJ097CIq738jecS7hoIrlFMd1OSOvC2J TrjA== X-Gm-Message-State: AOAM533WJF/cbC0Gt8y9XfzJ9sOGVQvKD9S4rrpjA+vrwsL+BIsy3pxG QpBzCIkvAQCk54URJvijr6IzlctK2yY8bYrp6pc= X-Google-Smtp-Source: ABdhPJx5T8pnmYEoVILJZV7sYChj7NtX2g9Aa/MzlC2dnS3tqnFJ2p7V+moxgb6YbarVadSxC8/t023tWv4jY/mUtR8= X-Received: by 2002:a05:6402:268c:b0:411:e086:b7d1 with SMTP id w12-20020a056402268c00b00411e086b7d1mr9518611edd.111.1646631882748; Sun, 06 Mar 2022 21:44:42 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: vignesh C Date: Mon, 7 Mar 2022 11:14:31 +0530 Message-ID: Subject: Re: Handle infinite recursion in logical replication setup To: "kuroda.hayato@fujitsu.com" Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 1, 2022 at 4:12 PM kuroda.hayato@fujitsu.com wrote: > > Hi Vignesh, > > > In logical replication, currently Walsender sends the data that is > > generated locally and the data that are replicated from other > > instances. This results in infinite recursion in circular logical > > replication setup. > > Thank you for good explanation. I understand that this fix can be used > for a bidirectional replication. > > > Here there are two problems for the user: a) incremental > > synchronization of table sending both local data and replicated data > > by walsender b) Table synchronization of table using copy command > > sending both local data and replicated data > > So you wanted to solve these two problem and currently focused on > the first one, right? We can check one by one. > > > For the first problem "Incremental synchronization of table by > > Walsender" can be solved by: > > Currently the locally generated data does not have replication origin > > associated and the data that has originated from another instance will > > have a replication origin associated. We could use this information to > > differentiate locally generated data and replicated data and send only > > the locally generated data. This "only_local" could be provided as an > > option while subscription is created: > > ex: CREATE SUBSCRIPTION sub1 CONNECTION 'dbname =postgres port=5433' > > PUBLICATION pub1 with (only_local = on); > > Sounds good, but I cannot distinguish whether the assumption will keep. > > I played with your patch, but it could not be applied to current master. > I tested from bd74c40 and I confirmed infinite loop was not appeared. > > local_only could not be set from ALTER SUBSCRIPTION command. > Is it expected? I felt changing only_local option might be useful for the user while modifying the subscription like setting it with a different set of publications. Changes for this are included in the v2 patch attached at [1]. [2] - https://www.postgresql.org/message-id/CALDaNm0WSo5369pr2eN1obTGBeiJU9cQdF6Ju1sC4hMQNy5BfQ%40mail.gmail.com Regards, Vignesh