• Robert Haas's avatar
    autovacuum: Drop orphan temp tables more quickly but with more caution. · a734fd5d
    Robert Haas authored
    Previously, we only dropped an orphan temp table when it became old
    enough to threaten wraparound; instead, doing it immediately.  The
    only value of waiting is that someone might be able to examine the
    contents of the orphan temp table for forensic purposes, but it's
    pretty difficult to actually do that and few users will wish to do so.
    On the flip side, not performing the drop immediately generates log
    spam and bloats pg_class.
    
    In addition, per a report from Grigory Smolkin, if a temporary schema
    contains a very large number of temporary tables, a backend attempting
    to clear the temporary schema might fail due to lock table exhaustion.
    It's helpful for autovacuum to clean up after such cases, and we don't
    want it to wait for wraparound to threaten before doing so.  To
    prevent autovacuum from failing in the same manner as a backend trying
    to drop an entire temp schema, remove orphan temp tables in batches of
    50, committing after each batch, so that we don't accumulate an
    unbounded number of locks.  If a drop fails, retry other orphan tables
    that need to be dropped up to 10 times before giving up.  With this
    system, if a backend does fail to clean a temporary schema due to
    lock table exhaustion, autovacuum should hopefully put things right
    the next time it processes the database.
    
    Discussion: CAB7nPqSbYT6dRwsXVgiKmBdL_ARemfDZMPA+RPeC_ge0GK70hA@mail.gmail.com
    
    Michael Paquier, with a bunch of comment changes by me.
    a734fd5d
autovacuum.c 90 KB