]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Avoid SIGSEGV in pg_get_database_ddl() on NULL tablespace
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 30 Apr 2026 14:14:52 +0000 (10:14 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 30 Apr 2026 14:14:52 +0000 (10:14 -0400)
There is a narrow race in which a concurrent ALTER DATABASE ... SET
TABLESPACE moves the database off the tablespace and a DROP TABLESPACE
removes it between the syscache lookup and the catalog scan. If that
happens, output an error.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Jack Bonatakis <jack@bonatak.is>
Reviewed-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/573E45C1-31A4-4885-A00C-1A2171159A2A@gmail.com

src/backend/utils/adt/ddlutils.c

index d83cda3342e2d041bb936cda000a5e57bccc3165..d6f55c48f37dbdee4426a5120e8f9c16553bf224 100644 (file)
@@ -986,6 +986,13 @@ pg_get_database_ddl_internal(Oid dbid, bool pretty,
        {
                char       *spcname = get_tablespace_name(dbform->dattablespace);
 
+               if (spcname == NULL)
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_UNDEFINED_OBJECT),
+                                        errmsg("tablespace with OID %u does not exist",
+                                                       dbform->dattablespace),
+                                        errdetail("It may have been concurrently dropped.")));
+
                if (pg_strcasecmp(spcname, "pg_default") != 0)
                        append_ddl_option(&buf, pretty, 4, "TABLESPACE = %s",
                                                          quote_identifier(spcname));