diff --git a/doc/src/sgml/bki.sgml b/doc/src/sgml/bki.sgml
index 61a736b6995f5c7830e977a1b8cb81ca9cc3b6ef..d0c08e08d9c4bab1721a1b87e080ae12782b6419 100644
--- a/doc/src/sgml/bki.sgml
+++ b/doc/src/sgml/bki.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.21 2007/02/01 00:28:16 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.22 2009/09/26 22:42:00 tgl Exp $ -->
 
 <chapter id="bki">
  <title><acronym>BKI</acronym> Backend Interface</title>
@@ -67,12 +67,13 @@
   <variablelist>
    <varlistentry>
     <term>
-     <literal>create</> 
+     <literal>create</>
+     <replaceable class="parameter">tablename</replaceable>
+     <replaceable class="parameter">tableoid</replaceable>
      <optional><literal>bootstrap</></optional>
      <optional><literal>shared_relation</></optional>
      <optional><literal>without_oids</></optional>
-     <replaceable class="parameter">tablename</replaceable>
-     <replaceable class="parameter">tableoid</replaceable>
+     <optional><literal>rowtype_oid</> <replaceable>oid</></optional>
      (<replaceable class="parameter">name1</replaceable> =
      <replaceable class="parameter">type1</replaceable> <optional>,
      <replaceable class="parameter">name2</replaceable> = <replaceable
@@ -121,6 +122,11 @@
       The table is created as shared if <literal>shared_relation</> is
       specified.
       It will have OIDs unless <literal>without_oids</> is specified.
+      The table's rowtype OID (<structname>pg_type</> OID) can optionally
+      be specified via the <literal>rowtype_oid</> clause; if not specified,
+      an OID is automatically generated for it.  (The <literal>rowtype_oid</>
+      clause is useless if <literal>bootstrap</> is specified, but it can be
+      provided anyway for documentation.)
      </para>
     </listitem>
    </varlistentry>
diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y
index 1670e462bc3506777b9089ab326841f9c240270c..0b2733148e898518d4c07e56ac27b7de859de2f1 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.97 2009/07/29 20:56:18 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.98 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -108,13 +108,13 @@ int num_columns_read = 0;
 %type <ival>  boot_const boot_ident
 %type <ival>  optbootstrap optsharedrelation optwithoutoids
 %type <ival>  boot_tuple boot_tuplelist
-%type <oidval> oidspec optoideq
+%type <oidval> oidspec optoideq optrowtypeoid
 
 %token <ival> CONST_P ID
 %token OPEN XCLOSE XCREATE INSERT_TUPLE
 %token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE XTOAST
 %token COMMA EQUALS LPAREN RPAREN
-%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS NULLVAL
+%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS XROWTYPE_OID NULLVAL
 %start TopLevel
 
 %nonassoc low
@@ -168,15 +168,15 @@ Boot_CloseStmt:
 		;
 
 Boot_CreateStmt:
-		  XCREATE optbootstrap optsharedrelation optwithoutoids boot_ident oidspec LPAREN
+		  XCREATE boot_ident oidspec optbootstrap optsharedrelation optwithoutoids optrowtypeoid LPAREN
 				{
 					do_start();
 					numattr = 0;
 					elog(DEBUG4, "creating%s%s relation %s %u",
-						 $2 ? " bootstrap" : "",
-						 $3 ? " shared" : "",
-						 LexIDStr($5),
-						 $6);
+						 $4 ? " bootstrap" : "",
+						 $5 ? " shared" : "",
+						 LexIDStr($2),
+						 $3);
 				}
 		  boot_typelist
 				{
@@ -188,9 +188,9 @@ Boot_CreateStmt:
 
 					do_start();
 
-					tupdesc = CreateTupleDesc(numattr, !($4), attrtypes);
+					tupdesc = CreateTupleDesc(numattr, !($6), attrtypes);
 
-					if ($2)
+					if ($4)
 					{
 						if (boot_reldesc)
 						{
@@ -198,13 +198,13 @@ Boot_CreateStmt:
 							closerel(NULL);
 						}
 
-						boot_reldesc = heap_create(LexIDStr($5),
+						boot_reldesc = heap_create(LexIDStr($2),
 												   PG_CATALOG_NAMESPACE,
-												   $3 ? GLOBALTABLESPACE_OID : 0,
-												   $6,
+												   $5 ? GLOBALTABLESPACE_OID : 0,
+												   $3,
 												   tupdesc,
 												   RELKIND_RELATION,
-												   $3,
+												   $5,
 												   true);
 						elog(DEBUG4, "bootstrap relation created");
 					}
@@ -212,15 +212,16 @@ Boot_CreateStmt:
 					{
 						Oid id;
 
-						id = heap_create_with_catalog(LexIDStr($5),
+						id = heap_create_with_catalog(LexIDStr($2),
 													  PG_CATALOG_NAMESPACE,
-													  $3 ? GLOBALTABLESPACE_OID : 0,
-													  $6,
+													  $5 ? GLOBALTABLESPACE_OID : 0,
+													  $3,
+													  $7,
 													  BOOTSTRAP_SUPERUSERID,
 													  tupdesc,
 													  NIL,
 													  RELKIND_RELATION,
-													  $3,
+													  $5,
 													  true,
 													  0,
 													  ONCOMMIT_NOOP,
@@ -343,6 +344,11 @@ optwithoutoids:
 		|					{ $$ = 0; }
 		;
 
+optrowtypeoid:
+			XROWTYPE_OID oidspec	{ $$ = $2; }
+		|							{ $$ = InvalidOid; }
+		;
+
 boot_typelist:
 		  boot_type_thing
 		| boot_typelist COMMA boot_type_thing
@@ -363,7 +369,7 @@ oidspec:
 
 optoideq:
 			OBJ_ID EQUALS oidspec				{ $$ = $3; }
-		|										{ $$ = (Oid) 0; }
+		|										{ $$ = InvalidOid; }
 		;
 
 boot_tuplelist:
diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index ec5d6944baf532c6d42fab44cb3325d6c94b594b..d4bcffee53416c7572cdaf6426d048d9a93f0bd9 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.48 2009/01/01 17:23:36 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.49 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -77,6 +77,7 @@ OID				{ return(OBJ_ID); }
 bootstrap		{ return(XBOOTSTRAP); }
 "shared_relation"	{ return(XSHARED_RELATION); }
 "without_oids"	{ return(XWITHOUT_OIDS); }
+"rowtype_oid"	{ return(XROWTYPE_OID); }
 _null_			{ return(NULLVAL); }
 
 insert			{ return(INSERT_TUPLE); }
diff --git a/src/backend/catalog/genbki.sh b/src/backend/catalog/genbki.sh
index 2582f426bb291e330be1653a8d07681fedbd39f3..bda9a380fdb94194af0de57a0bd56957bdc77e53 100644
--- a/src/backend/catalog/genbki.sh
+++ b/src/backend/catalog/genbki.sh
@@ -11,7 +11,7 @@
 #
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.46 2009/01/01 17:23:36 momjian Exp $
+#    $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.47 2009/09/26 22:42:01 tgl Exp $
 #
 # NOTES
 #    non-essential whitespace is removed from the generated file.
@@ -178,6 +178,7 @@ BEGIN {
 	bootstrap = "";
 	shared_relation = "";
 	without_oids = "";
+	rowtype_oid = "";
 	nc = 0;
 	reln_open = 0;
 	comment_level = 0;
@@ -319,13 +320,16 @@ comment_level > 0 { next; }
 	oid = substr(catalogandoid, pos+1, length(catalogandoid)-pos);
 
 	if ($0 ~ /BKI_BOOTSTRAP/) {
-		bootstrap = "bootstrap ";
+		bootstrap = " bootstrap";
 	}
 	if ($0 ~ /BKI_SHARED_RELATION/) {
-		shared_relation = "shared_relation ";
+		shared_relation = " shared_relation";
 	}
 	if ($0 ~ /BKI_WITHOUT_OIDS/) {
-		without_oids = "without_oids ";
+		without_oids = " without_oids";
+	}
+	if ($0 ~ /BKI_ROWTYPE_OID\([0-9]*\)/) {
+		rowtype_oid = gensub(/^.*BKI_ROWTYPE_OID\(([0-9]*)\).*$/, " rowtype_oid \\1", 1);
 	}
 
         i = 1;
@@ -351,7 +355,7 @@ inside == 1 {
 #  if this is the last line, then output the bki catalog stuff.
 # ----
 	if ($1 ~ /}/) {
-		print "create " bootstrap shared_relation without_oids catalog " " oid;
+		print "create " catalog " " oid bootstrap shared_relation without_oids rowtype_oid;
 		print "\t(";
 
 		for (j=1; j<i-1; j++) {
@@ -370,6 +374,7 @@ inside == 1 {
 		bootstrap = "";
 		shared_relation = "";
 		without_oids = "";
+		rowtype_oid = "";
 		next;
 	}
 
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 2d97dba701408fca2b0b2d645594689bef3ecc36..e9bdc882238189748b277afb35fb54bb42c6c6b3 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.358 2009/08/23 19:23:40 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.359 2009/09/26 22:42:01 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -80,6 +80,7 @@ static Oid AddNewRelationType(const char *typeName,
 				   Oid new_rel_oid,
 				   char new_rel_kind,
 				   Oid ownerid,
+				   Oid new_row_type,
 				   Oid new_array_type);
 static void RelationRemoveInheritance(Oid relid);
 static void StoreRelCheck(Relation rel, char *ccname, Node *expr,
@@ -790,10 +791,11 @@ AddNewRelationType(const char *typeName,
 				   Oid new_rel_oid,
 				   char new_rel_kind,
 				   Oid ownerid,
+				   Oid new_row_type,
 				   Oid new_array_type)
 {
 	return
-		TypeCreate(InvalidOid,	/* no predetermined OID */
+		TypeCreate(new_row_type,		/* optional predetermined OID */
 				   typeName,	/* type name */
 				   typeNamespace,		/* type namespace */
 				   new_rel_oid, /* relation oid */
@@ -836,6 +838,7 @@ heap_create_with_catalog(const char *relname,
 						 Oid relnamespace,
 						 Oid reltablespace,
 						 Oid relid,
+						 Oid reltypeid,
 						 Oid ownerid,
 						 TupleDesc tupdesc,
 						 List *cooked_constraints,
@@ -952,7 +955,9 @@ heap_create_with_catalog(const char *relname,
 
 	/*
 	 * Since defining a relation also defines a complex type, we add a new
-	 * system type corresponding to the new relation.
+	 * system type corresponding to the new relation.  The OID of the type
+	 * can be preselected by the caller, but if reltypeid is InvalidOid,
+	 * we'll generate a new OID for it.
 	 *
 	 * NOTE: we could get a unique-index failure here, in case someone else is
 	 * creating the same type name in parallel but hadn't committed yet when
@@ -963,6 +968,7 @@ heap_create_with_catalog(const char *relname,
 									  relid,
 									  relkind,
 									  ownerid,
+									  reltypeid,
 									  new_array_oid);
 
 	/*
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index 9e2f20e3bf03233ffae03bad2ffd44ed44f84189..ac7b52734ddedd3c18a3f23e5e51bd498877d579 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.18 2009/07/29 20:56:18 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.19 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -203,6 +203,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
 										   namespaceid,
 										   rel->rd_rel->reltablespace,
 										   toastOid,
+										   InvalidOid,
 										   rel->rd_rel->relowner,
 										   tupdesc,
 										   NIL,
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 1fabfb3d65c9f27356718c1411d7d5abe162f979..5c483614e33870f683fd66b7605cf4a0a66eb280 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.186 2009/06/11 20:46:11 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.187 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -703,6 +703,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace)
 										  RelationGetNamespace(OldHeap),
 										  NewTableSpace,
 										  InvalidOid,
+										  InvalidOid,
 										  OldHeap->rd_rel->relowner,
 										  tupdesc,
 										  NIL,
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a36cbc51aff79f94368a61f2a13635f04d400781..07b4af611c412074f8f300e2871a74b2c397a5b9 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.298 2009/08/23 19:23:41 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.299 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -510,6 +510,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
 										  namespaceId,
 										  tablespaceId,
 										  InvalidOid,
+										  InvalidOid,
 										  GetUserId(),
 										  descriptor,
 										  list_concat(cookedDefaults,
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 1bfe48eaac45f1df592b0aa8fc31ed87ded971a9..1fcf2afdd91e58b367aec530fc4d592c1586f997 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -26,7 +26,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.327 2009/07/29 20:56:18 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.328 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2925,6 +2925,7 @@ OpenIntoRel(QueryDesc *queryDesc)
 											  namespaceId,
 											  tablespaceId,
 											  InvalidOid,
+											  InvalidOid,
 											  GetUserId(),
 											  tupdesc,
 											  NIL,
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 5e0fc241549e41442871cc96b6779049dc1e204c..4ae915755663d988732392054bff8331240886c9 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.539 2009/09/22 23:43:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.540 2009/09/26 22:42:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*							yyyymmddN */
-#define CATALOG_VERSION_NO	200909221
+#define CATALOG_VERSION_NO	200909261
 
 #endif
diff --git a/src/include/catalog/duplicate_oids b/src/include/catalog/duplicate_oids
index ea58f4a0252ffbe009fac4eec0d281819c7ded4b..ded692ca8a93eeb0de7f335355b47196f86fc8b8 100755
--- a/src/include/catalog/duplicate_oids
+++ b/src/include/catalog/duplicate_oids
@@ -2,7 +2,7 @@
 #
 # duplicate_oids
 #
-# $PostgreSQL: pgsql/src/include/catalog/duplicate_oids,v 1.8 2006/07/31 01:16:37 tgl Exp $
+# $PostgreSQL: pgsql/src/include/catalog/duplicate_oids,v 1.9 2009/09/26 22:42:01 tgl Exp $
 #
 # finds manually-assigned oids that are duplicated in the system tables.
 #
@@ -10,11 +10,12 @@
 #
 
 # note: we exclude BKI_BOOTSTRAP relations since they are expected to have
-# matching DATA lines in pg_class.h
+# matching DATA lines in pg_class.h and pg_type.h
 
 cat pg_*.h toasting.h indexing.h | \
 egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \
 sed -n	-e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \
+	-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \
 	-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
 	-e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
 	-e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
diff --git a/src/include/catalog/genbki.h b/src/include/catalog/genbki.h
index 1bdd1f9e57898da56942d340936077d8fd889cce..4c0952f00cbecfdaff8e4be45d8fbe31bc5234a5 100644
--- a/src/include/catalog/genbki.h
+++ b/src/include/catalog/genbki.h
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/genbki.h,v 1.3 2009/06/11 14:49:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/genbki.h,v 1.4 2009/09/26 22:42:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,6 +26,7 @@
 #define BKI_BOOTSTRAP
 #define BKI_SHARED_RELATION
 #define BKI_WITHOUT_OIDS
+#define BKI_ROWTYPE_OID(oid)
 
 /* Declarations that provide the initial content of a catalog */
 /* In C, these need to expand into some harmless, repeatable declaration */
diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h
index 1d7449f1f10d4db075b483e0578af652e5db3c35..0d42cf11963624dd92f2813aa9271d0eb83aa380 100644
--- a/src/include/catalog/heap.h
+++ b/src/include/catalog/heap.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/heap.h,v 1.92 2009/08/23 19:23:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/heap.h,v 1.93 2009/09/26 22:42:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -47,6 +47,7 @@ extern Oid heap_create_with_catalog(const char *relname,
 						 Oid relnamespace,
 						 Oid reltablespace,
 						 Oid relid,
+						 Oid reltypeid,
 						 Oid ownerid,
 						 TupleDesc tupdesc,
 						 List *cooked_constraints,
diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h
index f3c19d7475db17ce3667b41524daec40726b5da3..1315e4241aca0fc2c8e5b6e220577cb056bc4064 100644
--- a/src/include/catalog/pg_attribute.h
+++ b/src/include/catalog/pg_attribute.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.152 2009/08/12 20:53:30 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.153 2009/09/26 22:42:02 tgl Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -35,8 +35,9 @@
  * ----------------
  */
 #define AttributeRelationId  1249
+#define AttributeRelation_Rowtype_Id  75
 
-CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS
+CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75)
 {
 	Oid			attrelid;		/* OID of relation containing this attribute */
 	NameData	attname;		/* name of attribute */
diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index 15a3b5f8d31f34db71516ab236c22e93160803a1..2ab4e9fda0236a575bf067a906bb71760c52cd5b 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_class.h,v 1.115 2009/08/02 22:14:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_class.h,v 1.116 2009/09/26 22:42:02 tgl Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -27,8 +27,9 @@
  * ----------------
  */
 #define RelationRelationId	1259
+#define RelationRelation_Rowtype_Id  83
 
-CATALOG(pg_class,1259) BKI_BOOTSTRAP
+CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83)
 {
 	NameData	relname;		/* class name */
 	Oid			relnamespace;	/* OID of namespace containing this class */
diff --git a/src/include/catalog/pg_database.h b/src/include/catalog/pg_database.h
index f7c2327098d533bfb91fc348e7f3dd34a22aa8f3..730c23c8635925f755df2e1f67e8ab5f9b7f41d5 100644
--- a/src/include/catalog/pg_database.h
+++ b/src/include/catalog/pg_database.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_database.h,v 1.49 2009/01/01 17:23:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_database.h,v 1.50 2009/09/26 22:42:02 tgl Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -27,8 +27,9 @@
  * ----------------
  */
 #define DatabaseRelationId	1262
+#define DatabaseRelation_Rowtype_Id  1248
 
-CATALOG(pg_database,1262) BKI_SHARED_RELATION
+CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248)
 {
 	NameData	datname;		/* database name */
 	Oid			datdba;			/* owner of database */
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index f6a9a8a838704c259ddf3c66d2a4dd7ffbac0022..0ea894854b705ea6bb9e5888353d8b7b402b3326 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.550 2009/09/01 02:54:52 alvherre Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.551 2009/09/26 22:42:02 tgl Exp $
  *
  * NOTES
  *	  The script catalog/genbki.sh reads this file and generates .bki
@@ -31,8 +31,9 @@
  * ----------------
  */
 #define ProcedureRelationId  1255
+#define ProcedureRelation_Rowtype_Id  81
 
-CATALOG(pg_proc,1255) BKI_BOOTSTRAP
+CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81)
 {
 	NameData	proname;		/* procedure name */
 	Oid			pronamespace;	/* OID of namespace containing this proc */
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 8bd23da82c392540923ee57ed69057503f47bdb4..92e6a7d1887506c6515a8ea197d8450dd4573a17 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.209 2009/08/13 21:14:31 petere Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.210 2009/09/26 22:42:03 tgl Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -32,8 +32,9 @@
  * ----------------
  */
 #define TypeRelationId	1247
+#define TypeRelation_Rowtype_Id  71
 
-CATALOG(pg_type,1247) BKI_BOOTSTRAP
+CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71)
 {
 	NameData	typname;		/* type name */
 	Oid			typnamespace;	/* OID of namespace containing this type */
@@ -330,7 +331,8 @@ DATA(insert OID = 30 (	oidvector  PGNSP PGUID -1 f b A f t \054 0	26 1013 oidvec
 DESCR("array of oids, used in system tables");
 #define OIDVECTOROID	30
 
-/* hand-built rowtype entries for bootstrapped catalogs: */
+/* hand-built rowtype entries for bootstrapped catalogs */
+/* NB: OIDs assigned here must match the BKI_ROWTYPE_OID declarations */
 
 DATA(insert OID = 71 (	pg_type			PGNSP PGUID -1 f c C f t \054 1247 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 _null_ _null_ ));
 DATA(insert OID = 75 (	pg_attribute	PGNSP PGUID -1 f c C f t \054 1249 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 _null_ _null_ ));
diff --git a/src/include/catalog/unused_oids b/src/include/catalog/unused_oids
index 4003beef5323ffefc1ab6f30c4d59988cef9faf4..371473926c77f7b1ac8e03ac6b7f683d0aeae211 100755
--- a/src/include/catalog/unused_oids
+++ b/src/include/catalog/unused_oids
@@ -2,7 +2,7 @@
 #
 # unused_oids
 #
-# $PostgreSQL: pgsql/src/include/catalog/unused_oids,v 1.8 2006/07/31 01:16:38 tgl Exp $
+# $PostgreSQL: pgsql/src/include/catalog/unused_oids,v 1.9 2009/09/26 22:42:03 tgl Exp $
 #
 #	finds blocks of manually-assignable oids that have not already been
 #	claimed by post_hackers.  primarily useful for finding available
@@ -25,11 +25,12 @@ export FIRSTOBJECTID
 
 # this part (down to the uniq step) should match the duplicate_oids script
 # note: we exclude BKI_BOOTSTRAP relations since they are expected to have
-# matching DATA lines in pg_class.h
+# matching DATA lines in pg_class.h and pg_type.h
 
 cat pg_*.h toasting.h indexing.h | \
 egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \
 sed -n	-e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \
+	-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \
 	-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
 	-e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
 	-e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
diff --git a/src/tools/msvc/Genbki.pm b/src/tools/msvc/Genbki.pm
index 73adc3e7bb676ee792c14c727c3a3695b3f9c801..0b0e24f1205c84cd92e6f555ce78e1df41509b89 100644
--- a/src/tools/msvc/Genbki.pm
+++ b/src/tools/msvc/Genbki.pm
@@ -11,7 +11,7 @@
 #
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/tools/msvc/Genbki.pm,v 1.6 2009/01/01 17:24:05 momjian Exp $
+#    $PostgreSQL: pgsql/src/tools/msvc/Genbki.pm,v 1.7 2009/09/26 22:42:03 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -79,6 +79,7 @@ sub genbki
     my $bootstrap = "";
     my $shared_relation = "";
     my $without_oids = "";
+    my $rowtype_oid = "";
     my $nc = 0;
     my $inside = 0;
     my @attr;
@@ -152,18 +153,22 @@ sub genbki
             my @fields = split /,/,$1;
             $catalog = $fields[0];
             $oid = $fields[1];
-            $bootstrap=$shared_relation=$without_oids="";
+            $bootstrap=$shared_relation=$without_oids=$rowtype_oid="";
             if ($rest =~ /BKI_BOOTSTRAP/)
             {
-                $bootstrap = "bootstrap ";
+                $bootstrap = " bootstrap";
             }
             if ($rest =~ /BKI_SHARED_RELATION/)
             {
-                $shared_relation = "shared_relation ";
+                $shared_relation = " shared_relation";
             }
             if ($rest =~ /BKI_WITHOUT_OIDS/)
             {
-                $without_oids = "without_oids ";
+                $without_oids = " without_oids";
+            }
+            if ($rest =~ /BKI_ROWTYPE_OID\((\d+)\)/)
+            {
+                $rowtype_oid = " rowtype_oid $1";
             }
             $nc++;
             $inside = 1;
@@ -176,7 +181,7 @@ sub genbki
             {
 
                 # Last line
-                $bki .= "create $bootstrap$shared_relation$without_oids$catalog $oid\n (\n";
+                $bki .= "create $catalog $oid$bootstrap$shared_relation$without_oids$rowtype_oid\n\t(\n";
                 my $first = 1;
                 for (my $i = 0; $i <= $#attr; $i++)
                 {