Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6Cpk-00Hb3u-Ss for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Nov 2023 16:45:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r6Cph-002EcL-AH for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Nov 2023 16:45:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6Cpg-002EcA-WB for pgsql-hackers@lists.postgresql.org; Thu, 23 Nov 2023 16:45:41 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r6Cpd-0084D4-G0 for pgsql-hackers@lists.postgresql.org; Thu, 23 Nov 2023 16:45:39 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3316d3d11e1so643214f8f.0 for ; Thu, 23 Nov 2023 08:45:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1700757936; x=1701362736; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=hbnrhCSAp8044ihsvsTbnIXqrXCclWNsLrkVJ7+hFCU=; b=Jo2KQibAmOAtpHvqA8bFRXW1qmWl1ZR7jMDA3NKVZ3JW+RfBKleYBNKi1ex9+1iJIM Xjv3VIwn76alsOWDw3rVDsKhMICc1Fsne8Nop68BkzOm0+nen66C6MKQwUS+hpc2HkB/ SgCYYGG2X9P8FxZOU8HSrQojIZfu6REMvk1cZe5ZQwKR07bRjSuPEs7qdOxuy1fZ9nta 0+fCcnd8KNFeqvixWO0Y5EAtDqHtwk21BMfGrodXdLBt/iYpG1HdQ23h5nihgaU89HKj 9KJmlyXuEAljp0rT8KxGtZ4TF5Etk+F/bt5mISXB/urRM9FN4IWoi0iBexJ9WkQda2Tt AsnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700757936; x=1701362736; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hbnrhCSAp8044ihsvsTbnIXqrXCclWNsLrkVJ7+hFCU=; b=a2P4pMiV/henmSTYzWnDMHhEpcR+uhYJZQV+uCBdj0Dci9tem6Oyzf9CZtD69l5RZF ZPyD1DNsAEJKReB7WH07edo7nNpxDhOJ6RzMsO4F58D3Zr+BVCT1/+vK1mInK1rRrCON WPEMHzD53xKRWvHcTAmGvKF+KJUKR0OoXKA975YrIRIa3JOVuwfHkgZW04erfYUQyyB9 LDJjwERN/oEmjJ3scynLKzBq+7613F+68/87BbTrPBgCBAFkaxFNGdcqrb1HasvJfOLV dLfifQa4vu9ZtCxcrpN3i/up/UvPNTGs6o58fK6z75lwqUhgQcufEQ5Vtp0/J4YXsSGU 8YEQ== X-Gm-Message-State: AOJu0YybEEFW5u3ZgiWyxAU1UUHSg6GFWOoToa8yWZHr+EfkgBcHAwM2 ZMikIYldjqnVZ25MfLlBDNBkrw== X-Google-Smtp-Source: AGHT+IEVbnskfhjE7IfqJDPAsbKicszJlDzuL8msYBZRWb6J3BE/YDzBT+C22fH27gRGPciXAqlgoQ== X-Received: by 2002:adf:fd11:0:b0:332:c65a:8f1e with SMTP id e17-20020adffd11000000b00332c65a8f1emr2499048wrr.19.1700757935735; Thu, 23 Nov 2023 08:45:35 -0800 (PST) Received: from [10.137.0.17] (srv1.mobissw.com. [89.235.0.226]) by smtp.gmail.com with ESMTPSA id o7-20020a5d6847000000b0032dab20e773sm2056050wrw.69.2023.11.23.08.45.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Nov 2023 08:45:35 -0800 (PST) Message-ID: <9afab261-94a7-3e58-f0fb-040e45f42aa5@enterprisedb.com> Date: Thu, 23 Nov 2023 17:45:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: undetected deadlock in ALTER SUBSCRIPTION ... REFRESH PUBLICATION Content-Language: en-US To: Amit Kapila Cc: PostgreSQL Hackers References: <8948e4a2-fec7-8a61-9ace-2537cee3ef6f@enterprisedb.com> <69e9a1af-a315-8b05-0674-2cc53bf27682@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/23/23 10:24, Amit Kapila wrote: > On Wed, Nov 22, 2023 at 4:51 PM Tomas Vondra > wrote: >> >> On 11/22/23 11:38, Amit Kapila wrote: >>> >>> Okay. IIUC, what's going on here is that the apply worker acquires >>> AccessShareLock on pg_subscription to update rel state for one of the >>> tables say tbl-1, and then for another table say tbl-2, it started >>> waiting for a state change via wait_for_relation_state_change(). I >>> think here the fix is to commit the transaction before we go for a >>> wait. I guess we need something along the lines of what is proposed in >>> [1] though we have solved the problem in that thread in some other >>> way.. >>> >> >> Possibly. I haven't checked if the commit might have some unexpected >> consequences, but I can confirm I can no longer reproduce the deadlock >> with the patch applied. >> > > Thanks for the verification. Offhand, I don't see any problem with > doing a commit at that place but will try to think some more about it. > I think we may want to call pgstat_report_stat(false) after commit to > avoid a long delay in stats. > Makes sense. > I haven't verified but I think this will be a problem in > back-branches as well. > Yes. I haven't tried but I don't see why backbranches wouldn't have the same issue. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company