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 1shagD-004bdP-On for pgsql-general@arkaria.postgresql.org; Fri, 23 Aug 2024 20:14:42 +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 1shagA-00GwuF-E8 for pgsql-general@arkaria.postgresql.org; Fri, 23 Aug 2024 20:14:38 +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 1shag9-00Gwu6-01 for pgsql-general@lists.postgresql.org; Fri, 23 Aug 2024 20:14:38 +0000 Received: from fhigh1-smtp.messagingengine.com ([103.168.172.152]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1shag6-0016xV-Cb for pgsql-general@lists.postgresql.org; Fri, 23 Aug 2024 20:14:36 +0000 Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5DC121146CF3; Fri, 23 Aug 2024 16:14:33 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 23 Aug 2024 16:14:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1724444073; x=1724530473; bh=oKeoJAvPJe+IzCCBDl/uGCC/XfKVfVn/yUmF6KYpZCU=; b= p+x6k2Y+Mhq1jI/i5cDkJKXoY0KIxLpEnd+mO5RPstExozeiJDB1JBi9EhWmfKEs 6fi5dTDCPyB9Qg62EMp21ZNxSD4TPRzKhyaSjRiloaKRTg/dbuNfZDt4Ae55jEHX 0Qo6yjoOpULrzCcFuYgA7zkaMyTVqdPSkvOb7nRg/WuClX+ueMcrdl0rSiK04yTe DnErD5lNmWJEqywEZUCeCNCuNePyduizVxC1EtbSCCTldE/nRYdF9WFc1UlGrybC PgOJj79h/u6c18rSnaU/H3OF1Y9Y8leu3lxzVxV2wun80Q//4/LYn0bGsobd5NJT a9nIz9HxymaWpubpKnqelw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1724444073; x= 1724530473; bh=oKeoJAvPJe+IzCCBDl/uGCC/XfKVfVn/yUmF6KYpZCU=; b=t VBOI3OPwBkkfLn8yNnAMv/7kW6GQc4AWGPzauWAhJK/j70UAEVcG0GBXoZKRHneP tvz38+ayqXezNSZkTnfIXqiP4T6TRhPtM0sr3pfMwyATQRl7iLbGf5pj1VKWbfX0 2+gtNAe1meFZWGAXH04e9Snxz+VNYoWDnJiDtpemB81dLppwLezSamyqGs3PMHKj WbWNFmoBa5wt4S65wEAD3oM8seJ91/BxvLhlITDvR9ggAIlfKARaHKlItcbznUHi EQOjqrM1oJy+/NKW//Lf9KkC+U3KG3WD2usdlEGJA/G3ay6WUpAsvk/8N0vCpWMc TBIe7cNoy6+8bgJx8XjFQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvvddgudegiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddv jeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpefgudefkefhveefleev ieeuveehvdduudekuddvvdelhfeuueeijedtuedvvedvueenucffohhmrghinhepphhosh htghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepkhgughdr uggvvhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlse hlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 23 Aug 2024 16:14:32 -0400 (EDT) Message-ID: Date: Fri, 23 Aug 2024 13:14:31 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: On a subscriber, why is last_msg_send_time in pg_stat_subscription sometimes null? To: Koen De Groote Cc: PostgreSQL General References: <65d55d32-c9c3-4446-a367-d3cca3282dea@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/23/24 12:31, Koen De Groote wrote: > Adrian, > > Thanks for pointing me at the source code. > > Digging a bit, the view seems to eventually get its data on last msg > send time from here: > https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/replication/logical/launcher.c;h=c566d50a072b92bd07f4179100275d0d0b1f4c7c;hb=HEAD#l1288 > > And in particular, this: > > 1332         if (worker.last_send_time == 0) > 1333             nulls[5] = true; > 1334         else > 1335             values[5] = TimestampTzGetDatum(worker.last_send_time); > 1336         if (worker.last_recv_time == 0) > 1337             nulls[6] = true; > 1338         else > 1339             values[6] = TimestampTzGetDatum(worker.last_recv_time); > > I don't have any knowledge of C, or postgres internals, so I may well be > wrong in what follows: > > From the bit of comment you posted my impression is that this means > there are separate workers that each send their update, that is then > reflected in the output of the pg_stat_subscription table... many > workers, but only 1 table to show metrics, to show both the update by > the leader and the parallel workers... This is getting out of my depth, but that has not stopped me before so onward. I think it is important to realize parallel workers are optional: https://www.postgresql.org/docs/current/sql-createsubscription.html streaming (enum) Specifies whether to enable streaming of in-progress transactions for this subscription. The default value is off, meaning all transactions are fully decoded on the publisher and only then sent to the subscriber as a whole. If set to on, the incoming changes are written to temporary files and then applied only after the transaction is committed on the publisher and received by the subscriber. If set to parallel, incoming changes are directly applied via one of the parallel apply workers, if available. If no parallel apply worker is free to handle streaming transactions then the changes are written to temporary files and applied after the transaction is committed. Note that if an error happens in a parallel apply worker, the finish LSN of the remote transaction might not be reported in the server log. > > And these parallel workers get created on the fly, I assume? So they > might well have a last_send_time of 0 if they haven't done anything yet? > > What I would expect to see is a table that tells me how a particular > publishers/subscriber is doing, and the metrics around that process, and > the concept of "when data was last sent" to be persistent on the level > of the publisher/subscriber, not based on the lifespan of ephemeral > workers that each time they get created start at 0 and so now the table > claims "last_send_msg" is NULL because of it. Some combination of?: https://www.postgresql.org/docs/current/view-pg-replication-slots.html https://www.postgresql.org/docs/current/catalog-pg-subscription-rel.html > > Am I getting that wrong? Is my understanding mistaken? > > Regards, > Koen De Groote > > -- Adrian Klaver adrian.klaver@aklaver.com