diff --git a/doc/src/sgml/errcodes.sgml b/doc/src/sgml/errcodes.sgml
index 950f97151bc3aab325a64b37b143e30e215bd21a..7bcff2c1d90870d8cb53e01e8961507eda7da2b7 100644
--- a/doc/src/sgml/errcodes.sgml
+++ b/doc/src/sgml/errcodes.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.8 2004/08/24 00:06:50 neilc Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.9 2004/10/01 16:39:46 tgl Exp $ -->
 
 <appendix id="errcodes-appendix">
  <title><productname>PostgreSQL</productname> Error Codes</title>
@@ -1099,6 +1099,11 @@
 <entry>CANT CHANGE RUNTIME PARAM</entry>
 </row>
 
+<row>
+<entry><literal>55P03</literal></entry>
+<entry>LOCK NOT AVAILABLE</entry>
+</row>
+
 
 <row>
 <entry>Class 57</entry>
diff --git a/doc/src/sgml/ref/lock.sgml b/doc/src/sgml/ref/lock.sgml
index cab378ec95cb12d6da61a2914eab9d3c2e9c879c..34e01c82a58edab66938d4455e0dd9f26346b0d7 100644
--- a/doc/src/sgml/ref/lock.sgml
+++ b/doc/src/sgml/ref/lock.sgml
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/lock.sgml,v 1.42 2004/03/12 00:52:23 neilc Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/lock.sgml,v 1.43 2004/10/01 16:39:47 tgl Exp $
 PostgreSQL documentation
 -->
 
@@ -37,7 +37,7 @@ where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
    if necessary for any conflicting locks to be released.  If
    <literal>NOWAIT</literal> is specified, <command>LOCK
    TABLE</command> does not wait to acquire the desired lock: if it
-   cannot be immediately acquired, the transaction is aborted and an
+   cannot be acquired immediately, the command is aborted and an
    error is emitted.  Once obtained, the lock is held for the
    remainder of the current transaction.  (There is no <command>UNLOCK
    TABLE</command> command; locks are always released at transaction
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index b8d38cc86baebec63d589df85c604fe52be3bbb2..a5426d089a9045867bcaa469a42426f15a154716 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.176 2004/09/17 18:09:55 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.177 2004/10/01 16:39:54 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -465,6 +465,13 @@ relation_open(Oid relationId, LOCKMODE lockmode)
 	return r;
 }
 
+/* ----------------
+ *		conditional_relation_open - open with option not to wait
+ *
+ *		As above, but if nowait is true, then throw an error rather than
+ *		waiting when the lock is not immediately obtainable.
+ * ----------------
+ */
 Relation
 conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait)
 {
@@ -483,7 +490,10 @@ conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait)
 		if (nowait)
 		{
 			if (!ConditionalLockRelation(r, lockmode))
-				elog(ERROR, "could not acquire relation lock");
+				ereport(ERROR,
+						(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
+						 errmsg("could not obtain lock on \"%s\"",
+								RelationGetRelationName(r))));
 		}
 		else
 			LockRelation(r, lockmode);
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 8f1b393d29a084f8e2f5221f37fba14874532969..5a12bf118919d65a08b4e241b4d7a9e6ec014125 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.477 2004/09/30 00:24:20 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.478 2004/10/01 16:39:59 tgl Exp $
  *
  * HISTORY
  *	  AUTHOR			DATE			MAJOR EVENT
@@ -7727,6 +7727,7 @@ unreserved_keyword:
 			| NOCREATEUSER
 			| NOTHING
 			| NOTIFY
+			| NOWAIT
 			| OBJECT_P
 			| OF
 			| OIDS
@@ -7944,7 +7945,6 @@ reserved_keyword:
 			| LOCALTIMESTAMP
 			| NEW
 			| NOT
-			| NOWAIT
 			| NULL_P
 			| OFF
 			| OFFSET
diff --git a/src/include/utils/errcodes.h b/src/include/utils/errcodes.h
index 5ef9461f444fc4219f0e9cf523efbd8289ca18ed..a43f6991da77134e723286db7d3b39fc8a471c29 100644
--- a/src/include/utils/errcodes.h
+++ b/src/include/utils/errcodes.h
@@ -11,7 +11,7 @@
  *
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/include/utils/errcodes.h,v 1.15 2004/08/29 05:06:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/errcodes.h,v 1.16 2004/10/01 16:40:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -308,6 +308,7 @@
 #define ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE	MAKE_SQLSTATE('5','5', '0','0','0')
 #define ERRCODE_OBJECT_IN_USE				MAKE_SQLSTATE('5','5', '0','0','6')
 #define ERRCODE_CANT_CHANGE_RUNTIME_PARAM	MAKE_SQLSTATE('5','5', 'P','0','2')
+#define ERRCODE_LOCK_NOT_AVAILABLE			MAKE_SQLSTATE('5','5', 'P','0','3')
 
 /* Class 57 - Operator Intervention (class borrowed from DB2) */
 #define ERRCODE_OPERATOR_INTERVENTION		MAKE_SQLSTATE('5','7', '0','0','0')
diff --git a/src/pl/plpgsql/src/plerrcodes.h b/src/pl/plpgsql/src/plerrcodes.h
index 5ad86ed07ed1a1ae1f5ff74f80a8666d05f14682..d5893c6ed6de045d3cea01b0c62498db2777e9ad 100644
--- a/src/pl/plpgsql/src/plerrcodes.h
+++ b/src/pl/plpgsql/src/plerrcodes.h
@@ -9,7 +9,7 @@
  *
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/plerrcodes.h,v 1.4 2004/08/29 05:07:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/plerrcodes.h,v 1.5 2004/10/01 16:40:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -659,6 +659,10 @@
 	"cant_change_runtime_param", ERRCODE_CANT_CHANGE_RUNTIME_PARAM
 },
 
+{
+	"lock_not_available", ERRCODE_LOCK_NOT_AVAILABLE
+},
+
 {
 	"operator_intervention", ERRCODE_OPERATOR_INTERVENTION
 },