Commitfest Bot · GitHub

Commits on Aug 21, 2026

  1. Fix replication slot leak on error caught in a subtransaction.

    The SQL-callable replication slot functions, such as
    pg_replication_slot_advance(), acquire a slot and release it
    before returning. If one throws an error in between, the slot is
    released by the top-level error handler (the sigsetjmp block in
    PostgresMain()). But PL/pgSQL, PL/Perl, PL/Python and PL/Tcl run
    an error-handling block in an internal subtransaction: when an
    error is raised there, they abort the subtransaction and, if a
    handler matches, catch the error without re-throwing it. The
    top-level handler is then never reached, and nothing in the
    (sub)transaction abort path releases the slot either.
    The slot is therefore left acquired after the caught error. The
    next slot operation in the session then fails an assertion, or in
    a non-assertion build silently overwrites the reference and leaks
    the slot, which keeps holding back WAL removal and the catalog
    xmin (blocking vacuum) and can no longer be acquired.
    An error that does reach the top-level handler is unaffected.
    That is the case for a plain ROLLBACK TO SAVEPOINT, or for a
    PL/pgSQL exception handler whose conditions do not match the
    error, which then re-throws it.
    Fix by recording the subtransaction that acquires the slot and
    releasing the slot when that subtransaction aborts, the same way
    other subtransaction-scoped resources are released, for example
    in AtEOSubXact_LargeObject() and AtEOSubXact_Files(). The slot
    cannot simply be released on every subtransaction abort, because
    logical decoding starts and aborts an internal transaction or
    subtransaction for each decoded transaction while holding the
    slot. Those internal aborts are below the acquiring
    subtransaction and so are left alone.
    Releasing a temporary slot does not drop it, so it would keep
    holding resources until the session ends. To avoid that, when
    releasing the held slot on abort also drop the session's
    temporary slots, the same way the top-level error handler already
    does.
    Reported-by: Satya Narlapuram <satyanarlapuram@gmail.com>
    Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
    Co-authored-by: Satya Narlapuram <satyanarlapuram@gmail.com>
    Co-authored-by: Masahiko Sawada <sawada.mshk@gmail.com>
    Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
    Reviewed-by: shveta malik <shveta.malik@gmail.com>
    Reviewed-by: Hou Zhijie <houzj.fnst@fujitsu.com>
    Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
    Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com>
    Discussion: https://postgr.es/m/CAHg+QDeuf9tCq3ce=kgFMJP0m=PZC+wi6B=yS+7V0vNXjLS31w@mail.gmail.com
    Backpatch-through: 14

    3 people authored and committed

    Aug 21, 2026
    Configuration menu

    Browse the repository at this point in the history

  2. Configuration menu

    Browse the repository at this point in the history

Read the original on github.com ↗