postgres.git / summary / log / commit / refs

commit    2980e5e4d3f5c56b02f6a321e40d154e889b560c
Author:   Dean Rasheed <dean.a.rasheed@gmail.com>
Date:     Wed Nov 04 19:45:39 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    Fix ExecCheckIndexConstraints() crash when es_snapshot is invalid.
    
    At transaction level SERIALIZABLE, commit fb60892f403 made
    check_exclusion_or_unique_constraint() read the conflicting tuple
    again using estate->es_snapshot when violationOK is true and
    conflictTid is non-NULL, to ensure that INSERT ... ON CONFLICT takes
    an SIREAD lock. This can only happen from ExecCheckIndexConstraints(),
    but not all callers of ExecCheckIndexConstraints() initialize
    estate->es_snapshot, and the re-fetch crashes if it's invalid.
    
    In core Postgres, this only affects the logical replication apply
    worker which, starting from v18, uses ExecCheckIndexConstraints() to
    log conflicts while applying changes, without initializing es_snapshot
    in the EState that it builds. However, there is also extension code
    that does the same, so the problem affects all versions that
    fb60892f403 was applied to.
    
    Fix by skipping the re-fetch in check_exclusion_or_unique_constraint()
    if the snapshot is invalid.
    
    Reported-by: Zsolt Parragi <zsolt.parragi@percona.com>
    Author: Zsolt Parragi <zsolt.parragi@percona.com>
    Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
    Discussion: https://postgr.es/m/CAN4CZFPz4ysPyo1ahD-5n0iyKxmuo2Wvn%3DPgEZTyW63_Tu7Eaw%40mail.gmail.com
    Backpatch-through: 14


src/backend/executor/execIndexing.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c index 1e3a86aca1b..0d4c53e85dc 100644 --- a/src/backend/executor/execIndexing.c +++ b/src/backend/executor/execIndexing.c @@ -919,8 +919,14 @@ retry: * read. Read the tuple again with the query snapshot to * record it. The result is of no interest here, the caller * checks visibility itself. + * + * Some callers, such as the logical replication apply worker, + * may have not set es_snapshot. Since such callers are not + * executing INSERT ... ON CONFLICT, there is nothing to + * record for SSI; skip the read in that case. */ - if (IsolationIsSerializable()) + if (IsolationIsSerializable() && + estate->es_snapshot != InvalidSnapshot) { INJECTION_POINT("check-exclusion-or-unique-constraint-conflict", NULL); (void) table_tuple_fetch_row_version(heap, conflictTid, [parent: a8e54f3dad3a]