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.98.2) (envelope-from ) id 1xSyVl-000000000RB-1JXU for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Nov 2026 15:20:50 +0000 Received: from localhost ([127.0.0.1]:53100 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xSyVk-00000001q9L-36Bg for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Nov 2026 15:20:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:49178) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xReZR-00000005p5t-0Ir8 for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 23:51:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xReZO-00000000lE8-1wfn for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 23:51:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=BbQvRHNDIEufdmSYgiyVjuF9MdI1OaBGKO0Q5FP8crc=; b=TZR93S72w/40T0rRPqki2aMhqi g89Uy8rmMXCJuHxXOpVOWmpz0sddz8wm5b17+QczNfOETuDx48Jgp3QtyI5UORWJBUlvttQNdKi/l iXjMwR5QcpWDbfvLzHLfa906rxejv8zJHLaSBYghIy61mk4tCh8OpEOcNkur/7RNbwxyAcUs7UzLh HF7FC2VaXZTtiIVvCfAcQQnrW5ZKJMydnWh+ASNZFcNJ9b/Ucy0+Mllm0U8n7eAHnAVBTkvm+QWzL WhMsHgNHLFwBSaTKaomd/NlHNojzCtU99jmWuLKFZY7C0fthqFrv741bhhlNGDzMeTpBcIVJVWZ+H Kh/oNP/g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xReZM-00000001jnW-3Uiz for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 23:51:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xReZM-00000004NAJ-0N5V for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 23:51:04 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19899: PL/Python backend crashes (SIGSEGV) when converting a column value to a Python object fails To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: marcos.castedo@anachronics.com Reply-To: marcos.castedo@anachronics.com, pgsql-bugs@lists.postgresql.org Date: Thu, 12 Nov 2026 23:50:19 +0000 Message-ID: <19899-3e21845d988f0c0f@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19899 Logged by: Marcos Castedo Email address: marcos.castedo@anachronics.com PostgreSQL version: 19rc2 Operating system: Debian GNU/Linux (x86_64) Description: =20 When the conversion of a column value to a Python object fails inside Python, the backend terminates with signal 11 and the postmaster restarts all sessions. The expected result is an ERROR in the calling session. The steps below read a row with plpy.execute and make the conversion of one column fail on demand by starting the server with a lower memory limit; the limit is only a way to trigger the failure. The conversion is done by PLyDict_FromTuple, which also builds row arguments and TD["new"]/TD["old"]; only the plpy.execute case was run. Steps to reproduce: 1. In a new cluster: CREATE EXTENSION plpython3u; CREATE TABLE big (id int, b bytea); INSERT INTO big SELECT 1, convert_to(repeat('a', 300000000), 'UTF8'); 2. Restart the server under an address-space limit that leaves room for the server to detoast the value but not for Python to copy it. Here a backend with Python loaded uses about 188 MB, and the limit was 188 MB + 450 MB: ulimit -v 653312 pg_ctl -D -l start The numbers depend on the build and platform; the limit has to leave room for the detoasted value but not for a second copy of it. 3. Then: CREATE FUNCTION g() RETURNS int AS $$ r =3D plpy.execute("SELECT b FROM big") return len(r[0]["b"]) $$ LANGUAGE plpython3u; SELECT g(); server closed the connection unexpectedly Server log (19rc2): LOG: client backend (PID 548414) was terminated by signal 11: Segmentation fault LOG: terminating any other active server processes LOG: all server processes terminated; reinitializing 17.12 shows the same with the same limit: LOG: server process (PID 546767) was terminated by signal 11: Segmentation fault On 19rc2, with a higher limit (188 MB + 1200 MB) SELECT g() returns 300000000, and with a lower one (188 MB + 100 MB) the server fails first, while detoasting, with an ordinary out-of-memory ERROR and the session survives. Backtrace from the core of the crashing backend (19rc2, same run as the log above): #0 Py_INCREF (op=3D0x0) at ./Include/refcount.h:282 #1 _Py_NewRef (obj=3D0x0) at ./Include/refcount.h:543 #2 PyDict_SetItem (op=3D..., key=3D..., value=3D0x0) at Objects/dictobject= .c:2727 #3 PyDict_SetItemString (v=3D..., key=3D"b", item=3D0x0) at Objects/dictobject.c:5094 #4 PLyDict_FromTuple (...) at src/pl/plpython/plpy_typeio.c #5 PLy_input_from_tuple (...) at src/pl/plpython/plpy_typeio.c #6 PLy_spi_execute_fetch_result (tuptable=3D..., rows=3D1, status=3D5) at src/pl/plpython/plpy_spi.c:412 #7 PLy_spi_execute_query (query=3D"SELECT b FROM big", limit=3D0) at src/pl/plpython/plpy_spi.c:324