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 1rpcuQ-007dYk-P0 for pgsql-general@arkaria.postgresql.org; Wed, 27 Mar 2024 23:42:19 +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 1rpctR-004Vgk-P7 for pgsql-general@arkaria.postgresql.org; Wed, 27 Mar 2024 23:41:17 +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 1rpctQ-004Vgb-5I for pgsql-general@lists.postgresql.org; Wed, 27 Mar 2024 23:41:17 +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 1rpctL-006ruu-Mp for pgsql-general@lists.postgresql.org; Wed, 27 Mar 2024 23:41:15 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 75A981C000A2; Wed, 27 Mar 2024 19:41:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 19:41:07 -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=1711582866; x=1711669266; bh=dOQ9Qasm6+mLg38XS3G3OwvUae8BnUdstMndR6nonyc=; b= SNt+WOpM5s14hD13oUGDrhseI6rfV3NRQuDDEgDoRbYGHdz/GNw5Sevv3FPsl4I9 dHpMJ+q29tfI1FiMynYgRE2KLJo1DuPBHoYDI9PBAR60kCt8UajgmNorAirzkBy8 caBsqOmRMP4+jY6agyO1BzlYdRDpevYcs89HDDQgXWL5N2aNG1a+e/fAN1zWqpP1 N0YTyiPmD/DQqn4Z23TOsNWhKuxwQt3HKum34wigsmH1ld41i3VgPe6Uq3JzZK74 AfFjjQw7fJrHSgovThepCSlV/71sM3z5DFUrlyYliu9W+4Vo6YvM4OlXzUL2eS+P sDM0hJTsJigMx2HnwHWn6A== 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=1711582866; x= 1711669266; bh=dOQ9Qasm6+mLg38XS3G3OwvUae8BnUdstMndR6nonyc=; b=q wXhK/G+6wwBBJUGcL/RLQXLLT9q778wJgcLokFUUAWfbA2J8cUtjbwPDAGZgXnQJ 15ikHsvqa+E2ppy0Jl8y+E+GnIZU0y3xiTq/xdEobJv2U+n4u6GwULzu42i+cTDa RAR2PwHdezEq8Ad+Ogojq6kEsjFBHViQfTMPPaCoj06sfMX0pbHouD3PCllKRfnX C26pRwuI2pozNoX1waPkGXLCJqBfMBjYKIcz35n4KuwJ2VkD8XcYFSqQs568RozC kjhipePiiNX/rOfBz1zhLZx18UIU7DzWA+DlfpsBPcoeW+I7zjTBmxh7lso/KnZd gEdVUBxjZvO6ugjVGOaOQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddukedgudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthejredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeeivdfhieehheegueeileejieettdejhedugeefleek vdelkeehtdfgiefffeekudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 19:41:06 -0400 (EDT) Message-ID: Date: Wed, 27 Mar 2024 16:41:05 -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: Rob Sargent , 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> Content-Language: en-US From: Adrian Klaver In-Reply-To: <98d3484a-0ce1-4c74-85d4-c053652c5b9d@gmail.com> 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 3/27/24 16: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. I would start with: def logging(comment): global database <...> -- Adrian Klaver adrian.klaver@aklaver.com