diff -cpr pgsql-orig/src/backend/access/common/heaptuple.c pgsql/src/backend/access/common/heaptuple.c
*** pgsql-orig/src/backend/access/common/heaptuple.c	2005-11-09 18:07:14.000000000 +0900
--- pgsql/src/backend/access/common/heaptuple.c	2005-11-09 18:38:50.000000000 +0900
*************** heap_compute_data_size(TupleDesc tupleDe
*** 43,63 ****
  					   Datum *values,
  					   bool *isnull)
  {
! 	Size		data_length = 0;
  	int			i;
  	int			numberOfAttributes = tupleDesc->natts;
  	Form_pg_attribute *att = tupleDesc->attrs;
  
  	for (i = 0; i < numberOfAttributes; i++)
  	{
  		if (isnull[i])
  			continue;
  
  		data_length = att_align(data_length, att[i]->attalign);
  		data_length = att_addlength(data_length, att[i]->attlen, values[i]);
  	}
  
! 	return data_length;
  }
  
  /* ----------------
--- 43,95 ----
  					   Datum *values,
  					   bool *isnull)
  {
! 	Size	start;
! 	Size	end;
! 	heap_compute_data_size_aligned(tupleDesc, values, isnull, 0, &start, &end);
! 	return end - start;
! }
! 
! /*
!  * heap_compute_data_size_aligned
!  *		Determine size of the data area of a tuple to be constructed
!  */
! void
! heap_compute_data_size_aligned(TupleDesc tupleDesc,
! 					   Datum *values,
! 					   bool *isnull,
! 					   Size offset,
! 					   Size *start,
! 					   Size *end)
! {
! 	Size		data_length = offset;
  	int			i;
  	int			numberOfAttributes = tupleDesc->natts;
  	Form_pg_attribute *att = tupleDesc->attrs;
  
+ 	AssertArg(start);
+ 	AssertArg(end);
+ 
  	for (i = 0; i < numberOfAttributes; i++)
  	{
  		if (isnull[i])
  			continue;
  
  		data_length = att_align(data_length, att[i]->attalign);
+ 		*start = data_length;
+ 		data_length = att_addlength(data_length, att[i]->attlen, values[i]);
+ 		i++;
+ 		break;
+ 	}
+ 	for (; i < numberOfAttributes; i++)
+ 	{
+ 		if (isnull[i])
+ 			continue;
+ 
+ 		data_length = att_align(data_length, att[i]->attalign);
  		data_length = att_addlength(data_length, att[i]->attlen, values[i]);
  	}
  
! 	*end = data_length;
  }
  
  /* ----------------
*************** heap_compute_data_size(TupleDesc tupleDe
*** 68,95 ****
   * OLD API with char 'n'/' ' convention for indicating nulls
   * ----------------
   */
! static Size
  ComputeDataSize(TupleDesc tupleDesc,
  				Datum *values,
! 				char *nulls)
  {
! 	Size		data_length = 0;
  	int			i;
  	int			numberOfAttributes = tupleDesc->natts;
  	Form_pg_attribute *att = tupleDesc->attrs;
  
  	for (i = 0; i < numberOfAttributes; i++)
  	{
  		if (nulls[i] != ' ')
  			continue;
  
  		data_length = att_align(data_length, att[i]->attalign);
  		data_length = att_addlength(data_length, att[i]->attlen, values[i]);
  	}
  
! 	return data_length;
  }
  
  /*
   * heap_fill_tuple
   *		Load data portion of a tuple from values/isnull arrays
--- 100,145 ----
   * OLD API with char 'n'/' ' convention for indicating nulls
   * ----------------
   */
! static void
  ComputeDataSize(TupleDesc tupleDesc,
  				Datum *values,
! 				char *nulls,
! 				Size offset,
! 				Size *start,
! 				Size *end)
  {
! 	Size		data_length = offset;
  	int			i;
  	int			numberOfAttributes = tupleDesc->natts;
  	Form_pg_attribute *att = tupleDesc->attrs;
  
+ 	AssertArg(start);
+ 	AssertArg(end);
+ 
  	for (i = 0; i < numberOfAttributes; i++)
  	{
  		if (nulls[i] != ' ')
  			continue;
  
  		data_length = att_align(data_length, att[i]->attalign);
+ 		*start = data_length;
  		data_length = att_addlength(data_length, att[i]->attlen, values[i]);
+ 		i++;
+ 		break;
  	}
+ 	for (; i < numberOfAttributes; i++)
+ 	{
+ 		if (nulls[i] != ' ')
+ 			continue;
  
! 		data_length = att_align(data_length, att[i]->attalign);
! 		data_length = att_addlength(data_length, att[i]->attlen, values[i]);
! 	}
! 
! 	*end = data_length;
  }
  
+ 
  /*
   * heap_fill_tuple
   *		Load data portion of a tuple from values/isnull arrays
*************** heap_form_tuple(TupleDesc tupleDescripto
*** 666,673 ****
  {
  	HeapTuple	tuple;			/* return tuple */
  	HeapTupleHeader td;			/* tuple data */
! 	unsigned long len;
! 	int			hoff;
  	bool		hasnull = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
--- 716,723 ----
  {
  	HeapTuple	tuple;			/* return tuple */
  	HeapTupleHeader td;			/* tuple data */
! 	Size		len;
! 	Size		hoff;
  	bool		hasnull = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
*************** heap_form_tuple(TupleDesc tupleDescripto
*** 714,724 ****
  		len += BITMAPLEN(numberOfAttributes);
  
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	hoff = len = MAXALIGN(len); /* align user data safely */
! 
! 	len += heap_compute_data_size(tupleDescriptor, values, isnull);
  
  	/*
  	 * Allocate and zero the space needed.	Note that the tuple body and
--- 764,775 ----
  		len += BITMAPLEN(numberOfAttributes);
  
  	if (tupleDescriptor->tdhasoid)
+ 	{
  		len += sizeof(Oid);
+ 		len = TYPEALIGN(ALIGNOF_OID, len);
+ 	}
  
! 	heap_compute_data_size_aligned(tupleDescriptor, values, isnull, len, &hoff, &len);
  
  	/*
  	 * Allocate and zero the space needed.	Note that the tuple body and
*************** heap_formtuple(TupleDesc tupleDescriptor
*** 774,781 ****
  {
  	HeapTuple	tuple;			/* return tuple */
  	HeapTupleHeader td;			/* tuple data */
! 	unsigned long len;
! 	int			hoff;
  	bool		hasnull = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
--- 825,832 ----
  {
  	HeapTuple	tuple;			/* return tuple */
  	HeapTupleHeader td;			/* tuple data */
! 	Size		len;
! 	Size		hoff;
  	bool		hasnull = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
*************** heap_formtuple(TupleDesc tupleDescriptor
*** 822,832 ****
  		len += BITMAPLEN(numberOfAttributes);
  
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	hoff = len = MAXALIGN(len); /* align user data safely */
! 
! 	len += ComputeDataSize(tupleDescriptor, values, nulls);
  
  	/*
  	 * Allocate and zero the space needed.	Note that the tuple body and
--- 873,884 ----
  		len += BITMAPLEN(numberOfAttributes);
  
  	if (tupleDescriptor->tdhasoid)
+ 	{
  		len += sizeof(Oid);
+ 		len = TYPEALIGN(ALIGNOF_OID, len);
+ 	}
  
! 	ComputeDataSize(tupleDescriptor, values, nulls, len, &hoff, &len);
  
  	/*
  	 * Allocate and zero the space needed.	Note that the tuple body and
diff -cpr pgsql-orig/src/include/access/heapam.h pgsql/src/include/access/heapam.h
*** pgsql-orig/src/include/access/heapam.h	2005-11-09 18:07:14.000000000 +0900
--- pgsql/src/include/access/heapam.h	2005-11-09 18:17:06.000000000 +0900
*************** extern XLogRecPtr log_heap_move(Relation
*** 188,193 ****
--- 188,196 ----
  /* in common/heaptuple.c */
  extern Size heap_compute_data_size(TupleDesc tupleDesc,
  					   Datum *values, bool *isnull);
+ extern void heap_compute_data_size_aligned(TupleDesc tupleDesc,
+ 					   Datum *values, bool *isnull,
+ 					   Size offset, Size *start, Size *end);
  extern void heap_fill_tuple(TupleDesc tupleDesc,
  				Datum *values, bool *isnull,
  				char *data, uint16 *infomask, bits8 *bit);
diff -cpr pgsql-orig/src/include/postgres_ext.h pgsql/src/include/postgres_ext.h
*** pgsql-orig/src/include/postgres_ext.h	2005-11-09 18:07:14.000000000 +0900
--- pgsql/src/include/postgres_ext.h	2005-11-09 18:12:24.000000000 +0900
*************** typedef unsigned int Oid;
*** 35,40 ****
--- 35,41 ----
  #endif
  
  #define OID_MAX  UINT_MAX
+ #define ALIGNOF_OID		ALIGNOF_INT
  /* you will need to include <limits.h> to use the above #define */
  
  