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 1tuQT3-008OKo-3e for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Mar 2025 06:30:25 +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 1tuQT0-008juq-QK for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Mar 2025 06:30:22 +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 1tuQT0-008jui-Fs for pgsql-hackers@lists.postgresql.org; Tue, 18 Mar 2025 06:30:22 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tuQSx-003SFF-0Z for pgsql-hackers@lists.postgresql.org; Tue, 18 Mar 2025 06:30:20 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-22423adf751so87838785ad.2 for ; Mon, 17 Mar 2025 23:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742279418; x=1742884218; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=U/Aco9ePnfcdqy0bkGg85yqKjdCfWSy3WrfSjWlhd1U=; b=Tt0N9R1XlWg4+L/yjA42o7OHxj9fNu+c7ZTDCYTliGgePVqUkDiliqFyGAkvuIgvkC jEL/1sH4nZzOTktLgDE7tKfyJ6PfqExVWc1oPrWVdU/T+2VM3F3R5NQL8p/OcMim7xUh CCnywhIpjeeFUtrhPXhaXkzVlHnNkWH177UWy7My4cvMawTe0G0YXiu6h79amf8KGWEb NgEa4sL5dLIINnta+pVVdITMvWf9QJuxblRXwc2H7LQITPEg/1fcGRHhZQRaDmiy1w9k AmVdKmsYnubDmwfIsl9u+KHa+AXn27YMZRCQG4nquV0PCkmN1I0yCzH0R0CvUfqRxXmU ZjIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742279418; x=1742884218; h=content-transfer-encoding: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=U/Aco9ePnfcdqy0bkGg85yqKjdCfWSy3WrfSjWlhd1U=; b=beTZ1bGRWlXgwqGAdU0FqIWKj5e29D6EnTsOv0y0+3VBkMCSx4t+e+aXF8FZbCM74R 9U/YvO7m4W2L+u3iNwzXf34JSEWnpQm+G3iiy61IL/eSJja9xK7jpZn0fcbOHKbxWiYG oBaGw5V4t8xVK8PoE+82709TKsVAWnM1UBznBfDgB7sl3vSxkxLlEjk1YbcrhXWEDku2 X+rmTJjtf871czRbmv6oykzEP793UQosNE00s0HM7eKvZIlBbwwmR0PohOjbODknNKf5 qHbHLiQFy1I2QHfSi+1INNtwgdPRrGRL3xNIEOC0IQEZmtZe4+A8vJSjz704YRvWEQ2h +bpQ== X-Forwarded-Encrypted: i=1; AJvYcCXucDrliKktF8H90Ys8xlJmUHczwXX2KGC9Bxqgsk/sM0FhLfn2RwmE8zhlQIzEv9hXvTOS0oehlMBYURsa@lists.postgresql.org X-Gm-Message-State: AOJu0Yx1IW0fvH6a5NOh67RR2qzpkNlJsXwfxEAER9yOmcQHE3ToKSUH MfNaj9T8Xvircpw5beC4cWEsGCBLU7zfYfugfkK4Eq2oJjdxne63hKeR/irCY87cST4ItB12LH+ I3Gjm0+kiWqs5oj3SpKrUEv12Lt0= X-Gm-Gg: ASbGncsuXSiMPxovtzg8yLMPzsb22JetPWoxfQaIU7JN1GOFUk8Uji+ewAQQO1hBX0x VrtBti27g/r7ynY5iDmX5ijf8QSOCmwreRSQD4YR4EC+CxZbhc5TYGhVV7xP588eO5J6lSYfE82 E+vE9GSSOKZRwVK+FKPugNRZ7NlA== X-Google-Smtp-Source: AGHT+IEhtssuvyIEEVqBpEac6BG2EY0emZPXO1aIGZZTjWtEyLZQn7OW67ZuQDxkUPB7CNRMEpgSF3C8SANTegrWamA= X-Received: by 2002:a17:903:2f89:b0:223:7006:4db2 with SMTP id d9443c01a7336-225e0a93e74mr181640975ad.31.1742279417916; Mon, 17 Mar 2025 23:30:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Tue, 18 Mar 2025 12:00:04 +0530 X-Gm-Features: AQ5f1JoCEsIoi4xQzkoWHWtQxPx_F83jUYifBl1ZwZRWZdbuxGdlw88hY8IM8SU Message-ID: Subject: Re: pgsql: Avoid invalidating all RelationSyncCache entries on publication To: Robert Haas Cc: Amit Kapila , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 17, 2025 at 9:35=E2=80=AFPM Robert Haas = wrote: > > On Thu, Mar 13, 2025 at 12:00=E2=80=AFAM Amit Kapila wrote: > > Avoid invalidating all RelationSyncCache entries on publication rename. > > > > On Publication rename, we need to only invalidate the RelationSyncCache > > entries corresponding to relations that are part of the publication bei= ng > > renamed. > > > > As part of this patch, we introduce a new invalidation message to > > invalidate the cache maintained by the logical decoding output plugin. = We > > can't use existing relcache invalidation for this purpose, as that woul= d > > unnecessarily cause relcache invalidations in other backends. > > This seems like too much infrastructure for a niche optimization. If > there are plans to use this new invalidation message type to optimize > a bunch of other cases, then maybe it's worth it, but adding this just > to cover the presumably-rare case of ALTER PUBLICATION .. RENAME > doesn't seem worth it to me. > This commit will be helpful for many other existing commands like: CREATE PUBLICATION ... ALTER PUBLICATION name SET (publication_parameter) ALTER PUBLICATION name OWNER ... DROP PUBLICATION ... Before this, commit any publication command that modified pg_publication catalog use to invalidate the entire RelationSyncCache. The code that led to entire RelationSyncCache invalidation was removed in this commit: publication_invalidation_cb(Datum arg, int cacheid, uint32 hashvalue) { publications_valid =3D false; - - /* - * Also invalidate per-relation cache so that next time the filtering i= nfo - * is checked it will be updated with the new publication settings. - */ - rel_sync_cache_publication_cb(arg, cacheid, hashvalue); } We can't remove this without having a solution for ALTER PUBLICATION .. RENAME command to invalidate the specific RelationSyncCache entries. As mentioned in the commit message, the other idea was to register a relcache invalidation for all relations that are part of a publication which we felt could be harmful to other backends that are not even involved in decoding. Now, the ALTER PUBLICATION name OWNER command doesn't need to use this new invalidation at this stage because it doesn't impact the RelationSyncCache entries but it benefits from not requiring to invalidate the entire cache. Similarly, the other commands mentioned above uses relcache invalidation for this purpose but the difference is that the other commands do need relcache invalidation for the purpose of correctness whereas ALTER PUBLICATION .. RENAME command doesn't need it. In the future, we can use this invalidation in existing publication commands like altering a publication where we only publish 'INSERT' (and or 'TRUNCATE') and change other publication properties like 'publish_via_partition_root', 'publish_generated_columns'. Similarly, I think we can even use new invalidation for SET/ADD/DROP variants of Alter PUBLICATION where the publication publishes only 'INSERT' and or 'TRUNCATE'. Before this commit, we didn't have a better way so we used relcache invalidations for these cases as well. Also, any new publication property or command should prefer to use this new invalidation instead of using a relcache invalidation unless required the same for correctness. The impact of not doing any solution for this problem (aka removing the above code in publication_invalidation_cb) could be magnified in future commits where we are trying to solve a long-standing data loss issue in logical decoding/replication via distributing invalidations to all in-progress transactions [1]. You can read the commit message to understand that problem and solution. I think I should have mentioned the future use and other improvements of this work in the commit message. [1] - https://www.postgresql.org/message-id/OSCPR01MB14966DDB92FA7DA8FA8658= 216F5DE2%40OSCPR01MB14966.jpnprd01.prod.outlook.com --=20 With Regards, Amit Kapila.