*** a/src/backend/access/transam/multixact.c
--- b/src/backend/access/transam/multixact.c
***************
*** 133,138 ****
--- 133,142 ----
  #define MULTIXACT_MEMBERS_PER_PAGE	\
  	(MULTIXACT_MEMBERGROUPS_PER_PAGE * MULTIXACT_MEMBERS_PER_MEMBERGROUP)
  
+ /* The number of members in the last page of the last segment. */
+ #define MAX_MEMBERS_IN_LAST_MEMBERS_PAGE \
+ 		((uint32) ((0xFFFFFFFF % MULTIXACT_MEMBERS_PER_PAGE) + 1))
+ 
  /* page in which a member is to be found */
  #define MXOffsetToMemberPage(xid) ((xid) / (TransactionId) MULTIXACT_MEMBERS_PER_PAGE)
  
***************
*** 2278,2283 **** ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
--- 2282,2288 ----
  	{
  		int			flagsoff;
  		int			flagsbit;
+ 		uint32		difference;
  
  		/*
  		 * Only zero when at first entry of a page.
***************
*** 2302,2322 **** ExtendMultiXactMember(MultiXactOffset offset, int nmembers)
  		 * Advance to next page, taking care to properly handle the wraparound
  		 * case.  OK if nmembers goes negative.
  		 */
- 		if ((unsigned int) (offset + nmembers) < offset)
- 		{
- 			uint32		difference = offset + MULTIXACT_MEMBERS_PER_PAGE;
  
! 			nmembers -= (unsigned int) (MULTIXACT_MEMBERS_PER_PAGE - difference);
! 			offset = 0;
  		}
  		else
- 		{
- 			int			difference;
- 
  			difference = MULTIXACT_MEMBERS_PER_PAGE - offset % MULTIXACT_MEMBERS_PER_PAGE;
! 			nmembers -= difference;
! 			offset += difference;
! 		}
  	}
  }
  
--- 2307,2332 ----
  		 * Advance to next page, taking care to properly handle the wraparound
  		 * case.  OK if nmembers goes negative.
  		 */
  
! 		if ((unsigned int) (offset + MAX_MEMBERS_IN_LAST_MEMBERS_PAGE) < offset)
! 		{
! 			/*
! 			 * This is the last page of the last segment; we compute the number
! 			 * of members to store in it noting that all previous pages have
! 			 * MULTIXACT_MEMBERS_PER_PAGE members, but this one has a smaller
! 			 * number of them.  Note that while in general the (offset %
! 			 * MULTIXACT_MEMBERS_PER_PAGE) expression might be larger than
! 			 * MAX_MEMBERS_IN_LAST_MEMBERS_PAGE, we know that it cannot be in
! 			 * this case, so the difference is always a positive number.
! 			 */
! 			difference = MAX_MEMBERS_IN_LAST_MEMBERS_PAGE -
! 				offset % MULTIXACT_MEMBERS_PER_PAGE;
  		}
  		else
  			difference = MULTIXACT_MEMBERS_PER_PAGE - offset % MULTIXACT_MEMBERS_PER_PAGE;
! 
! 		nmembers -= difference;
! 		offset += difference;
  	}
  }
  
