mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	Tweak pg_promote() to report failures on kill() or postmaster failures
Since its introduction in 10074651e3, pg_promote() has been returning
a false status in three cases:
- SIGUSR1 not sent to the postmaster process.
- Postmaster death during standby promotion.
- Standby not promoted within the specified wait time.
An application calling this function will have a hard time understanding
what a false state returned actually means.
Per discussion, this switches the two first states to fail rather than
return a "false" status, making the second case more consistent with the
existing CHECK_FOR_INTERRUPTS in the wait loop.  False is only returned
when the promotion is not completed within the specified time (60s by
default).
Author: Ashutosh Sharma
Reviewed-by: Fujii Masao, Laurenz Albe, Michael Paquier
Discussion: https://postgr.es/m/CAE9k0P=QTrwptL0t4J0fuBRDDjgsT-0PVKd-ikd96i1hyL7Bcg@mail.gmail.com
			
			
This commit is contained in:
		| @@ -711,10 +711,10 @@ pg_promote(PG_FUNCTION_ARGS) | |||||||
| 	/* signal the postmaster */ | 	/* signal the postmaster */ | ||||||
| 	if (kill(PostmasterPid, SIGUSR1) != 0) | 	if (kill(PostmasterPid, SIGUSR1) != 0) | ||||||
| 	{ | 	{ | ||||||
| 		ereport(WARNING, |  | ||||||
| 				(errmsg("failed to send signal to postmaster: %m"))); |  | ||||||
| 		(void) unlink(PROMOTE_SIGNAL_FILE); | 		(void) unlink(PROMOTE_SIGNAL_FILE); | ||||||
| 		PG_RETURN_BOOL(false); | 		ereport(ERROR, | ||||||
|  | 				(errcode(ERRCODE_SYSTEM_ERROR), | ||||||
|  | 				 errmsg("failed to send signal to postmaster: %m"))); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/* return immediately if waiting was not requested */ | 	/* return immediately if waiting was not requested */ | ||||||
| @@ -744,7 +744,10 @@ pg_promote(PG_FUNCTION_ARGS) | |||||||
| 		 * necessity for manual cleanup of all postmaster children. | 		 * necessity for manual cleanup of all postmaster children. | ||||||
| 		 */ | 		 */ | ||||||
| 		if (rc & WL_POSTMASTER_DEATH) | 		if (rc & WL_POSTMASTER_DEATH) | ||||||
| 			PG_RETURN_BOOL(false); | 			ereport(FATAL, | ||||||
|  | 					(errcode(ERRCODE_ADMIN_SHUTDOWN), | ||||||
|  | 					 errmsg("terminating connection due to unexpected postmaster exit"), | ||||||
|  | 					 errcontext("while waiting on promotion"))); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	ereport(WARNING, | 	ereport(WARNING, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user