diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index c518c2133cdbb68620282b68bee1147849ab0c21..225c175d7fcd9bd3d2ce2020ef72432e57cf319f 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -894,9 +894,9 @@ CreateLockFile(const char *filename, bool amPostmaster,
 
 	/*
 	 * Successfully created the file, now fill it.	See comment in miscadmin.h
-	 * about the contents.	Note that we write the same info into both datadir
-	 * and socket lockfiles; although more stuff may get added to the datadir
-	 * lockfile later.
+	 * about the contents.  Note that we write the same first five lines into
+	 * both datadir and socket lockfiles; although more stuff may get added to
+	 * the datadir lockfile later.
 	 */
 	snprintf(buffer, sizeof(buffer), "%d\n%s\n%ld\n%d\n%s\n",
 			 amPostmaster ? (int) my_pid : -((int) my_pid),
@@ -905,6 +905,13 @@ CreateLockFile(const char *filename, bool amPostmaster,
 			 PostPortNumber,
 			 socketDir);
 
+	/*
+	 * In a standalone backend, the next line (LOCK_FILE_LINE_LISTEN_ADDR)
+	 * will never receive data, so fill it in as empty now.
+	 */
+	if (isDDLock && !amPostmaster)
+		strlcat(buffer, "\n", sizeof(buffer));
+
 	errno = 0;
 	if (write(fd, buffer, strlen(buffer)) != strlen(buffer))
 	{
@@ -1078,7 +1085,8 @@ AddToDataDirLockFile(int target_line, const char *str)
 	{
 		if ((srcptr = strchr(srcptr, '\n')) == NULL)
 		{
-			elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
+			elog(LOG, "incomplete data in \"%s\": found only %d newlines while trying to add line %d",
+				 DIRECTORY_LOCK_FILE, lineno - 1, target_line);
 			close(fd);
 			return;
 		}