Skip to content

Commit a6ca47c

Browse files
committed
Make autovacuum more selective about temp tables to keep
When temp tables are in danger of XID wraparound, autovacuum drops them; however, it preserves those that are owned by a working session. This is desirable, except when the session is connected to a different database (because the temp tables cannot be from that session), so make it only keep the temp tables only if the backend is in the same database as the temp tables. This is not bulletproof: it fails to detect temp tables left by a session whose backend ID is reused in the same database but the new session does not use temp tables. Commit 943576b fixes that case too, for branches 11 and up (which is why we don't apply this fix to those branches), but back-patching that one is not universally agreed on. Discussion: https://postgr.es/m/20181214162843.37g6h3txto43akrb@alvherre.pgsql Reviewed-by: Takayuki Tsunakawa, Michaël Paquier
1 parent d448670 commit a6ca47c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,13 +2084,18 @@ do_autovacuum(void)
20842084
if (classForm->relpersistence == RELPERSISTENCE_TEMP)
20852085
{
20862086
int backendID;
2087+
PGPROC *proc;
20872088

20882089
backendID = GetTempNamespaceBackendId(classForm->relnamespace);
20892090

2090-
/* We just ignore it if the owning backend is still active */
2091+
/*
2092+
* We just ignore it if the owning backend is still active in the
2093+
* same database.
2094+
*/
20912095
if (backendID != InvalidBackendId &&
20922096
(backendID == MyBackendId ||
2093-
BackendIdGetProc(backendID) == NULL))
2097+
(proc = BackendIdGetProc(backendID)) == NULL ||
2098+
proc->databaseId != MyDatabaseId))
20942099
{
20952100
/*
20962101
* The table seems to be orphaned -- although it might be that

0 commit comments

Comments
 (0)