Thread

  1. Re: Fix bug with accessing to temporary tables of other sessions

    Daniil Davydov <3danissimo@gmail.com> — 2026-05-03T08:53:39Z

    Hi,
    
    On Sun, May 3, 2026 at 12:32 AM Jim Jones <jim.jones@uni-muenster.de> wrote:
    >
    > In addition to the DROP TABLE exception:
    >
    > It is also possible to LOCK temporary tables from other sessions:
    >
    > postgres=# BEGIN;
    > BEGIN
    > postgres=*# LOCK TABLE pg_temp_91.t IN ACCESS SHARE MODE ;
    > LOCK TABLE
    >
    > pg_temp_91.t lives as long the transaction is open -- even after the
    > origin session closes, which is totally expected. I'd say it falls into
    > the same category of DROP TABLE, where the table contents are never
    > read, so I'd argue it's ok.
    
    Autovacuum locks orphaned table's oid before deleting it. LOCK TABLE command
    also locks the oid of the specified table. If we want to make sure that
    autovacuum can acquire the mentioned lock (i.e. cover this behavior using
    tests), I suggest testing it using the LOCK TABLE command.
    
    Please, see the attached patch that ensures that cross-session LOCK TABLE works
    properly.
    
    --
    Best regards,
    Daniil Davydov