Index: contrib/dblink/dblink.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/contrib/dblink/dblink.c,v
retrieving revision 1.65
diff -c -r1.65 dblink.c
*** contrib/dblink/dblink.c	27 Aug 2007 01:24:50 -0000	1.65
--- contrib/dblink/dblink.c	28 Sep 2007 02:26:18 -0000
***************
*** 1690,1696 ****
  	AclResult	aclresult;
  
  	/* open relation using relid, check permissions, get tupdesc */
! 	rel = relation_open(relid, AccessShareLock);
  
  	aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
  								  ACL_SELECT);
--- 1690,1696 ----
  	AclResult	aclresult;
  
  	/* open relation using relid, check permissions, get tupdesc */
! 	rel = relation_open(relid, AccessShareLock, true);
  
  	aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
  								  ACL_SELECT);
***************
*** 1819,1825 ****
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock);
  	tupdesc = rel->rd_att;
  	natts = tupdesc->natts;
  
--- 1819,1825 ----
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock, true);
  	tupdesc = rel->rd_att;
  	natts = tupdesc->natts;
  
***************
*** 1902,1908 ****
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock);
  	tupdesc = rel->rd_att;
  	natts = tupdesc->natts;
  
--- 1902,1908 ----
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock, true);
  	tupdesc = rel->rd_att;
  	natts = tupdesc->natts;
  
***************
*** 1954,1960 ****
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock);
  	tupdesc = rel->rd_att;
  	natts = tupdesc->natts;
  
--- 1954,1960 ----
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock, true);
  	tupdesc = rel->rd_att;
  	natts = tupdesc->natts;
  
***************
*** 2098,2104 ****
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock);
  	tupdesc = CreateTupleDescCopy(rel->rd_att);
  	relation_close(rel, AccessShareLock);
  
--- 2098,2104 ----
  	/*
  	 * Open relation using relid
  	 */
! 	rel = relation_open(relid, AccessShareLock, true);
  	tupdesc = CreateTupleDescCopy(rel->rd_att);
  	relation_close(rel, AccessShareLock);
  
Index: contrib/pgstattuple/pgstattuple.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/contrib/pgstattuple/pgstattuple.c,v
retrieving revision 1.30
diff -c -r1.30 pgstattuple.c
*** contrib/pgstattuple/pgstattuple.c	20 Sep 2007 17:56:30 -0000	1.30
--- contrib/pgstattuple/pgstattuple.c	28 Sep 2007 02:22:00 -0000
***************
*** 183,189 ****
  				 (errmsg("must be superuser to use pgstattuple functions"))));
  
  	/* open relation */
! 	rel = relation_open(relid, AccessShareLock);
  
  	PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
  }
--- 183,189 ----
  				 (errmsg("must be superuser to use pgstattuple functions"))));
  
  	/* open relation */
! 	rel = relation_open(relid, AccessShareLock, true);
  
  	PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
  }
Index: src/backend/access/heap/heapam.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/access/heap/heapam.c,v
retrieving revision 1.242
diff -c -r1.242 heapam.c
*** src/backend/access/heap/heapam.c	21 Sep 2007 21:25:42 -0000	1.242
--- src/backend/access/heap/heapam.c	28 Sep 2007 02:51:24 -0000
***************
*** 819,824 ****
--- 819,827 ----
   *		obtained on the relation.  (Generally, NoLock should only be
   *		used if the caller knows it has some appropriate lock on the
   *		relation already.)
+  *		
+  *		if wait is false open but don't wait for lock, instead throw an error 
+  *		when the requested lock is not immediately obtainable.
   *
   *		An error is raised if the relation does not exist.
   *
***************
*** 827,833 ****
   * ----------------
   */
  Relation
! relation_open(Oid relationId, LOCKMODE lockmode)
  {
  	Relation	r;
  
--- 830,836 ----
   * ----------------
   */
  Relation
! relation_open(Oid relationId, LOCKMODE lockmode, bool wait)
  {
  	Relation	r;
  
***************
*** 835,842 ****
  
  	/* Get the lock before trying to open the relcache entry */
  	if (lockmode != NoLock)
! 		LockRelationOid(relationId, lockmode);
! 
  	/* The relcache does all the real work... */
  	r = RelationIdGetRelation(relationId);
  
--- 838,865 ----
  
  	/* Get the lock before trying to open the relcache entry */
  	if (lockmode != NoLock)
! 	{
! 		if (wait)
! 			LockRelationOid(relationId, lockmode);
! 		else
! 			if (!ConditionalLockRelationOid(relationId, lockmode))
! 			{
! 				/* try to throw error by name; relation could be deleted... */
! 				char	   *relname = get_rel_name(relationId);
! 	
! 				if (relname)
! 					ereport(ERROR,
! 							(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
! 							 errmsg("could not obtain lock on relation \"%s\"",
! 									relname)));
! 				else
! 					ereport(ERROR,
! 							(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
! 						  errmsg("could not obtain lock on relation with OID %u",
! 								 relationId)));
! 			}
! 	}
! 	
  	/* The relcache does all the real work... */
  	r = RelationIdGetRelation(relationId);
  
***************
*** 892,942 ****
  	return r;
  }
  
- /* ----------------
-  *		relation_open_nowait - open but don't wait for lock
-  *
-  *		Same as relation_open, except throw an error instead of waiting
-  *		when the requested lock is not immediately obtainable.
-  * ----------------
-  */
- Relation
- relation_open_nowait(Oid relationId, LOCKMODE lockmode)
- {
- 	Relation	r;
- 
- 	Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
- 
- 	/* Get the lock before trying to open the relcache entry */
- 	if (lockmode != NoLock)
- 	{
- 		if (!ConditionalLockRelationOid(relationId, lockmode))
- 		{
- 			/* try to throw error by name; relation could be deleted... */
- 			char	   *relname = get_rel_name(relationId);
- 
- 			if (relname)
- 				ereport(ERROR,
- 						(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
- 						 errmsg("could not obtain lock on relation \"%s\"",
- 								relname)));
- 			else
- 				ereport(ERROR,
- 						(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
- 					  errmsg("could not obtain lock on relation with OID %u",
- 							 relationId)));
- 		}
- 	}
- 
- 	/* The relcache does all the real work... */
- 	r = RelationIdGetRelation(relationId);
- 
- 	if (!RelationIsValid(r))
- 		elog(ERROR, "could not open relation with OID %u", relationId);
- 
- 	pgstat_initstats(r);
- 
- 	return r;
- }
  
  /* ----------------
   *		relation_openrv - open any relation specified by a RangeVar
--- 915,920 ----
***************
*** 968,974 ****
  	relOid = RangeVarGetRelid(relation, false);
  
  	/* Let relation_open do the rest */
! 	return relation_open(relOid, lockmode);
  }
  
  /* ----------------
--- 946,952 ----
  	relOid = RangeVarGetRelid(relation, false);
  
  	/* Let relation_open do the rest */
! 	return relation_open(relOid, lockmode, true);
  }
  
  /* ----------------
***************
*** 1008,1014 ****
  {
  	Relation	r;
  
! 	r = relation_open(relationId, lockmode);
  
  	if (r->rd_rel->relkind == RELKIND_INDEX)
  		ereport(ERROR,
--- 986,992 ----
  {
  	Relation	r;
  
! 	r = relation_open(relationId, lockmode, true);
  
  	if (r->rd_rel->relkind == RELKIND_INDEX)
  		ereport(ERROR,
Index: src/backend/access/index/indexam.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/access/index/indexam.c,v
retrieving revision 1.99
diff -c -r1.99 indexam.c
*** src/backend/access/index/indexam.c	20 Sep 2007 17:56:30 -0000	1.99
--- src/backend/access/index/indexam.c	28 Sep 2007 02:29:34 -0000
***************
*** 138,144 ****
  {
  	Relation	r;
  
! 	r = relation_open(relationId, lockmode);
  
  	if (r->rd_rel->relkind != RELKIND_INDEX)
  		ereport(ERROR,
--- 138,144 ----
  {
  	Relation	r;
  
! 	r = relation_open(relationId, lockmode, true);
  
  	if (r->rd_rel->relkind != RELKIND_INDEX)
  		ereport(ERROR,
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.323
diff -c -r1.323 heap.c
*** src/backend/catalog/heap.c	8 Sep 2007 20:31:14 -0000	1.323
--- src/backend/catalog/heap.c	28 Sep 2007 02:28:46 -0000
***************
*** 437,443 ****
  		TupleDesc tupdesc;
  		int i;
  
! 		relation = relation_open(get_typ_typrelid(atttypid), AccessShareLock);
  
  		tupdesc = RelationGetDescr(relation);
  
--- 437,443 ----
  		TupleDesc tupdesc;
  		int i;
  
! 		relation = relation_open(get_typ_typrelid(atttypid), AccessShareLock, true);
  
  		tupdesc = RelationGetDescr(relation);
  
***************
*** 1131,1137 ****
  	 * when cascading from a drop of some other object, we may not have any
  	 * lock.)
  	 */
! 	rel = relation_open(relid, AccessExclusiveLock);
  
  	attr_rel = heap_open(AttributeRelationId, RowExclusiveLock);
  
--- 1131,1137 ----
  	 * when cascading from a drop of some other object, we may not have any
  	 * lock.)
  	 */
! 	rel = relation_open(relid, AccessExclusiveLock, true);
  
  	attr_rel = heap_open(AttributeRelationId, RowExclusiveLock);
  
***************
*** 1292,1298 ****
  	myattnum = ((Form_pg_attrdef) GETSTRUCT(tuple))->adnum;
  
  	/* Get an exclusive lock on the relation owning the attribute */
! 	myrel = relation_open(myrelid, AccessExclusiveLock);
  
  	/* Now we can delete the pg_attrdef row */
  	simple_heap_delete(attrdef_rel, &tuple->t_self);
--- 1292,1298 ----
  	myattnum = ((Form_pg_attrdef) GETSTRUCT(tuple))->adnum;
  
  	/* Get an exclusive lock on the relation owning the attribute */
! 	myrel = relation_open(myrelid, AccessExclusiveLock, true);
  
  	/* Now we can delete the pg_attrdef row */
  	simple_heap_delete(attrdef_rel, &tuple->t_self);
***************
*** 1345,1351 ****
  	/*
  	 * Open and lock the relation.
  	 */
! 	rel = relation_open(relid, AccessExclusiveLock);
  
  	/*
  	 * Schedule unlinking of the relation's physical file at commit.
--- 1345,1351 ----
  	/*
  	 * Open and lock the relation.
  	 */
! 	rel = relation_open(relid, AccessExclusiveLock, true);
  
  	/*
  	 * Schedule unlinking of the relation's physical file at commit.
Index: src/backend/commands/lockcmds.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/commands/lockcmds.c,v
retrieving revision 1.16
diff -c -r1.16 lockcmds.c
*** src/backend/commands/lockcmds.c	5 Jan 2007 22:19:26 -0000	1.16
--- src/backend/commands/lockcmds.c	28 Sep 2007 02:41:55 -0000
***************
*** 59,68 ****
  			aclcheck_error(aclresult, ACL_KIND_CLASS,
  						   get_rel_name(reloid));
  
! 		if (lockstmt->nowait)
! 			rel = relation_open_nowait(reloid, lockstmt->mode);
! 		else
! 			rel = relation_open(reloid, lockstmt->mode);
  
  		/* Currently, we only allow plain tables to be locked */
  		if (rel->rd_rel->relkind != RELKIND_RELATION)
--- 59,65 ----
  			aclcheck_error(aclresult, ACL_KIND_CLASS,
  						   get_rel_name(reloid));
  
! 		rel = relation_open(reloid, lockstmt->mode, !lockstmt->nowait);
  
  		/* Currently, we only allow plain tables to be locked */
  		if (rel->rd_rel->relkind != RELKIND_RELATION)
Index: src/backend/commands/sequence.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/commands/sequence.c,v
retrieving revision 1.146
diff -c -r1.146 sequence.c
*** src/backend/commands/sequence.c	20 Sep 2007 17:56:31 -0000	1.146
--- src/backend/commands/sequence.c	28 Sep 2007 02:36:31 -0000
***************
*** 853,859 ****
  	}
  
  	/* We now know we have AccessShareLock, and can safely open the rel */
! 	return relation_open(seq->relid, NoLock);
  }
  
  /*
--- 853,859 ----
  	}
  
  	/* We now know we have AccessShareLock, and can safely open the rel */
! 	return relation_open(seq->relid, NoLock, true);
  }
  
  /*
Index: src/backend/commands/tablecmds.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/commands/tablecmds.c,v
retrieving revision 1.232
diff -c -r1.232 tablecmds.c
*** src/backend/commands/tablecmds.c	6 Sep 2007 17:31:58 -0000	1.232
--- src/backend/commands/tablecmds.c	28 Sep 2007 02:32:33 -0000
***************
*** 448,454 ****
  	 * the new rel anyway until we commit), but it keeps the lock manager from
  	 * complaining about deadlock risks.
  	 */
! 	rel = relation_open(relationId, AccessExclusiveLock);
  
  	/*
  	 * Now add any newly specified column default values and CHECK constraints
--- 448,454 ----
  	 * the new rel anyway until we commit), but it keeps the lock manager from
  	 * complaining about deadlock risks.
  	 */
! 	rel = relation_open(relationId, AccessExclusiveLock, true);
  
  	/*
  	 * Now add any newly specified column default values and CHECK constraints
***************
*** 629,635 ****
  		 */
  		if (OidIsValid(toast_relid))
  		{
! 			rel = relation_open(toast_relid, AccessExclusiveLock);
  			setNewRelfilenode(rel, RecentXmin);
  			heap_close(rel, NoLock);
  		}
--- 629,635 ----
  		 */
  		if (OidIsValid(toast_relid))
  		{
! 			rel = relation_open(toast_relid, AccessExclusiveLock, true);
  			setNewRelfilenode(rel, RecentXmin);
  			heap_close(rel, NoLock);
  		}
***************
*** 1441,1447 ****
  	 * Grab an exclusive lock on the target table, which we will NOT release
  	 * until end of transaction.
  	 */
! 	targetrelation = relation_open(myrelid, AccessExclusiveLock);
  
  	/*
  	 * permissions checking.  this would normally be done in utility.c, but
--- 1441,1447 ----
  	 * Grab an exclusive lock on the target table, which we will NOT release
  	 * until end of transaction.
  	 */
! 	targetrelation = relation_open(myrelid, AccessExclusiveLock, true);
  
  	/*
  	 * permissions checking.  this would normally be done in utility.c, but
***************
*** 1637,1643 ****
  	 * Grab an exclusive lock on the target table, index, sequence or
  	 * view, which we will NOT release until end of transaction.
  	 */
! 	targetrelation = relation_open(myrelid, AccessExclusiveLock);
  
  	oldrelname = pstrdup(RelationGetRelationName(targetrelation));
  	namespaceId = RelationGetNamespace(targetrelation);
--- 1637,1643 ----
  	 * Grab an exclusive lock on the target table, index, sequence or
  	 * view, which we will NOT release until end of transaction.
  	 */
! 	targetrelation = relation_open(myrelid, AccessExclusiveLock, true);
  
  	oldrelname = pstrdup(RelationGetRelationName(targetrelation));
  	namespaceId = RelationGetNamespace(targetrelation);
***************
*** 1786,1792 ****
  void
  AlterTableInternal(Oid relid, List *cmds, bool recurse)
  {
! 	Relation rel = relation_open(relid, AccessExclusiveLock);
  
  	ATController(rel, cmds, recurse);
  }
--- 1786,1792 ----
  void
  AlterTableInternal(Oid relid, List *cmds, bool recurse)
  {
! 	Relation rel = relation_open(relid, AccessExclusiveLock, true);
  
  	ATController(rel, cmds, recurse);
  }
***************
*** 2041,2047 ****
  			/*
  			 * Exclusive lock was obtained by phase 1, needn't get it again
  			 */
! 			rel = relation_open(tab->relid, NoLock);
  
  			foreach(lcmd, subcmds)
  				ATExecCmd(tab, rel, (AlterTableCmd *) lfirst(lcmd));
--- 2041,2047 ----
  			/*
  			 * Exclusive lock was obtained by phase 1, needn't get it again
  			 */
! 			rel = relation_open(tab->relid, NoLock, true);
  
  			foreach(lcmd, subcmds)
  				ATExecCmd(tab, rel, (AlterTableCmd *) lfirst(lcmd));
***************
*** 2783,2789 ****
  
  			if (childrelid == relid)
  				continue;
! 			childrel = relation_open(childrelid, AccessExclusiveLock);
  			/* check for child relation in use in this session */
  			if (childrel->rd_refcnt != 1)
  				ereport(ERROR,
--- 2783,2789 ----
  
  			if (childrelid == relid)
  				continue;
! 			childrel = relation_open(childrelid, AccessExclusiveLock, true);
  			/* check for child relation in use in this session */
  			if (childrel->rd_refcnt != 1)
  				ereport(ERROR,
***************
*** 2820,2826 ****
  		Oid			childrelid = lfirst_oid(child);
  		Relation	childrel;
  
! 		childrel = relation_open(childrelid, AccessExclusiveLock);
  		/* check for child relation in use in this session */
  		if (childrel->rd_refcnt != 1)
  			ereport(ERROR,
--- 2820,2826 ----
  		Oid			childrelid = lfirst_oid(child);
  		Relation	childrel;
  
! 		childrel = relation_open(childrelid, AccessExclusiveLock, true);
  		/* check for child relation in use in this session */
  		if (childrel->rd_refcnt != 1)
  			ereport(ERROR,
***************
*** 2888,2894 ****
  			pg_depend->objsubid <= 0)
  			continue;
  
! 		rel = relation_open(pg_depend->objid, AccessShareLock);
  		att = rel->rd_att->attrs[pg_depend->objsubid - 1];
  
  		if (rel->rd_rel->relkind == RELKIND_RELATION)
--- 2888,2894 ----
  			pg_depend->objsubid <= 0)
  			continue;
  
! 		rel = relation_open(pg_depend->objid, AccessShareLock, true);
  		att = rel->rd_att->attrs[pg_depend->objsubid - 1];
  
  		if (rel->rd_rel->relkind == RELKIND_RELATION)
***************
*** 5373,5379 ****
  	 * Get exclusive lock till end of transaction on the target table. Use
  	 * relation_open so that we can work on indexes and sequences.
  	 */
! 	target_rel = relation_open(relationOid, AccessExclusiveLock);
  
  	/* Get its pg_class tuple, too */
  	class_rel = heap_open(RelationRelationId, RowExclusiveLock);
--- 5373,5379 ----
  	 * Get exclusive lock till end of transaction on the target table. Use
  	 * relation_open so that we can work on indexes and sequences.
  	 */
! 	target_rel = relation_open(relationOid, AccessExclusiveLock, true);
  
  	/* Get its pg_class tuple, too */
  	class_rel = heap_open(RelationRelationId, RowExclusiveLock);
***************
*** 5613,5619 ****
  			continue;
  
  		/* Use relation_open just in case it's an index */
! 		seqRel = relation_open(depForm->objid, AccessExclusiveLock);
  
  		/* skip non-sequence relations */
  		if (RelationGetForm(seqRel)->relkind != RELKIND_SEQUENCE)
--- 5613,5619 ----
  			continue;
  
  		/* Use relation_open just in case it's an index */
! 		seqRel = relation_open(depForm->objid, AccessExclusiveLock, true);
  
  		/* skip non-sequence relations */
  		if (RelationGetForm(seqRel)->relkind != RELKIND_SEQUENCE)
***************
*** 5804,5810 ****
  	/*
  	 * Need lock here in case we are recursing to toast table or index
  	 */
! 	rel = relation_open(tableOid, AccessExclusiveLock);
  
  	/*
  	 * We can never allow moving of shared or nailed-in-cache relations,
--- 5804,5810 ----
  	/*
  	 * Need lock here in case we are recursing to toast table or index
  	 */
! 	rel = relation_open(tableOid, AccessExclusiveLock, true);
  
  	/*
  	 * We can never allow moving of shared or nailed-in-cache relations,
***************
*** 6676,6682 ****
  			continue;
  
  		/* Use relation_open just in case it's an index */
! 		seqRel = relation_open(depForm->objid, AccessExclusiveLock);
  
  		/* skip non-sequence relations */
  		if (RelationGetForm(seqRel)->relkind != RELKIND_SEQUENCE)
--- 6676,6682 ----
  			continue;
  
  		/* Use relation_open just in case it's an index */
! 		seqRel = relation_open(depForm->objid, AccessExclusiveLock, true);
  
  		/* skip non-sequence relations */
  		if (RelationGetForm(seqRel)->relkind != RELKIND_SEQUENCE)
Index: src/backend/commands/typecmds.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/commands/typecmds.c,v
retrieving revision 1.107
diff -c -r1.107 typecmds.c
*** src/backend/commands/typecmds.c	4 Sep 2007 16:41:42 -0000	1.107
--- src/backend/commands/typecmds.c	28 Sep 2007 02:39:19 -0000
***************
*** 1965,1971 ****
  			Relation	rel;
  
  			/* Acquire requested lock on relation */
! 			rel = relation_open(pg_depend->objid, lockmode);
  
  			/*
  			 * Check to see if rowtype is stored anyplace as a composite-type
--- 1965,1971 ----
  			Relation	rel;
  
  			/* Acquire requested lock on relation */
! 			rel = relation_open(pg_depend->objid, lockmode, true);
  
  			/*
  			 * Check to see if rowtype is stored anyplace as a composite-type
Index: src/backend/commands/view.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/commands/view.c,v
retrieving revision 1.102
diff -c -r1.102 view.c
*** src/backend/commands/view.c	27 Aug 2007 03:36:08 -0000	1.102
--- src/backend/commands/view.c	28 Sep 2007 02:38:46 -0000
***************
*** 151,157 ****
  		/*
  		 * Yes.  Get exclusive lock on the existing view ...
  		 */
! 		rel = relation_open(viewOid, AccessExclusiveLock);
  
  		/*
  		 * Make sure it *is* a view, and do permissions checks.
--- 151,157 ----
  		/*
  		 * Yes.  Get exclusive lock on the existing view ...
  		 */
! 		rel = relation_open(viewOid, AccessExclusiveLock, true);
  
  		/*
  		 * Make sure it *is* a view, and do permissions checks.
***************
*** 314,320 ****
  	viewParse = (Query *) copyObject(viewParse);
  
  	/* need to open the rel for addRangeTableEntryForRelation */
! 	viewRel = relation_open(viewOid, AccessShareLock);
  
  	/*
  	 * Create the 2 new range table entries and form the new range table...
--- 314,320 ----
  	viewParse = (Query *) copyObject(viewParse);
  
  	/* need to open the rel for addRangeTableEntryForRelation */
! 	viewRel = relation_open(viewOid, AccessShareLock, true);
  
  	/*
  	 * Create the 2 new range table entries and form the new range table...
Index: src/backend/parser/parse_relation.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/parser/parse_relation.c,v
retrieving revision 1.128
diff -c -r1.128 parse_relation.c
*** src/backend/parser/parse_relation.c	6 Sep 2007 17:31:58 -0000	1.128
--- src/backend/parser/parse_relation.c	28 Sep 2007 02:42:59 -0000
***************
*** 1413,1419 ****
  	Relation	rel;
  
  	/* Get the tupledesc and turn it over to expandTupleDesc */
! 	rel = relation_open(relid, AccessShareLock);
  	expandTupleDesc(rel->rd_att, eref, rtindex, sublevels_up, include_dropped,
  					colnames, colvars);
  	relation_close(rel, AccessShareLock);
--- 1413,1419 ----
  	Relation	rel;
  
  	/* Get the tupledesc and turn it over to expandTupleDesc */
! 	rel = relation_open(relid, AccessShareLock, true);
  	expandTupleDesc(rel->rd_att, eref, rtindex, sublevels_up, include_dropped,
  					colnames, colvars);
  	relation_close(rel, AccessShareLock);
Index: src/backend/utils/adt/dbsize.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/utils/adt/dbsize.c,v
retrieving revision 1.14
diff -c -r1.14 dbsize.c
*** src/backend/utils/adt/dbsize.c	29 Aug 2007 17:24:29 -0000	1.14
--- src/backend/utils/adt/dbsize.c	28 Sep 2007 02:45:06 -0000
***************
*** 289,295 ****
  	Relation	rel;
  	int64		size;
  
! 	rel = relation_open(relOid, AccessShareLock);
  
  	size = calculate_relation_size(&(rel->rd_node));
  
--- 289,295 ----
  	Relation	rel;
  	int64		size;
  
! 	rel = relation_open(relOid, AccessShareLock, true);
  
  	size = calculate_relation_size(&(rel->rd_node));
  
***************
*** 329,335 ****
  	int64		size;
  	ListCell   *cell;
  
! 	heapRel = relation_open(Relid, AccessShareLock);
  	toastOid = heapRel->rd_rel->reltoastrelid;
  
  	/* Get the heap size */
--- 329,335 ----
  	int64		size;
  	ListCell   *cell;
  
! 	heapRel = relation_open(Relid, AccessShareLock, true);
  	toastOid = heapRel->rd_rel->reltoastrelid;
  
  	/* Get the heap size */
***************
*** 345,351 ****
  			Oid			idxOid = lfirst_oid(cell);
  			Relation	iRel;
  
! 			iRel = relation_open(idxOid, AccessShareLock);
  
  			size += calculate_relation_size(&(iRel->rd_node));
  
--- 345,351 ----
  			Oid			idxOid = lfirst_oid(cell);
  			Relation	iRel;
  
! 			iRel = relation_open(idxOid, AccessShareLock, true);
  
  			size += calculate_relation_size(&(iRel->rd_node));
  
Index: src/backend/utils/cache/typcache.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/backend/utils/cache/typcache.c,v
retrieving revision 1.25
diff -c -r1.25 typcache.c
*** src/backend/utils/cache/typcache.c	2 Apr 2007 03:49:39 -0000	1.25
--- src/backend/utils/cache/typcache.c	28 Sep 2007 02:44:27 -0000
***************
*** 282,288 ****
  		if (!OidIsValid(typentry->typrelid))	/* should not happen */
  			elog(ERROR, "invalid typrelid for composite type %u",
  				 typentry->type_id);
! 		rel = relation_open(typentry->typrelid, AccessShareLock);
  		Assert(rel->rd_rel->reltype == typentry->type_id);
  
  		/*
--- 282,288 ----
  		if (!OidIsValid(typentry->typrelid))	/* should not happen */
  			elog(ERROR, "invalid typrelid for composite type %u",
  				 typentry->type_id);
! 		rel = relation_open(typentry->typrelid, AccessShareLock, true);
  		Assert(rel->rd_rel->reltype == typentry->type_id);
  
  		/*
Index: src/include/access/heapam.h
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/include/access/heapam.h,v
retrieving revision 1.127
diff -c -r1.127 heapam.h
*** src/include/access/heapam.h	20 Sep 2007 17:56:32 -0000	1.127
--- src/include/access/heapam.h	28 Sep 2007 02:26:52 -0000
***************
*** 128,136 ****
   */
  
  /* in heap/heapam.c */
! extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
  extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
- extern Relation relation_open_nowait(Oid relationId, LOCKMODE lockmode);
  extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
  extern void relation_close(Relation relation, LOCKMODE lockmode);
  
--- 128,135 ----
   */
  
  /* in heap/heapam.c */
! extern Relation relation_open(Oid relationId, LOCKMODE lockmode, bool wait);
  extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode);
  extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
  extern void relation_close(Relation relation, LOCKMODE lockmode);
  
Index: src/pl/plpgsql/src/pl_comp.c
===================================================================
RCS file: /home/postgres/cvsrepo/pgsql/src/pl/plpgsql/src/pl_comp.c,v
retrieving revision 1.117
diff -c -r1.117 pl_comp.c
*** src/pl/plpgsql/src/pl_comp.c	16 Jul 2007 17:01:10 -0000	1.117
--- src/pl/plpgsql/src/pl_comp.c	28 Sep 2007 02:45:32 -0000
***************
*** 1593,1599 ****
  	/*
  	 * Open the relation to get info.
  	 */
! 	rel = relation_open(classOid, AccessShareLock);
  	classStruct = RelationGetForm(rel);
  	relname = RelationGetRelationName(rel);
  
--- 1593,1599 ----
  	/*
  	 * Open the relation to get info.
  	 */
! 	rel = relation_open(classOid, AccessShareLock, true);
  	classStruct = RelationGetForm(rel);
  	relname = RelationGetRelationName(rel);
  
