aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2018-12-27 16:00:39 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2018-12-27 16:00:39 -0300
commita85045cccb1b7a6e4b60a9b13abdfb5574eafae5 (patch)
treea56bc7b783cb2324820c7e919b196e8dbb23378b
parent0a323ae6769968408d00ec1a9d1790706d5540fc (diff)
downloadpostgresql-a85045cccb1b7a6e4b60a9b13abdfb5574eafae5.tar.gz
postgresql-a85045cccb1b7a6e4b60a9b13abdfb5574eafae5.zip
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 943576bddcb5 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
-rw-r--r--src/backend/postmaster/autovacuum.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index c49f1624b4c..a580a3c4924 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -2052,11 +2052,18 @@ do_autovacuum(void)
if (classForm->relpersistence == RELPERSISTENCE_TEMP)
{
int backendID;
+ PGPROC *proc;
backendID = GetTempNamespaceBackendId(classForm->relnamespace);
- /* We just ignore it if the owning backend is still active */
- if (backendID == MyBackendId || BackendIdGetProc(backendID) == NULL)
+ /*
+ * We just ignore it if the owning backend is still active in the
+ * same database.
+ */
+ if (backendID != InvalidBackendId &&
+ (backendID == MyBackendId ||
+ (proc = BackendIdGetProc(backendID)) == NULL ||
+ proc->databaseId != MyDatabaseId))
{
/*
* We found an orphan temp table (which was probably left