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 1sH3JH-002XAZ-Mg for pgsql-general@arkaria.postgresql.org; Tue, 11 Jun 2024 15:21:20 +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 1sH3JF-007LCz-OE for pgsql-general@arkaria.postgresql.org; Tue, 11 Jun 2024 15:21:18 +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 1sH3JE-007LBP-7U for pgsql-general@lists.postgresql.org; Tue, 11 Jun 2024 15:21:18 +0000 Received: from wfout7-smtp.messagingengine.com ([64.147.123.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sH3JA-0017h3-Uh for pgsql-general@lists.postgresql.org; Tue, 11 Jun 2024 15:21:16 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id DF8C71C0008C; Tue, 11 Jun 2024 11:21:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 11 Jun 2024 11:21:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= 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=1718119269; x=1718205669; bh=dPExgRwmZ7925Gix300N4ZSxYJ1agF9LNjYj59xLTU4=; b= XVezlfJq1wp0iputCyQrTih3WSa9GmkPIkkTldAE2To5cnJk5z7nwekOKooXakp9 JYENSMts/o40wQYZJO5UNYIZpM8pnj0MYRe22TFulM0bSaxxyaBReWa1mYjby2zd mOYeuCSxHXgoUDW6NzxldOoN/74paf7rT3gHsc4fr9Yl4PTXZQ4pveNNgvKg4Q0q G0w1Apn74XBclyPt+19SAGA+LhYwIvtqmu4gFEs9x7rvstj/2JX1NJVGGWDwST16 buFq3Zmwy2U2m2e72UtMtgETQCci+rkEPxHG1zDaTVVcGbFkkJ1l2Xoo2CVDqUhn QmnZ1V82Y647xDT8w8VR8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1718119269; x= 1718205669; bh=dPExgRwmZ7925Gix300N4ZSxYJ1agF9LNjYj59xLTU4=; b=F XPpONMYhpH95oBeJOXIcIY/lLZSVFqAAxi8jIi/vDRvdLeHdwboNFR6O3ygZ3rp1 VP7QpQeedevYa4P3YnHArMnm6qi+rW85q0seshLE+uXSZ5Zrs+twkg0YsvOUy4NC SqUt9Ss6sg0uwhdzgRMFghadtaRfNxfGzylBZQ38H0kh9zrWx93cif1wKqphXljp VTG0LQJFbgl9m0YH8I8cOChtO0Gzm7G+f2j+SDgQtnbWulVclKWFcvGeB3Dfp3yd 8HuuaybNqQkgrdWKUKWRliKpn6iQnRkwpBHBrwPOes8+28I6DVq/XiYQr6K9EO0V o1Cc5Avp6YudXmoK3pbWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeduvddgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthejredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeekfeehuddvjeeigfeifeejtdduudffledvfeelheef tdeiffeugfdvkeelgedtvdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Jun 2024 11:21:08 -0400 (EDT) Message-ID: <55bb1667-4972-4704-9548-45afeab45aa5@aklaver.com> Date: Tue, 11 Jun 2024 08:21:07 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Unexpected Backend PID reported by Notification To: Dominique Devienne , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/11/24 08:05, Dominique Devienne wrote: > Hi. I have a unit test using a single connection, that simulates a > client interacting with a server via a PostgreSQL "queue", i.e. a > non-writable table with SECURITY DEFINER procedures to mediate writes > to that table, with those PROC-initiated updates triggering > pg_notify() messages (via an UPDATE trigger). > > The test is passing, I get all the side-effects and notifications I > expect. BUT... > For some reason, the backend_pid reported on the notification object > itself (i.e. PGnotify::be_pid), > is different from the one reported for the (sole) connection the unit > test is using (PQbackendPID()). > > How can that be? > Are Stored PROCs running in a different backend? > Are Triggers running in a different backend? > > Any doc pointers to explain this behavior? https://www.postgresql.org/docs/current/sql-notify.html "It is common for a client that executes NOTIFY to be listening on the same notification channel itself. In that case it will get back a notification event, just like all the other listening sessions. Depending on the application logic, this could result in useless work, for example, reading a database table to find the same updates that that session just wrote out. It is possible to avoid such extra work by noticing whether the notifying session's server process PID (supplied in the notification event message) is the same as one's own session's PID (available from libpq). When they are the same, the notification event is one's own work bouncing back, and can be ignored." Looks to me like are seeing the correct thing, a client session that is different from the server process. > > Thanks. --DD > > PS: v14 server on RedHat; v16 libpq on Windows > PPS: Below's a snippet of my test code, which shows actual PID values: > > auto perreq_notif = c.notification(); > BOOST_REQUIRE(perreq_notif); > BOOST_CHECK_EQUAL(perreq_notif.channel(), req.channel()); > /* > ** In fact I get perreq_notif.backend_pid() == N + c.backend_pid() !!! > ** Is the fact the pg_notify() is done from a trigger the reason??? > ** e.g. [4053957 != 4053955] > BOOST_CHECK_EQUAL(perreq_notif.backend_pid(), c.backend_pid()); > */ > BOOST_CHECK_EQUAL(perreq_notif.payload(), "..."); > > -- Adrian Klaver adrian.klaver@aklaver.com