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 1uHUGS-0039Z4-QT for pgsql-hackers@arkaria.postgresql.org; Tue, 20 May 2025 21:12:45 +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 1uHUGR-009EoQ-NX for pgsql-hackers@arkaria.postgresql.org; Tue, 20 May 2025 21:12:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uHUGR-009EoG-AL for pgsql-hackers@lists.postgresql.org; Tue, 20 May 2025 21:12:43 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uHUGP-0000Oq-0A for pgsql-hackers@lists.postgresql.org; Tue, 20 May 2025 21:12:42 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2322dc5c989so20183605ad.3 for ; Tue, 20 May 2025 14:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1747775560; x=1748380360; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=ijAOyoedInWgoWjWP7/cCWaWIOvdTHQiZ6PjfYzrgU4=; b=sWrmLoeVhfKaidW403tMM0ry3g6/5jNYWOeyC/JSB4ZtIZBXQtVy3jBlpVEJeJ4MXg cv91Y12XxYysWRze3Z3zWdGYxm6qwCeq8oke7ghbzD20BiuLPk3ljMJIJLRDpE2yKjz4 uM//gRBwD21u8mN6iwpzBHs2Qfy+rypoXPWwss3Q/8Isoe+PqCjNq6CWHq++WQISLOBQ PShpKiUR6eO9t+zXmRRXUB4KSsv2jypJTXWAEgKcpu+cMVfIyOKwv+/UFeotHs2dAmKG QDz9M/VRKeDNN8Aqqf0cM8Hf9lHy8gY4oOmVNTEdSINYHg9kfiDYy9CesNVyLPomN9uk 46wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747775560; x=1748380360; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ijAOyoedInWgoWjWP7/cCWaWIOvdTHQiZ6PjfYzrgU4=; b=VJ0i/SkZad/kz4KnI/3I7ErCHfvW/SODaeBeJnzccGYKiWIykzzkghN25BhyN1xy3F bTJLB2EhzXXy5vG6lo6hT2fbohxYYxslE05DZ5MzSUm2IawWFobo68qhg8mSfPSGYmMS x75fBaJKxeORdpnPu1nRzv8RbAMi1fobF8cZkklT4lPqoh6gxBknynIJRYOMFOncxHrF nA0gZeZ2Bb6n+TuCZR3aS0jpTFzuulkRa0C3lyZc2DxvicLie4gVzCvthCQOaBkN4+2A Xq3Fgbh7XXCysgotvYbRPwoeS+d77YhVBajPc/JqNnE3NNweIoSRdjgQ1NCVrY6SM288 XeRg== X-Forwarded-Encrypted: i=1; AJvYcCVWDvCJMY5c8dP8Fz2UGPv6H9S8pfC9yasiQ3/BvzKrLnhYRe1aWyJkO/H8RxNuBxYvz/BQ/RCpOoPRmLJZ@lists.postgresql.org X-Gm-Message-State: AOJu0YwaLTaSzGv9wIreBScrA4mDDlgdY4TdGtcdd/N8ps2pa71YYZyp em6yOlJ38QEKVbvc4TeqfkXM6HNDtjWQovH+K9mcRsBvDauDcwdrgulsXzHNz4KIxg== X-Gm-Gg: ASbGncsm7AAjbsUVhh/PTBGl9g2/Yp3sNeB/i3+0gWTyio/sV/bq4l9WrIwi71L16+Q OjF+nzXCm5n0WOHY15EVS9AuMQ9sPrJTN8sDD6LJN61k5fOIhOxmK1PSUe1T01nyAetNIrxVCTW SDyVj5+IpcLwuBEthkPH8+bKPWfaPKsk8d9rcB8Lgk7269fwBb8MIOqlvySLxvLj5tB8D16MeNN W/0vWlPr+qlTcrglcCLCN/Nd5E0JrtQUzngyc4XlfBpmiFld5rnGZQRhLGT3ziMoHQFtKFtw2lH Sw926ZjxX+7f+SuUSmFZ52bCBEfmz0U1f0hwskjmOp34sZZadJ3c4g74jQ7n8g== X-Google-Smtp-Source: AGHT+IEA0APJbFFnrI6v7dxEsJX28xYejB3Hr+KGzu4axfvLNdcs01czPoYH7uaPGsd/SJX3e8or4A== X-Received: by 2002:a17:903:faf:b0:224:160d:3f5b with SMTP id d9443c01a7336-231de37ec9bmr228674285ad.49.1747775560310; Tue, 20 May 2025 14:12:40 -0700 (PDT) Received: from [172.24.2.37] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-231d4ebaf5esm81244035ad.194.2025.05.20.14.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 14:12:39 -0700 (PDT) Message-ID: Subject: Re: Avoid orphaned objects dependencies, take 3 From: Jeff Davis To: Robert Haas Cc: Bertrand Drouvot , Michael Paquier , Alexander Lakhin , pgsql-hackers@lists.postgresql.org, Tom Lane Date: Tue, 20 May 2025 14:12:41 -0700 In-Reply-To: References: <62310067-6dc4-97ab-6724-7d3602b5056d@gmail.com> <403075e1-4d60-09e2-a06a-749cd9d88f66@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2025-05-19 at 14:07 -0400, Robert Haas wrote: > I agree with that, but I think that it may also be error-prone to > assume that it's OK to acquire heavyweight locks on other catalog > objects at any place in the code where we record a dependency. I will > not be surprised at all if that turns out to have some negative > consequences. For example, I think it might result in acquiring the > locks on those other objects at a subtly wrong time (leading to race > conditions) or acquiring two locks on the same object with different > lock modes where we should really only acquire one. I'm all in favor > of solving this problem using heavyweight locks, but I think that > implicitly acquiring them as a side effect of recording dependencies > feels too surprising. I see what you mean now, in the sense that other code that calls LockDatabaseObject (and other variants of LockAcquire) are mostly higher-level operations like AlterPublication(), and not side-effects of something else. But relation_open() is sort of an exception. There are lots of places where that takes a lock because we happen to want something out of the relcache, like generate_partition_qual() taking a lock on the parent or CheckAttributeType() taking a lock on the typrelid. You could say those are fairly obvious, but that's because we already know, and we could make it more widely known that recording a dependency takes a lock. One compromise might be to have recordDependencyOn() take a LOCKMODE parameter, which would both inform the caller that a lock will be taken, and allow the caller to do it their own way and specify NoLock if necessary. That still results in a huge diff, but the end result would not be any more complex than the current code. Regards, Jeff Davis