From fef6c118478933962afedc4cdf0c4188facb2e5f Mon Sep 17 00:00:00 2001
From: Jim Jones <jim.jones@uni-muenster.de>
Date: Mon, 12 Oct 2026 18:33:47 +0200
Subject: [PATCH v9 2/2] fix premature lsn logging

---
 src/backend/commands/dbcommands.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 9b570e66f3b..fdb8da20a8a 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -1904,15 +1904,6 @@ dropdb(const char *dbname, bool missing_ok, bool force)
 	CatalogTupleDelete(pgdbrel, &tup->t_self);
 	heap_freetuple(tup);
 
-	/* Log the LSN captured before the database was marked invalid */
-	if (log_object_drops)
-		ereport(LOG,
-				(errmsg("database \"%s\" (OID %u) dropped, lsn=%X/%08X",
-						dbname, db_id, LSN_FORMAT_ARGS(drop_lsn)),
-				 errhint("To recover to the point before this drop, use recovery_target_lsn = '%X/%08X' "
-						 "with recovery_target_inclusive = false.",
-						 LSN_FORMAT_ARGS(drop_lsn))));
-
 	/*
 	 * Drop db-specific replication slots.
 	 */
@@ -1947,6 +1938,15 @@ dropdb(const char *dbname, bool missing_ok, bool force)
 	 */
 	remove_dbtablespaces(db_id);
 
+	/* Log the LSN captured before the database was marked invalid */
+	if (log_object_drops)
+		ereport(LOG,
+				(errmsg("database \"%s\" (OID %u) dropped, lsn=%X/%08X",
+						dbname, db_id, LSN_FORMAT_ARGS(drop_lsn)),
+				 errhint("To recover to the point before this drop, use recovery_target_lsn = '%X/%08X' "
+						 "with recovery_target_inclusive = false.",
+						 LSN_FORMAT_ARGS(drop_lsn))));
+
 	/*
 	 * Close pg_database, but keep lock till commit.
 	 */
-- 
2.56.0

