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 1rpfdg-007uCy-KQ for pgsql-general@arkaria.postgresql.org; Thu, 28 Mar 2024 02:37:13 +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 1rpfdf-006hgj-Ib for pgsql-general@arkaria.postgresql.org; Thu, 28 Mar 2024 02:37:11 +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 1rpfde-006hbF-Gy for pgsql-general@lists.postgresql.org; Thu, 28 Mar 2024 02:37:11 +0000 Received: from fhigh5-smtp.messagingengine.com ([103.168.172.156]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpfda-006tCg-NS for pgsql-general@lists.postgresql.org; Thu, 28 Mar 2024 02:37:09 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2FE9811400C8; Wed, 27 Mar 2024 22:37:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 27 Mar 2024 22:37:05 -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=fm1; t=1711593425; x=1711679825; bh=HAe4M7/x+oYBC6oYu+pakHc2u4py0fHFueQWuYJyPPs=; b= JvgM1aWfGYvA0O0VRsYMAnMU8OWq7yij8OoWZCNPZkkP38aMq45YFpaNxX2VDcc0 SQ+W3hPljnh0VSMaOP0Kz7/KRPy5LlsV5VQzV8tk+cCA91w3q4xorAYo0YgpIMrG 6ax9wJFcIlS5AOfJwgWtgRbVTg45xgwpH3Ca7zY+U8YiTvdJiD/2gAfzEdpuIb0C jGB15khGb4Kh6Kf5yYaap+53eZLeS5tfQ3BD1awEvvNILToM0mN/wtIIiWNCGCLs Tu2rpi6vEXJE3i9RR67MBqYGpk36UIFg+5w6YtyJR+M1VK6YTjrlotK3exuM3cPS PqMKL/sOwEc+ioHbMOhfgA== 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=fm2; t=1711593425; x= 1711679825; bh=HAe4M7/x+oYBC6oYu+pakHc2u4py0fHFueQWuYJyPPs=; b=I OCSfIRLytSsug/cD4BZeID5+8i+2A9joB83Ag7bKJ854BsrwoHrqPXXPXfTCBX87 rOmMVgFyWiDB1jyeLTixlpetP3Vhg8viQnZiQ9eL0KVF0ta4Yt0W6b+FMXL/Jh4E QIgZih9sw1/Y8amTHjKiYTDQdfouY+XanNp5ggG/R0If4ids36rK0++pEcIbS7iP 5VCPUO+5ebhX0Aln2JcY73IdEcpHPwhGBn5luxTGOvW6IkkU3g2d2/CWbjYhGtC3 Ef/21OIggufgtRxMrNNc2aVCd5POcc07s7D/nwPAy+9xRNnm/Y7breHV6yXR573E q7xsOmY++89qPnd2NANjQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddukedggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelgeevkeekkeeuiefgtdevieeluefhfedufeetkeej ffekjeeujeehgeehgeektdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 22:37:04 -0400 (EDT) Message-ID: <437939a7-d804-46d2-97f3-555c7dfb9937@aklaver.com> Date: Wed, 27 Mar 2024 19:37:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: After 10 -> 15 upgrade getting "cannot commit while a portal is pinned" on one python function To: Jeff Ross , pgsql-general@lists.postgresql.org References: <6960da61-8033-4067-84d1-d9257ce94870@openvistas.net> <81c4556d-b599-4512-b6a2-7255f2a39089@aklaver.com> <37154728-4700-45b7-9261-72400c80b12b@aklaver.com> <133886.1710975858@sss.pgh.pa.us> <5ef96169-c11d-48de-b322-b7579bf56cc3@openvistas.net> <3446817.1711575877@sss.pgh.pa.us> <45d75f81-0be1-4990-97a7-5b4fa0e37c65@openvistas.net> <98d3484a-0ce1-4c74-85d4-c053652c5b9d@gmail.com> <6a744d62-f286-4166-93f6-71610db579ad@openvistas.net> Content-Language: en-US From: Adrian Klaver In-Reply-To: <6a744d62-f286-4166-93f6-71610db579ad@openvistas.net> 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 3/27/24 18:00, Jeff Ross wrote: > > On 3/27/24 17:35, Rob Sargent wrote: >> >> >> On 3/27/24 17:05, Jeff Ross wrote: >>> >>> On 3/27/24 15:44, Tom Lane wrote: >>> >>>> Perhaps "pinned" in the error message means "open"? >>>> No, it means "pinned" ... but I see that plpython pins the portal >>>> underlying any PLyCursor object it creates. Most of our PLs do >>>> that too, to prevent a portal from disappearing under them (e.g. >>>> if you were to try to close the portal directly from SQL rather >>>> than via whatever mechanism the PL wants you to use). >>>> >>>>> I added a cursor.close() as the last line called in that function and it >>>>> works again. >>>> It looks to me like PLy_cursor_close does pretty much exactly the same >>>> cleanup as PLy_cursor_dealloc, including unpinning and closing the >>>> underlying portal. I'm far from a Python expert, but I suspect that >>>> the docs you quote intend to say "cursors are disposed of when Python >>>> garbage-collects them", and that the reason your code is failing is >>>> that there's still a reference to the PLyCursor somewhere after the >>>> plpython function exits, perhaps in a Python global variable. >>>> >>>> regards, tom lane >>>> >>>> >>> Thank you for your reply, as always, Tom! >>> >>> Debugging at this level might well be over my paygrade ;-) >>> >>> I just happy that the function works again, and that I was able to >>> share a solution to this apparently rare error with the community. >>> >>> Jeff >>> >> My read of Tom's reply suggests you still have work to do to find the >> other "reference" holding on to your cursor. > > Yes, my read was the same. > > There are exactly 3 references to that cursor now that I added the > close() at the end. > > Here are the first 2 (cursor renamed from the code I posted): > >         plpy_cursor = plpy.cursor(schemas_query) >         while True: >             schema_rows = plpy_cursor.fetch(100) If the above is the complete while loop how you expect it to break out of the loop? Or did you do per Postgres docs?: https://www.postgresql.org/docs/current/plpython-database.html cursor = plpy.cursor("select num from largetable") while True: rows = cursor.fetch(batch_size) if not rows: break for row in rows: if row['num'] % 2: odd += 1 > > The last is: > >         plpy_cursor.close() > > I don't know how to proceed further. > -- Adrian Klaver adrian.klaver@aklaver.com