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 1qipwC-00812w-2f for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Sep 2023 05:39:48 +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 1qipw8-00EZub-T0 for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Sep 2023 05:39:44 +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 1qipw8-00EZuF-Cf for pgsql-hackers@lists.postgresql.org; Wed, 20 Sep 2023 05:39:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qipw4-006Fp1-PF for pgsql-hackers@lists.postgresql.org; Wed, 20 Sep 2023 05:39:43 +0000 Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com [66.111.4.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 601FDE203CF; Wed, 20 Sep 2023 08:39:38 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1695188379; bh=JaoS5eXJfsPz1FJHoXYdlyM1za9XzWK6W2TBKV7EZFM=; h=User-Agent:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:From; b=PIr0X4f5wkKWs/D91Ck8RjuITaJvwC3Y80mx8RcxpbLuzLm7HaqAjfyoI4UNTM1GL cz6lw4DY8jvBSeXud6TYqgzPLqWfoOMU4OFLsgXZid6pUr2TGVLNbSDDeh/X1saCNb cNmbAoVNPxpLKD23AGEpEC1UYQjK6Ueryr9h9qsAeBqSvrRaEw2x7VTsIR4Q665MeE daG5P7NA5Jw13ytkzw/r8Tv9kCgcGoM/OkLz5VV5f5+GPv7mO1qnKiwLyHZ71yHJ+M izrVCdCe/4pc9lGOju6AuYg7+T+dY8m/Esp36IVvljz/IesnLvc5nfDn4kOWzHG+a1 G86qUryiCww2g== Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id C42F427C0054; Wed, 20 Sep 2023 01:39:35 -0400 (EDT) Received: from imap44 ([10.202.2.94]) by compute1.internal (MEProxy); Wed, 20 Sep 2023 01:39:35 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekvddgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedfnfgv phhikhhhohhvucetnhgurhgvihdfuceorgdrlhgvphhikhhhohhvsehpohhsthhgrhgvsh hprhhordhruheqnecuggftrfgrthhtvghrnheptedtleetleegudekhfeguedvgeeuudef tdejgffgteevkeeghfegkedvveehgeehnecuffhomhgrihhnpehgihhthhhusgdrtghomh dpphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheplhgvphhikhhhohhvodhmvghsmhhtphgruhhthhhpvghrsh honhgrlhhithihqddufeelgeehudejhedvqdeftddtiedtkeefvddqrgdrlhgvphhikhhh ohhvpeepphhoshhtghhrvghsphhrohdrrhhusehfrghsthhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ie8b149e1:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id E3E7836A0077; Wed, 20 Sep 2023 01:39:34 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-761-gece9e40c48-fm-20230913.001-gece9e40c MIME-Version: 1.0 Message-Id: <43bc4f5a-2fdc-46c8-ba4f-77ec5d7485e5@app.fastmail.com> In-Reply-To: <8068eb19f732169a1a79fdeadf104adf@oss.nttdata.com> References: <3bb7bacbc5ef9e58e2ece0557adac98b@oss.nttdata.com> <03c8dcbb-72d2-d3ad-3ad1-9efe69676529@oss.nttdata.com> <20220208.171852.1699766364147189900.horikyota.ntt@gmail.com> <3e94e9b3-83ef-c328-0c5c-f93aa3224790@oss.nttdata.com> <3d121ed5f81cef588bac836b43f5d1f9@oss.nttdata.com> <379d69c0b3d058997550f88e73ffddd6@oss.nttdata.com> <727712bcaa8d449615820c16d15e452e@oss.nttdata.com> <598171663576373@mail.yandex.ru> <38f4e19323b264e5975c60010b512b15@oss.nttdata.com> <20221206184101.exj2zyhmt7ta5fco@awork3.anarazel.de> <2f466f82de025f745dff9377a368cee4@oss.nttdata.com> <788e5db60b6c5de4b73fc9810b635d44@oss.nttdata.com> <9c3445ab0f695dbd0a879cf380f313c5@oss.nttdata.com> <00dac323d6732d59ba2c03be729966dc@oss.nttdata.com> <4e1e4e5d022964953e84468fe4e511b0@oss.nttdata.com> <4af7712833d4ce989cf5e658106e42da@oss.nttdata.com> <8068eb19f732169a1a79fdeadf104adf@oss.nttdata.com> Date: Wed, 20 Sep 2023 12:39:13 +0700 From: "Lepikhov Andrei" To: torikoshia Cc: "James Coleman" , "'Andres Freund'" , pgsql-hackers@lists.postgresql.org, "Greg Stark" , "Ronan Dunklau" , david.christensen@crunchydata.com, "Heikki Linnakangas" Subject: Re: RFC: Logging plan of the running query Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Sep 19, 2023, at 8:39 PM, torikoshia wrote: > On 2023-09-15 15:21, Lepikhov Andrei wrote: >> On Thu, Sep 7, 2023, at 1:09 PM, torikoshia wrote: >> I have explored this patch and, by and large, agree with the code. But >> some questions I want to discuss: >> 1. Maybe add a hook to give a chance for extensions, like >> pg_query_state, to do their job? > > Do you imagine adding a hook which enables adding custom interrupt codes > like below? > > https://github.com/postgrespro/pg_query_state/blob/master/patches/custom_signals_15.0.patch No, I think around the hook, which would allow us to rewrite the pg_query_state extension without additional patches by using the functionality provided by your patch. I mean, an extension could provide console UI, not only server logging. And obtain from target backend so much information in the explain as the instrumentation level of the current query can give. It may make pg_query_state shorter and more stable. >> 2. In this implementation, ProcessInterrupts does a lot of work during >> the explain creation: memory allocations, pass through the plan, >> systables locks, syscache access, etc. I guess it can change the >> semantic meaning of 'safe place' where CHECK_FOR_INTERRUPTS can be >> called - I can imagine a SELECT query, which would call a stored >> procedure, which executes some DDL and acquires row exclusive lock at >> the time of interruption. So, in my mind, it is too unpredictable to >> make the explain in the place of interruption processing. Maybe it is >> better to think about some hook at the end of ExecProcNode, where a >> pending explain could be created? > > Yeah, I withdrew this patch once for that reason, but we are resuming > development in response to the results of a discussion by James and > others at this year's pgcon about the safety of this process in CFI: > > https://www.postgresql.org/message-id/CAAaqYe9euUZD8bkjXTVcD9e4n5c7kzHzcvuCJXt-xds9X4c7Fw%40mail.gmail.com I can't track the logic path of the decision provided at this conference. But my anxiety related to specific place, where ActiveQueryDesc points top-level query and interruption comes during DDL, wrapped up in stored procedure. For example: CREATE TABLE test(); CREATE OR REPLACE FUNCTION ddl() RETURNS void AS $$ BEGIN EXECUTE format('ALTER TABLE test ADD COLUMN x integer;'); ... END; $$ LANGUAGE plpgsql VOLATILE; SELECT ddl(), ... FROM ...; > BTW it seems pg_query_state also enables users to get running query > plans using CFI. > Does pg_query_state do something for this safety concern? No, and I'm looking for the solution, which could help to rewrite pg_query_state as a clean extension, without patches. >> Also, I suggest minor code change with the diff in attachment. > > Thanks! > > This might be biased opinion and objections are welcomed, but I feel the > original patch is easier to read since PG_RETURN_BOOL(true/false) is > located in near place to each cases. > Also the existing function pg_log_backend_memory_contexts(), which does > the same thing, has the same form as the original patch. I got it, thank you. -- Regards, Andrei Lepikhov