pid.diff

text/x-diff

Filename: pid.diff
Type: text/x-diff
Part: 0
Message: Re: FATAL: bogus data in lock file "postmaster.pid": ""

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/utils/init/miscinit.c 0 0
src/bin/pg_ctl/pg_ctl.c 0 0
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
new file mode 100644
index 775d71f..9a0f92c
*** a/src/backend/utils/init/miscinit.c
--- b/src/backend/utils/init/miscinit.c
*************** CreateLockFile(const char *filename, boo
*** 766,771 ****
--- 766,779 ----
  							filename)));
  		close(fd);
  
+ 		if (len == 0)
+ 		{
+ 			ereport(FATAL,
+ 					(errcode(ERRCODE_LOCK_FILE_EXISTS),
+ 					 errmsg("lock file \"%s\" is empty", filename),
+ 					 errhint("Either another server is starting, or the lock file is the remnant of a previous server startup crash.")));
+ 		}
+ 
  		buffer[len] = '\0';
  		encoded_pid = atoi(buffer);
  
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
new file mode 100644
index af8d8b2..81ba39e
*** a/src/bin/pg_ctl/pg_ctl.c
--- b/src/bin/pg_ctl/pg_ctl.c
*************** get_pgpid(void)
*** 292,299 ****
  	}
  	if (fscanf(pidf, "%ld", &pid) != 1)
  	{
! 		write_stderr(_("%s: invalid data in PID file \"%s\"\n"),
! 					 progname, pid_file);
  		exit(1);
  	}
  	fclose(pidf);
--- 292,304 ----
  	}
  	if (fscanf(pidf, "%ld", &pid) != 1)
  	{
! 		/* Is the file empty? */
! 		if (ftell(pidf) == 0 && feof(pidf))
! 			write_stderr(_("%s: the PID file \"%s\" is empty\n"),
! 						 progname, pid_file);
! 		else
! 			write_stderr(_("%s: invalid data in PID file \"%s\"\n"),
! 						 progname, pid_file);
  		exit(1);
  	}
  	fclose(pidf);