*** a/src/backend/access/heap/hio.c
--- b/src/backend/access/heap/hio.c
***************
*** 24,29 ****
--- 24,30 ----
  #include "storage/lmgr.h"
  #include "storage/smgr.h"
  
+ int extend_num_pages = 0;
  
  /*
   * RelationPutHeapTuple - place tuple at specified page
***************
*** 238,243 **** RelationGetBufferForTuple(Relation relation, Size len,
--- 239,245 ----
  	BlockNumber targetBlock,
  				otherBlock;
  	bool		needLock;
+ 	int			totalBlocks;
  
  	len = MAXALIGN(len);		/* be conservative */
  
***************
*** 449,467 **** RelationGetBufferForTuple(Relation relation, Size len,
  	 * it worth keeping an accurate file length in shared memory someplace,
  	 * rather than relying on the kernel to do it for us?
  	 */
! 	buffer = ReadBufferBI(relation, P_NEW, bistate);
! 
! 	/*
! 	 * We can be certain that locking the otherBuffer first is OK, since it
! 	 * must have a lower page number.
! 	 */
! 	if (otherBuffer != InvalidBuffer)
! 		LockBuffer(otherBuffer, BUFFER_LOCK_EXCLUSIVE);
! 
! 	/*
! 	 * Now acquire lock on the new page.
! 	 */
! 	LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
  
  	/*
  	 * Release the file-extension lock; it's now OK for someone else to extend
--- 451,491 ----
  	 * it worth keeping an accurate file length in shared memory someplace,
  	 * rather than relying on the kernel to do it for us?
  	 */
! 
! 	totalBlocks = extend_num_pages;
! 
! 	do {
! 
! 
! 		buffer = ReadBufferBI(relation, P_NEW, bistate);
! 
! 		/*
! 		 * We can be certain that locking the otherBuffer first is OK, since it
! 		 * must have a lower page number.
! 		 */
! 		if ((otherBuffer != InvalidBuffer) && !totalBlocks)
! 			LockBuffer(otherBuffer, BUFFER_LOCK_EXCLUSIVE);
! 
! 		/*
! 		 * Now acquire lock on the new page.
! 		 */
! 		LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
! 
! 		if (totalBlocks)
! 		{
! 			Page page;
! 			Size freespace;
! 
! 			page = BufferGetPage(buffer);
! 			PageInit(page, BufferGetPageSize(buf), 0);
! 
! 			freespace = PageGetHeapFreeSpace(page);
! 			MarkBufferDirty(buffer);
! 			UnlockReleaseBuffer(buffer);
! 			RecordPageWithFreeSpace(relation, BufferGetBlockNumber(buffer), freespace);
! 		}
! 
! 	}while (totalBlocks--);
  
  	/*
  	 * Release the file-extension lock; it's now OK for someone else to extend
*** a/src/backend/utils/misc/guc.c
--- b/src/backend/utils/misc/guc.c
***************
*** 31,36 ****
--- 31,37 ----
  #include "access/transam.h"
  #include "access/twophase.h"
  #include "access/xact.h"
+ #include "access/hio.h"
  #include "catalog/namespace.h"
  #include "commands/async.h"
  #include "commands/prepare.h"
***************
*** 2683,2688 **** static struct config_int ConfigureNamesInt[] =
--- 2684,2699 ----
  		NULL, NULL, NULL
  	},
  
+ 	{
+ 		{"extend_num_pages", PGC_USERSET, UNGROUPED,
+ 			gettext_noop("Sets the Number of pages to extended at one time."),
+ 			NULL
+ 		},
+ 		&extend_num_pages,
+ 		0, 0, 100,
+ 		NULL, NULL, NULL
+ 	},
+ 
  	/* End-of-list marker */
  	{
  		{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL, NULL
*** a/src/backend/utils/misc/postgresql.conf.sample
--- b/src/backend/utils/misc/postgresql.conf.sample
***************
*** 139,144 ****
--- 139,146 ----
  
  #temp_file_limit = -1			# limits per-session temp file space
  					# in kB, or -1 for no limit
+ #extend_num_pages = 0			# number of extra pages allocate during extend
+ 					# min 0 max 100 pages
  
  # - Kernel Resource Usage -
  
*** a/src/include/access/hio.h
--- b/src/include/access/hio.h
***************
*** 19,25 ****
  #include "utils/relcache.h"
  #include "storage/buf.h"
  
! 
  /*
   * state for bulk inserts --- private to heapam.c and hio.c
   *
--- 19,25 ----
  #include "utils/relcache.h"
  #include "storage/buf.h"
  
! extern int extend_num_pages;
  /*
   * state for bulk inserts --- private to heapam.c and hio.c
   *
