diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index dd7dd5560faf03443df89f9216a31f2d51ad183f..e400f0a8e15e8d7e02b1d3f5724940c1dd323bf6 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -826,12 +826,6 @@ PostmasterMain(int argc, char *argv[])
 	 */
 	process_shared_preload_libraries();
 
-	/*
-	 * Remove old temporary files.	At this point there can be no other
-	 * Postgres processes running in this directory, so this should be safe.
-	 */
-	RemovePgTempFiles();
-
 	/*
 	 * Establish input sockets.
 	 */
@@ -1099,6 +1093,12 @@ PostmasterMain(int argc, char *argv[])
 	}
 	load_ident();
 
+	/*
+	 * Remove old temporary files.	At this point there can be no other
+	 * Postgres processes running in this directory, so this should be safe.
+	 */
+	RemovePgTempFiles();
+
 	/*
 	 * Remember postmaster startup time
 	 */