<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div style="font-family: inherit; font-size: inherit; color: inherit; background-color: transparent;">
</div>
<div style="font-family: inherit; font-size: inherit; color: inherit; background-color: transparent;">
I had similar issue recently. This could be caused by a recursive function call entering an endless loop. In my case checking the code and defining in the problematic function a limit for the depth of recursive calls solved the issue.</div>
<div style="font-family: inherit; font-size: inherit; color: inherit; background-color: transparent;">
<br>
</div>
<div style="font-family: inherit; font-size: inherit; color: inherit; background-color: transparent;">
Franck Theeten</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Michal Seidl <michal.seidl@gmail.com><br>
<b>Sent:</b> Wednesday, June 18, 2025 11:36<br>
<b>To:</b> postgis-users@lists.osgeo.org <postgis-users@lists.osgeo.org><br>
<b>Subject:</b> Topology - toTopoGeom causes segmentation fault and database restart</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hello,<br>
we use postgis topology for storing and updating quite complicated <br>
polygons representing roads.<br>
<br>
Sometimes inserting new polygon into topology causes exceptions (whis is <br>
not nice but acceptable, I can see there is plan to add some more <br>
usefull message <a href="https://trac.osgeo.org/postgis/ticket/5889)" data-auth="NotApplicable">
https://trac.osgeo.org/postgis/ticket/5889)</a> but <br>
sometimes it completely shut down server which is quite bad as there are <br>
other live databases on server.<br>
<br>
The error is cause by our function jt_to_topo_geom() which is just <br>
wrapper about toTopoGeom(). The inserted MultiPolygon geometry is quite <br>
large but postgis valid with reasonable vertices. I have suspicion there <br>
is conflict with data already inserted into topology, but have no idea <br>
where due to not info from log.<br>
<br>
Postgis:<br>
<br>
POSTGIS="3.4.2 c19ce56" [EXTENSION] PGSQL="140" GEOS="3.9.0-CAPI-1.16.2" <br>
PROJ="7.2.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org <br>
USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/usr/share/proj/proj.db" <br>
LIBXML="2.9.10" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 <br>
(Internal)" TOPOLOGY<br>
<br>
The code of function:<br>
<br>
CREATE OR REPLACE FUNCTION unis_emh.jt_to_topo_geom(<br>
dst_schema character varying,<br>
dst_table character varying,<br>
dst_column character varying,<br>
geom geometry)<br>
RETURNS topogeometry<br>
LANGUAGE 'plpgsql'<br>
COST 100<br>
VOLATILE PARALLEL UNSAFE<br>
AS $BODY$<br>
DECLARE<br>
layer_ layer;<br>
topology_ topology;<br>
BEGIN<br>
-- get names<br>
SELECT * FROM FindLayer(dst_schema, dst_table, dst_column) INTO layer_;<br>
SELECT * FROM FindTopology((layer_).topology_id) INTO topology_;<br>
<br>
-- insert geometry, no duplicate protection<br>
RETURN toTopoGeom(geom, (topology_).name, (layer_).layer_id);<br>
END;<br>
$BODY$;<br>
<br>
Database log:<br>
<br>
2025-06-17 17:41:46.509 CET [2414906] LOG: server process (PID 2415005) <br>
was terminated by signal 11: Segmentation fault<br>
2025-06-17 17:41:46.509 CEST [2414906] DETAIL: Failed process was <br>
running: INSERT INTO "j_pmh_topo_geometrie" ("id_geometrie", "topo_geom")<br>
SELECT "id_geometrie", <br>
"unis_emh"."jt_to_topo_geom"(current_schema::text, <br>
'j_pmh_topo_geometrie', 'topo_geom', "geom")<br>
FROM "j_pmh_geometrie"<br>
WHERE "id_geometrie"=63855<br>
2025-06-17 17:41:46.509 CEST [2414906] LOG: terminating any other <br>
active server processes<br>
2025-06-17 17:41:46.513 CEST [2414906] LOG: all server processes <br>
terminated; reinitializing<br>
2025-06-17 17:41:46.625 CEST [2415006] LOG: database system was <br>
interrupted; last known up at 2025-06-17 17:40:42 CEST<br>
2025-06-17 17:41:46.896 CEST [2415006] LOG: database system was not <br>
properly shut down; automatic recovery in progress<br>
2025-06-17 17:41:46.917 CEST [2415006] LOG: redo starts at 14F/64BCDA20<br>
2025-06-17 17:41:46.927 CEST [2415006] LOG: unexpected pageaddr <br>
14F/20000000 in log segment 000000010000014F00000065, offset 0<br>
2025-06-17 17:41:46.927 CEST [2415006] LOG: redo done at 14F/64FFFFC0 <br>
system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.01 s<br>
2025-06-17 17:41:47.021 CEST [2414906] LOG: database system is ready to <br>
accept connections<br>
<br>
MS.<br>
</div>
</span></font></div>
</body>
</html>