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.96) (envelope-from ) id 1w9fs9-001dga-2p for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 09:03:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9fs6-007Nqp-0q for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 09:03:50 +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.96) (envelope-from ) id 1w9fs5-007Nqg-2m for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 09:03:50 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9fs3-00000000sDx-1NCL for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 09:03:49 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-43cfde3c3f3so3618641f8f.3 for ; Mon, 06 Apr 2026 02:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1775466226; x=1776071026; darn=lists.postgresql.org; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=RXHoWulSIG9e5fCsBGYe27FXeLTJ4hrrm37KR+1FXeo=; b=QHH8Bp32Np7gSlf3QWRSJ1wTRslJ632YWSZELkMqfcgEoJjBCm6UOKzka6i2V9uOUR JZaXpGgN8X9M4g7yINHTWs4DWfmFe4/EKOtW2URHx4MuegrNoLihQhBvdFpFBIVTM2yb WSdI7wlJOO3uNHNNUGwaVvjUF2fho/RnKFCtFEMgYbG938dOzP3SOx8mjfBsgLaVwGHL pLKs++q9edYaPrGr84MLUlH2ItfeHF0BRkKOtoFxTV8OrjfWydsnepEah5sqcYHke3/I Su/+0cbyxD2Y9DLRsGoA7WLQP26OnOCK6EfLH2R2h51AtK/7k/YYMa4Cp0buZhN3Sjx/ DdPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775466226; x=1776071026; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=RXHoWulSIG9e5fCsBGYe27FXeLTJ4hrrm37KR+1FXeo=; b=IRW9F8bgC0XOTHiramEEJ8VHmhsU8qAXtVSe1uHNbKe3RESVr0DJ0OxC/ESAg2rH9H XcvgP9ppkj1Q8HDmxad+qkpn1GtAqdGo4oV78cAuVujyaQuIb/GBQ7rIAsvCum4ioMEv Lhi9IbBi/yjk7DG5hvwfEdcN8gSq6ZhmslwKgy9u80dEHsSg5ULK5QSwjBElmDuiThbr ItkTLsJbUTbo+sojXrvX+dnI/GGOfOrGDdj/fHwQP5Hs7L8xjn7AmyPsk7UsM4bX+DxB h97C3jz1s+8bYMGuxp290wdtDDNjrQ5p2zaueeH8PBRk121yPGHKsUgXnD2Y8Dg6pF2d 9KeQ== X-Forwarded-Encrypted: i=1; AJvYcCVj607M/SLb2QVnMOeqgg9yJ29lAzI+PdhU82UJCNGTmrHhVmfQaeJLv8JLQ2HJi3AOpEO9C9TBCF4T6Hsh@lists.postgresql.org X-Gm-Message-State: AOJu0YylH5MKeS9vObqpkto9l1FH+h1yFUbwwTg9SpHPphYlcaQj1YxK t7wtFlVX1zJ4rP4Uq0gWKGQQzSkCmp66tjBZ1YPcFZBsas1J+oxYq+yn/elzBagqOn8= X-Gm-Gg: AeBDieux3F+obnmCsFhRh+U2yXfkf5R3kpDq4ATs9XR3DPr5mG4/wKhqQUCL6mcgaYQ ByCZttcZ98RwRfHUsr3xSzQXeqHOnjDS9USftZVybKNj46xTIa4v7Q0nOcIld1OzGjSoBpa/EfB ak5yPTwT6RnxeuI5El2rV3A9c8ZZhQO02/dzsVwMX89kwCHR0EKGt9lckvsd4sXgUHyWARDe/Wj /i/eGHvoam2KNNmv+8y8JX8sk4IMOpeUULoT4koKwAO8HVN5BjVVZGyjP/dhbEy8WnCSBRcD8As RGqnn5bhviiJpsP2RQXLzVbBZprfU75LHGU6cIFkENiHuJY+CiIZotw4f1sW3pZcrEG0hCIQXM/ mNmUnvIO+yM6cHDWzBqv0txnCKyXAZJVwu09HFl3DoU/LY2/PS8K+nuuCSYXuAQAOfGm6nLBNoX 59nhXtwd4MZXVTlGizzGDxW6aVN6Pyx9up3ogEGUuOSiXoxDQ= X-Received: by 2002:a05:6000:2512:b0:43b:47bc:c147 with SMTP id ffacd0b85a97d-43d292fee54mr18524717f8f.45.1775466226144; Mon, 06 Apr 2026 02:03:46 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e4d58e5sm40148232f8f.23.2026.04.06.02.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2026 02:03:45 -0700 (PDT) From: Antonin Houska To: Alvaro Herrera cc: Srinath Reddy Sadipiralla , Amit Kapila , Mihail Nikalayeu , Matthias van de Meent , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: <202604051852.qfdnfvemfkd2@alvherre.pgsql> References: <202604051852.qfdnfvemfkd2@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Sun, 05 Apr 2026 20:56:16 +0200." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Mon, 06 Apr 2026 11:03:44 +0200 Message-ID: <82004.1775466224@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Alvaro Herrera wrote: > So I've been trying to understand the "Introduce an option to make > logical replication database specific." patch and I have to confess I > just cannot. > > As far as I can read, the point is that if we reach > SnapBuildProcessRunningXacts() when db_specific is true (which means > standby_decode is called in an output plugin that has set > need_shared_catalogs to false), _and_ we've not reached consistent state > yet, then we'll call LogStandbySnapshot with our DB oid to emit a new > xl_running_xacts message. Right. > So the WAL-decoding process emits WAL. I don't know if in normal > conditions logical decoding processes emit WAL. If this is exceptional, > I think we should add a comment. Emitting WAL in logical decoding is not exceptional: SnapBuildWaitSnapshot() already calls LogStandbySnapshot(), in order to get to the next phase. > Now, this additional WAL message will be processed by all other > processes decoding WAL. Perhaps it will ignored by most of them. Right. That's one thing that I realized late yesterday, after having posted the latest version of the patch. In SnapBuildProcessRunningXacts(), we need if (OidIsValid(running->dbid)) return; rather than if (db_specific) return; because other backends can also generate their database-specific records. > But > most importantly, it will also reach back to ourselves, at which point > we can hopefully use it to see that we might have reached consistent > state within our database. Then we know our snapshot is ready to be > used. > > Is this correct? Yes. > I think the reason it's safe to skip a lot of the processing caused by > this additional process, is that xl_running_xacts messages are also > emitted in other places in a non-database specific manner. So all the > other placecs that are emitting that message continue to exist and > cause logical-decoders operate in the same way as before. Yes. I'm still thinking though if, after having used the database-specific record to reach CONSITENT, we sould enforce one cluster-wide record, so that the cleanup (in "our backend") takes place sooner rather than later. Not sure about that. > I think we should sprinkle lots of comments in several places about > this. For example, I propose that standby_redo() should have something > like > > * If 'dbid' is valid, only gather transactions running in that database. > + * Such records should not be the only ones emitted, because this has > + * potentially dangerous side-effects which makes some places ignore them: > + * > + * 1. SnapBuildProcessRunningXacts will skip computing the xmin and restart > + * point from its input record if the record's xmin is older that the > + * snapbuilder's current xmin; this should normally be fine because that > + * information will be updated from other xl_running_xacts records. > + * 2. standby_redo will likewise skip processing such a record > * > (are there other things that should be mentioned?) I added something like that, but - due to the reference to SnapBuildProcessRunningXacts() - less verbose about snapbuild.c. > Also, LogStandbySnapshot() should have a comment explaining that passing > a valid dboid is a weird corner case which is to be used with care, and > that functions X Y and Z are going to ignore snapshots carrying a valid > dbid. One more check added in standby_decode() (and mentioned in that function in the comment). > Why do we call SnapBuildFindSnapshot() to do this, instead of doing it > directly in SnapBuildProcessRunningXacts? Seems like it would be more > straightforward. Yes, fixed. One more problem I found when testing w/o background worker (contrib/test_decoding) was that accessSharedCatalogsInDecoding was not set back to true. Both AllocateSnapshotBuilder() FreeSnapshotBuilder() do that now. -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=nocfbot.v53-0001.3-Introduce-an-option-to-make-logical-replication-.patch