From: Chris St Denis <chris@ctgameinfo.com>
To: David Geier <geidav.pg@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: crash in ltree_compare_distance() in 14.24
Date: Thu, 29 Oct 2026 23:16:04 -0700
Message-ID: <1990fc2d-c56a-4111-8444-6f8f1d66d1fd@ctgameinfo.com> (raw)
In-Reply-To: <23946400-3809-499d-b0bc-5f859df8ef50@gmail.com>
References: <043a5139-1f0c-49df-b423-1cd129839aa9@ctgameinfo.com>
<497fe0b6-2f8c-4237-b749-bed21de36c01@gmail.com>
<3527d5c4-0ce4-4412-b433-2e1d36517139@ctgameinfo.com>
<23946400-3809-499d-b0bc-5f859df8ef50@gmail.com>
On 2026-10-28 12:19 p.m., David Geier wrote:
>>> In case you cannot reproduce it, can you share at least the query you
>>> were running and the relevant parts of the schema?
>> It happened in the middle of the night, has not happened since.
>>
>> The ltree column id_tree contains a ltree of comment ID's showing the
>> tree of comment replies.
>>
>> Logs show this
>>
>> 2026-10-26 02:26:35.914 PDT [61206] LOG: server process (PID
>> 50023) was terminated by signal 11: Segmentation fault
>> 2026-10-26 02:26:35.914 PDT [61206] DETAIL: Failed process was
>> running: INSERT INTO "story_comments" ("comment", "reply_to",
>> "deleted", "id_tree", "sid", "user_id", "ipaddr") VALUES ($1, $2,
>> $3, $4, $5, $6, $7)
>>
>> Due to parameterised queries, I do not have the data values that were
>> inserted.
>>
>> Here is the table structure.
> Thanks for sharing the details.
>
> What can be concluded from the core dump information you shared in your
> first mail is that the read of b->numlevel in
>
> float
> ltree_compare_distance(const ltree *a, const ltree *b)
> {
> ltree_level *al = LTREE_FIRST(a);
> ltree_level *bl = LTREE_FIRST(b);
> int an = a->numlevel;
> int bn = b->numlevel;
>
> causes the segfault, likely because "b" is a corrupted pointer. The
> value of b is 0x127a2f2a13, which is unaligned and far away from "a"
> which is 0x2fa39243b1d8 and aligned as expected. Beyond that, the "a"
> ltree is empty / has 0 levels as can be inferred from edx = 0.
>
> I tried to create a failing test case based on your schema details but
> failed. I'm assuming that the order of INSERTs and the data matters.
>
> What you could try is open your core dump and go down the call stack to
> see where "b" gets messed up. It would also be interesting which of the
> two calls to ltree_compare_distance() in ltree_penalty() causes the
> segfault.
>
> Do you use data checksums? If not, maybe the issue stems from a data
> corruption on disk?
>
> FYI: PostgreSQL 14 reaches end of life on November 12, 2026. Though, I
> think it's not unlikely that this bug is also on master.
Data corruption is possible, I recently had an incident with it, however
my thinking was that if this was caused by corruption that the pg_dump
would also crash the server which is not happening. That assumption may
be incorrect.
If corruption is the cause, can you give guidance on what I should do to
repair/validate that data? Which index should be rebuilt/etc? I will be
doing a full dump/restore to upgrade to latest version soonish (need to
validate that new version won't break anything in the application) which
should hopefully remove any issues there.
I do not know gdb very well, so I will need guidance for commands to 'go
down the call stack tosee where "b" gets messed up'. I recompiled
postgres to try to get debugging symbols, and now backtrace is corrupt
so I don't know if I can still get useful data out of the core. I guess
I can go back to the old binary if the data is useful, but as you said
it's an old version.
Unfortunately not using checksums.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: chris@ctgameinfo.com, geidav.pg@gmail.com
Subject: Re: crash in ltree_compare_distance() in 14.24
In-Reply-To: <1990fc2d-c56a-4111-8444-6f8f1d66d1fd@ctgameinfo.com>
References: <043a5139-1f0c-49df-b423-1cd129839aa9@ctgameinfo.com> <497fe0b6-2f8c-4237-b749-bed21de36c01@gmail.com> <3527d5c4-0ce4-4412-b433-2e1d36517139@ctgameinfo.com> <23946400-3809-499d-b0bc-5f859df8ef50@gmail.com> <1990fc2d-c56a-4111-8444-6f8f1d66d1fd@ctgameinfo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox