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 1rpcna-007d6i-BM for pgsql-general@arkaria.postgresql.org; Wed, 27 Mar 2024 23:35:14 +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 1rpcnY-004S31-CS for pgsql-general@arkaria.postgresql.org; Wed, 27 Mar 2024 23:35:12 +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 1rpcnX-004S2t-V4 for pgsql-general@lists.postgresql.org; Wed, 27 Mar 2024 23:35:12 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rpcnU-006rsd-Ua for pgsql-general@lists.postgresql.org; Wed, 27 Mar 2024 23:35:11 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1dee27acf7aso2796705ad.2 for ; Wed, 27 Mar 2024 16:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711582506; x=1712187306; darn=lists.postgresql.org; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=cse0DqYXXAjWhYNFnOoC55Z8eO/O3/vwwP2ZI27+KNY=; b=KoFyL9dtM9pnphse3jae8WkaiAXarNRVwFU6hm7th0HOl6qqyVyzJ622otnfNHTqWW C1Odjljz0nDeDN8HK8GX5wa1f/LKc23ClyBMZnszowC8whVZGYH1vRdyW/zcu7/CRVo4 K4040VtmAJGI1MK57ibsGNkB4amUtJ72qwYWIBs7ejIQc4NyCAdFYqWPYRJPjg9humNb XRxNqKLnvaZ3c3CcPrnI/AyIdv6fXPTI+3SCIfVABT0eiSN6JPKVpbPNKzkGAVeVKL4q /IJf9uoQB2q4ISvNg+ye8P41YLnlwz093vZIl0zbTBUpz5DfqqzxqrY8AaoMVzEp/u6S vLdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711582506; x=1712187306; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=cse0DqYXXAjWhYNFnOoC55Z8eO/O3/vwwP2ZI27+KNY=; b=l2kmvmqMJu58C6cYrEYVYvymIwWhEGiAz1FdN3lKT+jEKlpDP9oFM8TMzj1dCtgVba moRRmNac8K88CMnZ3DBKi2RGCZ3+i31Sl6Ak6l19wjD93Aj2yRPJSBCiVSVUJ6cnJqy0 yrjqlzx9+4xOx3OoPw3yvypGkhC86+R5fifY4sd+rPakpuoQsRALCjfN8Op6DM1huWt1 KfCm4b8fhQejaGKH7eEazgWamqNIffNn4g1rodp+CndAEX2Urp+PqF8b+coAc7MgmPIX EUWe3iP23CwjnpUCtVnuZfqsOGWaefHn8adu2BK/ksofaLdNrp8cV8pKw77Ow15iuuVH NEBA== X-Gm-Message-State: AOJu0YyMeZqHa/kfgnl0tWQXi41eW0OMl0yxYeEd2FSTSbkO83+MT0Wu kRc07OXaedAeZClAHedUgnUf7LJ6sYjv8t4sNn/NmzBjEKhmRn6JDmggBHO2 X-Google-Smtp-Source: AGHT+IE4Cp/N5N2SnQ5iaCchzjMVi3zWY9+oAmBs4+nGdHZL95x1Sjd9LQ0ytPTptQminPaVFkcReA== X-Received: by 2002:a17:902:d4cb:b0:1de:e5aa:5ce with SMTP id o11-20020a170902d4cb00b001dee5aa05cemr1358109plg.41.1711582505459; Wed, 27 Mar 2024 16:35:05 -0700 (PDT) Received: from ?IPV6:2601:681:5a00:f790:9e86:29da:8080:70fd? ([2601:681:5a00:f790:9e86:29da:8080:70fd]) by smtp.gmail.com with ESMTPSA id a17-20020a170902ecd100b001e20ac508a3sm83911plh.280.2024.03.27.16.35.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Mar 2024 16:35:04 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------NAA1Z9snOSb4Imy0syYzgY0v" Message-ID: <98d3484a-0ce1-4c74-85d4-c053652c5b9d@gmail.com> Date: Wed, 27 Mar 2024 17:35:03 -0600 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 Content-Language: en-CA To: 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> From: Rob Sargent In-Reply-To: <45d75f81-0be1-4990-97a7-5b4fa0e37c65@openvistas.net> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------NAA1Z9snOSb4Imy0syYzgY0v Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------NAA1Z9snOSb4Imy0syYzgY0v Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

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.
--------------NAA1Z9snOSb4Imy0syYzgY0v--