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 1r4SCT-008ndD-8A for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Nov 2023 20:45:57 +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 1r4SCP-0023yP-3f for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Nov 2023 20:45:53 +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 1r4SCO-0023yH-PV for pgsql-hackers@lists.postgresql.org; Sat, 18 Nov 2023 20:45:52 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r4SCC-0077F7-NT for pgsql-hackers@lists.postgresql.org; Sat, 18 Nov 2023 20:45:48 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4083cd3917eso5528865e9.3 for ; Sat, 18 Nov 2023 12:45:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1700340337; x=1700945137; 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=4mOjHBv8YV+JESOGTEue78/egLTQ8WUyIFQyIdaaz4U=; b=Q8dIwBLTsjGDAWSYyQqzKpec413ig+bTomAzB03B0WL60F/fQJPpcin6j0Fb4B7vnv ZrkstuRDAfMtYp7tTnfY0nZ3TRz45eV3aO1zLvExpCVbba7xo0vKxmv+KkKtB8xJSorh bShmbkK2jNU032T2213Rpi2y6p4r7jEFyAxmPyoPeQaNC/Him6ykVJbuDA5Kun4duEor RUz3b/X2JBP9gwpmuOmG5/nw8SshlZZOcLOkyXkKMw/YTEgRAiLFhpYvpElNBNdmoB3E 2W84mAWvZdq1+SsnENfMHnXQCBbl7FgUI00LkPSFB8cXvjoDUTRMlPq7eNAvd3aubbiD P91A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700340337; x=1700945137; 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=4mOjHBv8YV+JESOGTEue78/egLTQ8WUyIFQyIdaaz4U=; b=sRgkneFdoiWHaliQ13wNg2U4qdx64kAosP2hVja6BaVX93lz4BTj/Kjt3ZSDOOskJl hvMrwzWbYXndTx1JNN1jHtHlm5SWW4qIONEGb8TyEgR5K/YxUBi64YFBe0N9EHW158h5 2xSeVRlgQszcTZN9YA/s55KY6sq5DOozZpufSxDsv+tDsKkHXYYz8aJuHymt4qdfZKFP Z8/A8OLaLsgGFhTSDmOvfUQ1VJFpNFNGEW5GjAXSY2yvyQkIiw01wJE6WXOnpYt//Ex4 EMESl2/qkseWeMBAoU9uANa8tSRnCv+lqTDngIOtdUnJvn4H9joLfKyHIWKK5Xx/CQdd Licw== X-Gm-Message-State: AOJu0YwzwFMRP3MqJcjHoDLupiTgmx41KVrV2UOeNCx4jEBJbjGpsPFR 9hD3mrA8pmlOvwfCyK2NpRclgRPmJXtQBnbrDyo= X-Google-Smtp-Source: AGHT+IE/bi3w3zpNPCTrybF6dnZ1j+QWVO0sHylF2rnjFwMOfR6+iXwYbJnoqWVrpwekR3yHqaY0tQ== X-Received: by 2002:a05:600c:3b02:b0:408:389d:c22e with SMTP id m2-20020a05600c3b0200b00408389dc22emr2195298wms.25.1700340337186; Sat, 18 Nov 2023 12:45:37 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-250-157.bb.vodafone.cz. [86.49.250.157]) by smtp.gmail.com with ESMTPSA id o5-20020a05600c2e0500b003feea62440bsm7444153wmf.43.2023.11.18.12.45.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Nov 2023 12:45:36 -0800 (PST) Message-ID: <3c5ad91c-330a-0c5a-974a-da3801ffc18b@enterprisedb.com> Date: Sat, 18 Nov 2023 21:45:35 +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: long-standing data loss bug in initial sync of logical replication Content-Language: en-US To: Andres Freund Cc: PostgreSQL Hackers References: <20231118015443.sfxfbr4eqolxbmjc@awork3.anarazel.de> <20231118025445.crhaeeuvoe2g5dv6@awork3.anarazel.de> <49958b83-009a-9360-2969-ea42cd15fff7@enterprisedb.com> <20231118181257.qtebsnkrzj3icg36@awork3.anarazel.de> From: Tomas Vondra In-Reply-To: <20231118181257.qtebsnkrzj3icg36@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/18/23 19:12, Andres Freund wrote: > Hi, > > On 2023-11-18 11:56:47 +0100, Tomas Vondra wrote: >>> I guess it's not really feasible to just increase the lock level here though >>> :(. The use of ShareUpdateExclusiveLock isn't new, and suddenly using AEL >>> would perhaps lead to new deadlocks and such? But it also seems quite wrong. >>> >> >> If this really is about the lock being too weak, then I don't see why >> would it be wrong? > > Sorry, that was badly formulated. The wrong bit is the use of > ShareUpdateExclusiveLock. > Ah, you meant the current lock mode seems wrong, not that changing the locks seems wrong. Yeah, true. > >> If it's required for correctness, it's not really wrong, IMO. Sure, stronger >> locks are not great ... >> >> I'm not sure about the risk of deadlocks. If you do >> >> ALTER PUBLICATION ... ADD TABLE >> >> it's not holding many other locks. It essentially gets a lock just a >> lock on pg_publication catalog, and then the publication row. That's it. >> >> If we increase the locks from ShareUpdateExclusive to ShareRowExclusive, >> we're making it conflict with RowExclusive. Which is just DML, and I >> think we need to do that. > > From what I can tell it needs to to be an AccessExlusiveLock. Completely > independent of logical decoding. The way the cache stays coherent is catalog > modifications conflicting with anything that builds cache entries. We have a > few cases where we do use lower level locks, but for those we have explicit > analysis for why that's ok (see e.g. reloptions.c) or we block until nobody > could have an old view of the catalog (various CONCURRENTLY) operations. > Yeah, I got too focused on the issue I triggered, which seems to be fixed by using SRE (still don't understand why ...). But you're probably right there may be other cases where SRE would not be sufficient, I certainly can't prove it'd be safe. > >> So maybe that's fine? For me, a detected deadlock is better than >> silently missing some of the data. > > That certainly is true. > > >>> We could brute force this in the logical decoding infrastructure, by >>> distributing invalidations from catalog modifying transactions to all >>> concurrent in-progress transactions (like already done for historic catalog >>> snapshot, c.f. SnapBuildDistributeNewCatalogSnapshot()). But I think that'd >>> be a fairly significant increase in overhead. >>> >> >> I have no idea what the overhead would be - perhaps not too bad, >> considering catalog changes are not too common (I'm sure there are >> extreme cases). And maybe we could even restrict this only to >> "interesting" catalogs, or something like that? (However I hate those >> weird differences in behavior, it can easily lead to bugs.) >> >> But it feels more like a band-aid than actually fixing the issue. > > Agreed. > ... and it would no not fix the other places outside logical decoding. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company