diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index eb2301a5cf4..7a7e2c6e3ef 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -1650,6 +1650,8 @@ dropdb(const char *dbname, bool missing_ok, bool force) bool db_istemplate; Relation pgdbrel; HeapTuple tup; + ScanKeyData scankey; + SysScanDesc scan; Form_pg_database datform; int notherbackends; int npreparedxacts; @@ -1787,7 +1789,18 @@ dropdb(const char *dbname, bool missing_ok, bool force) */ pgstat_drop_database(db_id); - tup = SearchSysCacheCopy1(DATABASEOID, ObjectIdGetDatum(db_id)); + /* + * Update the database's pg_database tuple + */ + ScanKeyInit(&scankey, + Anum_pg_database_datname, + BTEqualStrategyNumber, F_NAMEEQ, + CStringGetDatum(dbname)); + + scan = systable_beginscan(pgdbrel, DatabaseNameIndexId, true, + NULL, 1, &scankey); + + tup = systable_getnext(scan); if (!HeapTupleIsValid(tup)) elog(ERROR, "cache lookup failed for database %u", db_id); datform = (Form_pg_database) GETSTRUCT(tup); @@ -1813,6 +1826,8 @@ dropdb(const char *dbname, bool missing_ok, bool force) */ CatalogTupleDelete(pgdbrel, &tup->t_self); + systable_endscan(scan); + /* * Drop db-specific replication slots. */