diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
new file mode 100644
index 1208eb9..5287004
*** a/src/backend/utils/misc/guc.c
--- b/src/backend/utils/misc/guc.c
*************** write_auto_conf_file(int fd, const char
*** 7845,7894 ****
  /*
   * Update the given list of configuration parameters, adding, replacing
   * or deleting the entry for item "name" (delete if "value" == NULL).
   */
  static void
  replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
  						  const char *name, const char *value)
  {
! 	ConfigVariable *item,
! 			   *prev = NULL;
  
! 	/* Search the list for an existing match (we assume there's only one) */
! 	for (item = *head_p; item != NULL; item = item->next)
  	{
! 		if (strcmp(item->name, name) == 0)
  		{
! 			/* found a match, replace it */
! 			pfree(item->value);
! 			if (value != NULL)
  			{
! 				/* update the parameter value */
! 				item->value = pstrdup(value);
  			}
  			else
  			{
! 				/* delete the configuration parameter from list */
! 				if (*head_p == item)
! 					*head_p = item->next;
! 				else
! 					prev->next = item->next;
! 				if (*tail_p == item)
! 					*tail_p = prev;
! 
! 				pfree(item->name);
! 				pfree(item->filename);
! 				pfree(item);
  			}
! 			return;
! 		}
! 		prev = item;
  	}
  
  	/* Not there; no work if we're trying to delete it */
  	if (value == NULL)
  		return;
  
! 	/* OK, append a new entry */
  	item = palloc(sizeof *item);
  	item->name = pstrdup(name);
  	item->value = pstrdup(value);
--- 7845,7927 ----
  /*
   * Update the given list of configuration parameters, adding, replacing
   * or deleting the entry for item "name" (delete if "value" == NULL).
+  * If more than entry for item "name" is found, all entries except the
+  * last one will be deleted.
   */
  static void
  replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
  						  const char *name, const char *value)
  {
! 	ConfigVariable *item = NULL, *item_iter;
  
! 	/*
! 	 * Find the last match, so if there's more than one match we can
! 	 * delete any preceding matches.
! 	 */
! 	for (item_iter = *head_p; item_iter != NULL; item_iter = item_iter->next)
  	{
!    		if (strcmp(item_iter->name, name) == 0)
  		{
! 			item = item_iter;
! 		}
! 	}
! 
! 	/*
! 	 * At least one match was found, update or delete that as necessary,
! 	 * and remove any preceding duplicates. We'll return from this loop
! 	 * when the last match is processed.
! 	 */
! 	if (item != NULL)
! 	{
! 		ConfigVariable *prev = NULL;
! 		item_iter = *head_p;
! 
! 		do
! 		{
! 			ConfigVariable *item_next = item_iter->next;
! 
! 			if (strcmp(item_iter->name, name) == 0)
  			{
! 				pfree(item_iter->value);
! 
! 				if (item_iter == item && value != NULL)
! 				{
! 					/* Update the parameter value. */
! 					item->value = pstrdup(value);
! 				}
! 				else if (item_iter != item || (item_iter == item && value == NULL))
! 				{
! 					/* Delete a preceding duplicate, or the item itself if required. */
! 					if (*head_p == item_iter)
! 						*head_p = item_iter->next;
! 					else
! 						prev->next = item_iter->next;
! 					if (*tail_p == item_iter)
! 						*tail_p = prev;
! 
! 					pfree(item_iter->name);
! 					pfree(item_iter->filename);
! 					pfree(item_iter);
! 				}
! 
! 				/* We've processed the last item, nothing else to do. */
! 				if (item_iter == item)
! 					return;
  			}
  			else
  			{
! 				prev = item_iter;
  			}
! 
! 			item_iter = item_next;
! 		} while (item_iter != NULL);
  	}
  
  	/* Not there; no work if we're trying to delete it */
  	if (value == NULL)
  		return;
  
! 	/* No existing item found, append a new entry */
  	item = palloc(sizeof *item);
  	item->name = pstrdup(name);
  	item->value = pstrdup(value);
