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 1okl9e-0002fN-5V for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Oct 2022 11:53:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1okl9a-0002xc-S7 for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Oct 2022 11:53:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okl9a-0002xT-Iy for pgsql-hackers@lists.postgresql.org; Tue, 18 Oct 2022 11:53:02 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1okl9X-0000PB-Vs for pgsql-hackers@lists.postgresql.org; Tue, 18 Oct 2022 11:53:01 +0000 Received: by mail-ot1-x336.google.com with SMTP id r8-20020a056830120800b00661a0a236efso7455187otp.4 for ; Tue, 18 Oct 2022 04:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=j928j6b5dXnj2mEY31ARzWlU6sivvp1Z1076Mhr3MlI=; b=JubffjrCCftn7dBZi5lHn763Un2qfCTbrBKEZpTH939nvBH9FarZyoFUyU+7zlJ9nO +UC6YmGu6upaMgObsNLOlck9eodAhO4d1mErQJGRvboee9diJYUSPj+WKzcRIHtJcWSv Emmx20G/3H7uE6A23AtaA10X9PcNAO76HjpjGkod9LfG4afDtMwXscG0aE4l3e35uAho +zFXLjjrbMyTIY6lMz1iDiHxZrI5bM1ZO7dOnMjxPqgZLZlRvOZWMQGwR+eiWuxFfyQ6 /jd2yDNucoFfV1TUsUkiJhBTgLyqJGglUJbSk9n7f3r4qiFGtIS/NNmJgNV0jhdrClOG l2Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j928j6b5dXnj2mEY31ARzWlU6sivvp1Z1076Mhr3MlI=; b=Upop8H1azcEqZ7Qn+vX6emM5I5iuHRWnkrt7IMcQ6EDzjkA4yp2LqomfTtcZATzxku HaJP/JALJKpqtPZP8FcuAVNWQ57e7dKDdMeCvkxa2zsSIsf83o2ARHiEvjVifGBAvrcM +vfXEBct5bGay5VBYwx3pjkyrn8ggqX7qMz47iPDH2xsSLJX7+iiWmOCJgwzEiDMmAsz YKXJUz8ckS85bFPBNctFf2k7BzLtJsREgrsEYwvuHkDKWqS9l1BNC9oWBRXY5D0W42Nk FpB0KQnl1UHHOX6jxdEcSUVdfLIdSFhUqINnmTnrkoNSpA8XD3ML83gKS7VdV/hdyXJ2 t3zw== X-Gm-Message-State: ACrzQf0XpK4s5rXVwcGJSkiHl43YDx2Fcx7b2W+ANAAmTeGmdXueld/1 DrP88Z9zfdrU5Z7nnlJI9pw0SZTsBtmVJjWXoS9miS5t X-Google-Smtp-Source: AMsMyM7M2i9X/cbz//lkN91IYTbf6jM10IBaZbsk25VRA7vMmYmQ+Qcd4lG4RYClR09Ruz8jfqXpzsXOX8nem8VI59I= X-Received: by 2002:a9d:68d1:0:b0:661:c3ac:c4c1 with SMTP id i17-20020a9d68d1000000b00661c3acc4c1mr1129062oto.150.1666093977936; Tue, 18 Oct 2022 04:52:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Dilip Kumar Date: Tue, 18 Oct 2022 17:22:39 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: Masahiko Sawada Cc: "houzj.fnst@fujitsu.com" , Amit Kapila , "wangw.fnst@fujitsu.com" , Peter Smith , "shiy.fnst@fujitsu.com" , 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 Thu, Oct 6, 2022 at 1:37 PM Masahiko Sawada wrote: > > While looking at v35 patch, I realized that there are some cases where > the logical replication gets stuck depending on partitioned table > structure. For instance, there are following tables, publication, and > subscription: > > * On publisher > create table p (c int) partition by list (c); > create table c1 partition of p for values in (1); > create table c2 (c int); > create publication test_pub for table p, c1, c2 with > (publish_via_partition_root = 'true'); > > * On subscriber > create table p (c int) partition by list (c); > create table c1 partition of p for values In (2); > create table c2 partition of p for values In (1); > create subscription test_sub connection 'port=5551 dbname=postgres' > publication test_pub with (streaming = 'parallel', copy_data = > 'false'); > > Note that while both the publisher and the subscriber have the same > name tables the partition structure is different and rows go to a > different table on the subscriber (eg, row c=1 will go to c2 table on > the subscriber). If two current transactions are executed as follows, > the apply worker (ig, the leader apply worker) waits for a lock on c2 > held by its parallel apply worker: > > * TX-1 > BEGIN; > INSERT INTO p SELECT 1 FROM generate_series(1, 10000); --- changes are streamed > > * TX-2 > BEGIN; > TRUNCATE c2; --- wait for a lock on c2 > > * TX-1 > INSERT INTO p SELECT 1 FROM generate_series(1, 10000); > COMMIT; > > This might not be a common case in practice but it could mean that > there is a restriction on how partitioned tables should be structured > on the publisher and the subscriber when using streaming = 'parallel'. > When this happens, since the logical replication cannot move forward > the users need to disable parallel-apply mode or increase > logical_decoding_work_mem. We could describe this limitation in the > doc but it would be hard for users to detect problematic table > structure. Interesting case. So I think the root of the problem is the same as what we have for a column is marked unique to the subscriber but not to the publisher. In short, two transactions which are independent of each other on the publisher are dependent on each other on the subscriber side because table definition is different on the subscriber. So can't we handle this case in the same way by marking this table unsafe for parallel-apply? -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com