aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/namespace.c30
-rw-r--r--src/backend/postmaster/autovacuum.c7
2 files changed, 24 insertions, 13 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 5f68cc13776..2c9cea58269 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -3215,7 +3215,7 @@ isOtherTempNamespace(Oid namespaceId)
}
/*
- * isTempNamespaceInUse - is the given namespace owned and actively used
+ * checkTempNamespaceStatus - is the given namespace owned and actively used
* by a backend?
*
* Note: this can be used while scanning relations in pg_class to detect
@@ -3223,8 +3223,8 @@ isOtherTempNamespace(Oid namespaceId)
* given database. The result may be out of date quickly, so the caller
* must be careful how to handle this information.
*/
-bool
-isTempNamespaceInUse(Oid namespaceId)
+TempNamespaceStatus
+checkTempNamespaceStatus(Oid namespaceId)
{
PGPROC *proc;
int backendId;
@@ -3233,25 +3233,35 @@ isTempNamespaceInUse(Oid namespaceId)
backendId = GetTempNamespaceBackendId(namespaceId);
- /* No such temporary namespace? */
+ /* No such namespace, or its name shows it's not temp? */
if (backendId == InvalidBackendId)
- return false;
+ return TEMP_NAMESPACE_NOT_TEMP;
/* Is the backend alive? */
proc = BackendIdGetProc(backendId);
if (proc == NULL)
- return false;
+ return TEMP_NAMESPACE_IDLE;
/* Is the backend connected to the same database we are looking at? */
if (proc->databaseId != MyDatabaseId)
- return false;
+ return TEMP_NAMESPACE_IDLE;
/* Does the backend own the temporary namespace? */
if (proc->tempNamespaceId != namespaceId)
- return false;
+ return TEMP_NAMESPACE_IDLE;
- /* all good to go */
- return true;
+ /* Yup, so namespace is busy */
+ return TEMP_NAMESPACE_IN_USE;
+}
+
+/*
+ * isTempNamespaceInUse - oversimplified, deprecated version of
+ * checkTempNamespaceStatus
+ */
+bool
+isTempNamespaceInUse(Oid namespaceId)
+{
+ return checkTempNamespaceStatus(namespaceId) == TEMP_NAMESPACE_IN_USE;
}
/*
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 2d925d2ee0c..ac0242c9d37 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -2089,9 +2089,10 @@ do_autovacuum(void)
{
/*
* We just ignore it if the owning backend is still active and
- * using the temporary schema.
+ * using the temporary schema. Also, for safety, ignore it if the
+ * namespace doesn't exist or isn't a temp namespace after all.
*/
- if (!isTempNamespaceInUse(classForm->relnamespace))
+ if (checkTempNamespaceStatus(classForm->relnamespace) == TEMP_NAMESPACE_IDLE)
{
/*
* The table seems to be orphaned -- although it might be that
@@ -2261,7 +2262,7 @@ do_autovacuum(void)
continue;
}
- if (isTempNamespaceInUse(classForm->relnamespace))
+ if (checkTempNamespaceStatus(classForm->relnamespace) != TEMP_NAMESPACE_IDLE)
{
UnlockRelationOid(relid, AccessExclusiveLock);
continue;