pgsql: Make autovacuum more aggressive to remove orphaned temp tables - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Make autovacuum more aggressive to remove orphaned temp tables
Date
Msg-id E1fp9Uw-0006vV-PN@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Make autovacuum more aggressive to remove orphaned temp tables

Commit dafa084, added in 10, made the removal of temporary orphaned
tables more aggressive.  This commit makes an extra step into the
aggressiveness by adding a flag in each backend's MyProc which tracks
down any temporary namespace currently in use.  The flag is set when the
namespace gets created and can be reset if the temporary namespace has
been created in a transaction or sub-transaction which is aborted.  The
flag value assignment is assumed to be atomic, so this can be done in a
lock-less fashion like other flags already present in PGPROC like
databaseId or backendId, still the fact that the temporary namespace and
table created are still locked until the transaction creating those
commits acts as a barrier for other backends.

This new flag gets used by autovacuum to discard more aggressively
orphaned tables by additionally checking for the database a backend is
connected to as well as its temporary namespace in-use, removing
orphaned temporary relations even if a backend reuses the same slot as
one which created temporary relations in a past session.

The base idea of this patch comes from Robert Haas, has been written in
its first version by Tsunakawa Takayuki, then heavily reviewed by me.

Author: Tsunakawa Takayuki
Reviewed-by: Michael Paquier, Kyotaro Horiguchi, Andres Freund
Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1F8A4DC6@G01JPEXMBYT05
Backpatch: 11-, as PGPROC gains a new flag and we don't want silent ABI
breakages on already released versions.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/246a6c8f7b237cc1943efbbb8a7417da9288f5c4

Modified Files
--------------
src/backend/access/transam/twophase.c |  1 +
src/backend/catalog/namespace.c       | 70 ++++++++++++++++++++++++++++++++++-
src/backend/postmaster/autovacuum.c   | 20 ++++------
src/backend/storage/lmgr/proc.c       |  2 +
src/include/catalog/namespace.h       |  1 +
src/include/storage/proc.h            |  3 ++
6 files changed, 83 insertions(+), 14 deletions(-)


pgsql-committers by date:

Previous
From: Amit Kapila
Date:
Subject: pgsql: Adjust comment atop ExecShutdownNode.
Next
From: Tom Lane
Date:
Subject: pgsql: Fix libpq's implementation of per-host connection timeouts.