mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Add %P to log_line_prefix for parallel group leader
This is useful for monitoring purposes with log parsing. Similarly to pg_stat_activity, the leader's PID is shown only for active parallel workers, minimizing the log footprint for the leaders as the equivalent shared memory field is set as long as a backend is alive. Author: Justin Pryzby Reviewed-by: Álvaro Herrera, Michael Paquier, Julien Rouhaud, Tom Lane Discussion: https://postgr.es/m/20200315111831.GA21492@telsasoft.com
This commit is contained in:
		@@ -2448,6 +2448,29 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
 | 
			
		||||
				else
 | 
			
		||||
					appendStringInfo(buf, "%d", MyProcPid);
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case 'P':
 | 
			
		||||
				if (MyProc)
 | 
			
		||||
				{
 | 
			
		||||
					PGPROC	   *leader = MyProc->lockGroupLeader;
 | 
			
		||||
 | 
			
		||||
					/*
 | 
			
		||||
					 * Show the leader only for active parallel workers. This
 | 
			
		||||
					 * leaves out the leader of a parallel group.
 | 
			
		||||
					 */
 | 
			
		||||
					if (leader == NULL || leader->pid == MyProcPid)
 | 
			
		||||
						appendStringInfoSpaces(buf,
 | 
			
		||||
											   padding > 0 ? padding : -padding);
 | 
			
		||||
					else if (padding != 0)
 | 
			
		||||
						appendStringInfo(buf, "%*d", padding, leader->pid);
 | 
			
		||||
					else
 | 
			
		||||
						appendStringInfo(buf, "%d", leader->pid);
 | 
			
		||||
				}
 | 
			
		||||
				else if (padding != 0)
 | 
			
		||||
					appendStringInfoSpaces(buf,
 | 
			
		||||
										   padding > 0 ? padding : -padding);
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case 'l':
 | 
			
		||||
				if (padding != 0)
 | 
			
		||||
					appendStringInfo(buf, "%*ld", padding, log_line_number);
 | 
			
		||||
@@ -2836,6 +2859,21 @@ write_csvlog(ErrorData *edata)
 | 
			
		||||
	else
 | 
			
		||||
		appendCSVLiteral(&buf, GetBackendTypeDesc(MyBackendType));
 | 
			
		||||
 | 
			
		||||
	appendStringInfoChar(&buf, ',');
 | 
			
		||||
 | 
			
		||||
	/* leader PID */
 | 
			
		||||
	if (MyProc)
 | 
			
		||||
	{
 | 
			
		||||
		PGPROC	   *leader = MyProc->lockGroupLeader;
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		 * Show the leader only for active parallel workers.  This leaves out
 | 
			
		||||
		 * the leader of a parallel group.
 | 
			
		||||
		 */
 | 
			
		||||
		if (leader && leader->pid != MyProcPid)
 | 
			
		||||
			appendStringInfo(&buf, "%d", leader->pid);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	appendStringInfoChar(&buf, '\n');
 | 
			
		||||
 | 
			
		||||
	/* If in the syslogger process, try to write messages direct to file */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user