*** a/src/backend/access/common/heaptuple.c
--- b/src/backend/access/common/heaptuple.c
***************
*** 863,868 **** heap_form_tuple(TupleDesc tupleDescriptor,
--- 863,869 ----
  				data_len;
  	int			hoff;
  	bool		hasnull = false;
+ 	bool		maxalign = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
  	int			i;
***************
*** 886,891 **** heap_form_tuple(TupleDesc tupleDescriptor,
--- 887,895 ----
  	 */
  	for (i = 0; i < numberOfAttributes; i++)
  	{
+ 		if (att[i]->attalign == 'd')
+ 			maxalign = true;
+ 
  		if (isnull[i])
  			hasnull = true;
  		else if (att[i]->attlen == -1 &&
***************
*** 910,916 **** heap_form_tuple(TupleDesc tupleDescriptor,
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	hoff = len = MAXALIGN(len); /* align user data safely */
  
  	data_len = heap_compute_data_size(tupleDescriptor, values, isnull);
  
--- 914,923 ----
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	if(!maxalign)
! 		hoff = len = INTALIGN(len); /* align user data safely */
! 	else
! 		hoff = len = MAXALIGN(len); /* align user data safely */
  
  	data_len = heap_compute_data_size(tupleDescriptor, values, isnull);
  
***************
*** 941,946 **** heap_form_tuple(TupleDesc tupleDescriptor,
--- 948,956 ----
  	if (tupleDescriptor->tdhasoid)		/* else leave infomask = 0 */
  		td->t_infomask = HEAP_HASOID;
  
+ 	if (!maxalign)
+ 		td->t_infomask |= HEAP_INTALIGN;
+ 
  	heap_fill_tuple(tupleDescriptor,
  					values,
  					isnull,
***************
*** 974,979 **** heap_formtuple(TupleDesc tupleDescriptor,
--- 984,990 ----
  				data_len;
  	int			hoff;
  	bool		hasnull = false;
+ 	bool		maxalign = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
  	int			i;
***************
*** 997,1002 **** heap_formtuple(TupleDesc tupleDescriptor,
--- 1008,1016 ----
  	 */
  	for (i = 0; i < numberOfAttributes; i++)
  	{
+ 		if (att[i]->attalign == 'd')
+ 			maxalign = true;
+ 
  		if (nulls[i] != ' ')
  			hasnull = true;
  		else if (att[i]->attlen == -1 &&
***************
*** 1021,1027 **** heap_formtuple(TupleDesc tupleDescriptor,
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	hoff = len = MAXALIGN(len); /* align user data safely */
  
  	data_len = ComputeDataSize(tupleDescriptor, values, nulls);
  
--- 1035,1044 ----
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	if(!maxalign)
! 		hoff = len = INTALIGN(len); /* align user data safely */
! 	else
! 		hoff = len = MAXALIGN(len); /* align user data safely */
  
  	data_len = ComputeDataSize(tupleDescriptor, values, nulls);
  
***************
*** 1052,1057 **** heap_formtuple(TupleDesc tupleDescriptor,
--- 1069,1077 ----
  	if (tupleDescriptor->tdhasoid)		/* else leave infomask = 0 */
  		td->t_infomask = HEAP_HASOID;
  
+ 	if (!maxalign)
+ 		td->t_infomask |= HEAP_INTALIGN;
+ 
  	DataFill(tupleDescriptor,
  			 values,
  			 nulls,
***************
*** 1801,1806 **** heap_form_minimal_tuple(TupleDesc tupleDescriptor,
--- 1821,1827 ----
  				data_len;
  	int			hoff;
  	bool		hasnull = false;
+ 	bool		maxalign = false;
  	Form_pg_attribute *att = tupleDescriptor->attrs;
  	int			numberOfAttributes = tupleDescriptor->natts;
  	int			i;
***************
*** 1824,1829 **** heap_form_minimal_tuple(TupleDesc tupleDescriptor,
--- 1845,1853 ----
  	 */
  	for (i = 0; i < numberOfAttributes; i++)
  	{
+ 		if (att[i]->attalign == 'd')
+ 			maxalign = true;
+ 
  		if (isnull[i])
  			hasnull = true;
  		else if (att[i]->attlen == -1 &&
***************
*** 1848,1854 **** heap_form_minimal_tuple(TupleDesc tupleDescriptor,
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	hoff = len = MAXALIGN(len); /* align user data safely */
  
  	data_len = heap_compute_data_size(tupleDescriptor, values, isnull);
  
--- 1872,1881 ----
  	if (tupleDescriptor->tdhasoid)
  		len += sizeof(Oid);
  
! 	if(!maxalign)
! 		hoff = len = INTALIGN(len); /* align user data safely */
! 	else
! 		hoff = len = MAXALIGN(len); /* align user data safely */
  
  	data_len = heap_compute_data_size(tupleDescriptor, values, isnull);
  
***************
*** 1869,1874 **** heap_form_minimal_tuple(TupleDesc tupleDescriptor,
--- 1896,1904 ----
  	if (tupleDescriptor->tdhasoid)		/* else leave infomask = 0 */
  		tuple->t_infomask = HEAP_HASOID;
  
+ 	if (!maxalign)
+ 		tuple->t_infomask |= HEAP_INTALIGN;
+ 
  	heap_fill_tuple(tupleDescriptor,
  					values,
  					isnull,
*** a/src/backend/access/heap/tuptoaster.c
--- b/src/backend/access/heap/tuptoaster.c
***************
*** 592,598 **** toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
  		hoff += BITMAPLEN(numAttrs);
  	if (newtup->t_data->t_infomask & HEAP_HASOID)
  		hoff += sizeof(Oid);
! 	hoff = MAXALIGN(hoff);
  	Assert(hoff == newtup->t_data->t_hoff);
  	/* now convert to a limit on the tuple data size */
  	maxDataLen = TOAST_TUPLE_TARGET - hoff;
--- 592,601 ----
  		hoff += BITMAPLEN(numAttrs);
  	if (newtup->t_data->t_infomask & HEAP_HASOID)
  		hoff += sizeof(Oid);
! 	if (newtup->t_data->t_infomask & HEAP_INTALIGN)
! 		hoff = INTALIGN(hoff);
! 	else
! 		hoff = MAXALIGN(hoff);
  	Assert(hoff == newtup->t_data->t_hoff);
  	/* now convert to a limit on the tuple data size */
  	maxDataLen = TOAST_TUPLE_TARGET - hoff;
***************
*** 868,874 **** toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
  			new_len += BITMAPLEN(numAttrs);
  		if (olddata->t_infomask & HEAP_HASOID)
  			new_len += sizeof(Oid);
! 		new_len = MAXALIGN(new_len);
  		Assert(new_len == olddata->t_hoff);
  		new_data_len = heap_compute_data_size(tupleDesc,
  											  toast_values, toast_isnull);
--- 871,880 ----
  			new_len += BITMAPLEN(numAttrs);
  		if (olddata->t_infomask & HEAP_HASOID)
  			new_len += sizeof(Oid);
! 		if (olddata->t_infomask & HEAP_INTALIGN)
! 			new_len = INTALIGN(new_len);
! 		else
! 			new_len = MAXALIGN(new_len);
  		Assert(new_len == olddata->t_hoff);
  		new_data_len = heap_compute_data_size(tupleDesc,
  											  toast_values, toast_isnull);
***************
*** 1019,1025 **** toast_flatten_tuple_attribute(Datum value,
  		new_len += BITMAPLEN(numAttrs);
  	if (olddata->t_infomask & HEAP_HASOID)
  		new_len += sizeof(Oid);
! 	new_len = MAXALIGN(new_len);
  	Assert(new_len == olddata->t_hoff);
  	new_data_len = heap_compute_data_size(tupleDesc,
  										  toast_values, toast_isnull);
--- 1025,1034 ----
  		new_len += BITMAPLEN(numAttrs);
  	if (olddata->t_infomask & HEAP_HASOID)
  		new_len += sizeof(Oid);
! 	if (olddata->t_infomask & HEAP_INTALIGN)
! 		new_len = MAXALIGN(new_len);
! 	else
! 		new_len = MAXALIGN(new_len);
  	Assert(new_len == olddata->t_hoff);
  	new_data_len = heap_compute_data_size(tupleDesc,
  										  toast_values, toast_isnull);
*** a/src/backend/storage/page/bufpage.c
--- b/src/backend/storage/page/bufpage.c
***************
*** 223,229 **** PageAddItem(Page page,
  	else
  		lower = phdr->pd_lower;
  
! 	alignedSize = MAXALIGN(size);
  
  	upper = (int) phdr->pd_upper - (int) alignedSize;
  
--- 223,232 ----
  	else
  		lower = phdr->pd_lower;
  
! 	if (is_heap && ((HeapTupleHeader)item)->t_infomask & HEAP_INTALIGN)
! 		alignedSize = INTALIGN(size);
! 	else
! 		alignedSize = MAXALIGN(size);
  
  	upper = (int) phdr->pd_upper - (int) alignedSize;
  
***************
*** 401,407 **** PageRepairFragmentation(Page page)
  							(errcode(ERRCODE_DATA_CORRUPTED),
  							 errmsg("corrupted item pointer: %u",
  									itemidptr->itemoff)));
! 				itemidptr->alignedlen = MAXALIGN(ItemIdGetLength(lp));
  				totallen += itemidptr->alignedlen;
  				itemidptr++;
  			}
--- 404,414 ----
  							(errcode(ERRCODE_DATA_CORRUPTED),
  							 errmsg("corrupted item pointer: %u",
  									itemidptr->itemoff)));
! 
! 				if(((HeapTupleHeader)(page + itemidptr->itemoff))->t_infomask & HEAP_INTALIGN)
! 					itemidptr->alignedlen = INTALIGN(ItemIdGetLength(lp));
! 				else
! 					itemidptr->alignedlen = MAXALIGN(ItemIdGetLength(lp));
  				totallen += itemidptr->alignedlen;
  				itemidptr++;
  			}
*** a/src/include/access/htup.h
--- b/src/include/access/htup.h
***************
*** 163,169 **** typedef HeapTupleHeaderData *HeapTupleHeader;
  #define HEAP_HASVARWIDTH		0x0002	/* has variable-width attribute(s) */
  #define HEAP_HASEXTERNAL		0x0004	/* has external stored attribute(s) */
  #define HEAP_HASOID				0x0008	/* has an object-id field */
! /* bit 0x0010 is available */
  #define HEAP_COMBOCID			0x0020	/* t_cid is a combo cid */
  #define HEAP_XMAX_EXCL_LOCK		0x0040	/* xmax is exclusive locker */
  #define HEAP_XMAX_SHARED_LOCK	0x0080	/* xmax is shared locker */
--- 163,169 ----
  #define HEAP_HASVARWIDTH		0x0002	/* has variable-width attribute(s) */
  #define HEAP_HASEXTERNAL		0x0004	/* has external stored attribute(s) */
  #define HEAP_HASOID				0x0008	/* has an object-id field */
! #define HEAP_INTALIGN           0x0010  /* INTALIGN() vs MAXALIGN heap tuples */
  #define HEAP_COMBOCID			0x0020	/* t_cid is a combo cid */
  #define HEAP_XMAX_EXCL_LOCK		0x0040	/* xmax is exclusive locker */
  #define HEAP_XMAX_SHARED_LOCK	0x0080	/* xmax is shared locker */
