diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index dd9c774e2caa0f053d50648a1d38786c894282f4..4203a5a15dc1f3d7e31ee73fe8577491090d52a1 100644
--- a/src/backend/catalog/catalog.c
+++ b/src/backend/catalog/catalog.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.33 2000/07/03 20:48:28 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.34 2000/10/16 14:52:02 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "utils/syscache.h"
 
+#ifdef OLD_FILE_NAMING
 /*
  * relpath				- construct path to a relation's file
  *
@@ -104,6 +105,60 @@ relpath_blind(const char *dbname, const char *relname,
 	return path;
 }
 
+#else	/* ! OLD_FILE_NAMING */
+
+/*
+ * relpath			- construct path to a relation's file
+ *
+ * Result is a palloc'd string.
+ */
+
+char *
+relpath(RelFileNode rnode)
+{
+	char	   *path;
+
+	if (rnode.tblNode == (Oid) 0)	/* "global tablespace" */
+	{
+		/* Shared system relations live in {datadir}/global */
+		path = (char *) palloc(strlen(DataDir) + 8 + sizeof(NameData) + 1);
+		sprintf(path, "%s%cglobal%c%u", DataDir, SEP_CHAR, SEP_CHAR, rnode.relNode);
+	}
+	else
+	{
+		path = (char *) palloc(strlen(DataDir) + 6 + 2 * sizeof(NameData) + 3);
+		sprintf(path, "%s%cbase%c%u%c%u", DataDir, SEP_CHAR, SEP_CHAR, 
+			rnode.tblNode, SEP_CHAR, rnode.relNode);
+	}
+	return path;
+}
+
+/*
+ * GetDatabasePath			- construct path to a database dir
+ *
+ * Result is a palloc'd string.
+ */
+
+char *
+GetDatabasePath(Oid tblNode)
+{
+	char	   *path;
+
+	if (tblNode == (Oid) 0)	/* "global tablespace" */
+	{
+		/* Shared system relations live in {datadir}/global */
+		path = (char *) palloc(strlen(DataDir) + 8);
+		sprintf(path, "%s%cglobal", DataDir, SEP_CHAR);
+	}
+	else
+	{
+		path = (char *) palloc(strlen(DataDir) + 6 + sizeof(NameData) + 1);
+		sprintf(path, "%s%cbase%c%u", DataDir, SEP_CHAR, SEP_CHAR, tblNode);
+	}
+	return path;
+}
+
+#endif	/* OLD_FILE_NAMING */
 
 /*
  * IsSystemRelationName
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 5353108b98ead7ef9a203f9d054cd001b03a41aa..fbdd1ae0cf9fe663794c6b0a4b1ba079c867de86 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.148 2000/10/11 21:28:18 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.149 2000/10/16 14:52:02 vadim Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -177,12 +177,13 @@ heap_create(char *relname,
 {
 	static unsigned int uniqueId = 0;
 
-	Oid			relid;
-	Relation	rel;
-	bool		nailme = false;
-	int			natts = tupDesc->natts;
-	int			i;
-	MemoryContext oldcxt;
+	Oid				relid;
+	Relation		rel;
+	bool			nailme = false;
+	int				natts = tupDesc->natts;
+	int				i;
+	MemoryContext	oldcxt;
+	Oid				tblNode = MyDatabaseId;
 
 	/* ----------------
 	 *	sanity checks
@@ -203,25 +204,65 @@ heap_create(char *relname,
 	 *	descriptor follows.
 	 * ----------------
 	 */
-	if (relname && strcmp(RelationRelationName, relname) == 0)
-	{
-		relid = RelOid_pg_class;
-		nailme = true;
-	}
-	else if (relname && strcmp(AttributeRelationName, relname) == 0)
-	{
-		relid = RelOid_pg_attribute;
-		nailme = true;
-	}
-	else if (relname && strcmp(ProcedureRelationName, relname) == 0)
-	{
-		relid = RelOid_pg_proc;
-		nailme = true;
-	}
-	else if (relname && strcmp(TypeRelationName, relname) == 0)
+	if (relname && IsSystemRelationName(relname))
 	{
-		relid = RelOid_pg_type;
-		nailme = true;
+		if (strcmp(TypeRelationName, relname) == 0)
+		{
+			nailme = true;
+			relid = RelOid_pg_type;
+		}
+		else if (strcmp(AttributeRelationName, relname) == 0)
+		{
+			nailme = true;
+			relid = RelOid_pg_attribute;
+		}
+		else if (strcmp(ProcedureRelationName, relname) == 0)
+		{
+			nailme = true;
+			relid = RelOid_pg_proc;
+		}
+		else if (strcmp(RelationRelationName, relname) == 0)
+		{
+			nailme = true;
+			relid = RelOid_pg_class;
+		}
+		else if (strcmp(ShadowRelationName, relname) == 0)
+		{
+			tblNode = InvalidOid;
+			relid = RelOid_pg_shadow;
+		}
+		else if (strcmp(GroupRelationName, relname) == 0)
+		{
+			tblNode = InvalidOid;
+			relid = RelOid_pg_group;
+		}
+		else if (strcmp(DatabaseRelationName, relname) == 0)
+		{
+			tblNode = InvalidOid;
+			relid = RelOid_pg_database;
+		}
+		else if (strcmp(VariableRelationName, relname) == 0)
+		{
+			tblNode = InvalidOid;
+			relid = RelOid_pg_variable;
+		}
+		else if (strcmp(LogRelationName, relname) == 0)
+		{
+			tblNode = InvalidOid;
+			relid = RelOid_pg_log;
+		}
+		else if (strcmp(AttrDefaultRelationName, relname) == 0)
+			relid = RelOid_pg_attrdef;
+		else if (strcmp(RelCheckRelationName, relname) == 0)
+			relid = RelOid_pg_relcheck;
+		else if (strcmp(TriggerRelationName, relname) == 0)
+			relid = RelOid_pg_trigger;
+		else
+		{
+			relid = newoid();
+			if (IsSharedSystemRelationName(relname))
+				tblNode = InvalidOid;
+		}
 	}
 	else
 		relid = newoid();
@@ -290,6 +331,10 @@ heap_create(char *relname,
 		rel->rd_rel->reltype = relid;
 	}
 
+	rel->rd_node.tblNode = tblNode;
+	rel->rd_node.relNode = relid;
+	rel->rd_rel->relfilenode = relid;
+
 	/* ----------------
 	 *	done building relcache entry.
 	 * ----------------
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index f320979af99e7d20a53492e5a6689fc779b00541..f12ce4e56c73417d54500f60174613c9b21a5c7a 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.60 2000/09/06 14:15:16 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.61 2000/10/16 14:52:03 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -25,6 +25,7 @@
 
 #include "access/heapam.h"
 #include "catalog/catname.h"
+#include "catalog/catalog.h"
 #include "catalog/pg_database.h"
 #include "catalog/pg_shadow.h"
 #include "commands/comment.h"
@@ -76,6 +77,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
 	if (IsTransactionBlock())
 		elog(ERROR, "CREATE DATABASE: may not be called in a transaction block");
 
+#ifdef OLD_FILE_NAMING
 	/* Generate directory name for the new database */
 	if (dbpath == NULL || strcmp(dbpath, dbname) == 0)
 		strcpy(locbuf, dbname);
@@ -89,6 +91,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
 			 "The database path '%s' is invalid. "
 			 "This may be due to a character that is not allowed or because the chosen "
 			 "path isn't permitted for databases", dbpath);
+#endif
 
 	/*
 	 * Insert a new tuple into pg_database
@@ -111,6 +114,10 @@ createdb(const char *dbname, const char *dbpath, int encoding)
 	 */
 	heap_insert(pg_database_rel, tuple);
 
+#ifndef OLD_FILE_NAMING
+	loc = GetDatabasePath(tuple->t_data->t_oid);
+#endif
+
 	/*
 	 * Update indexes (there aren't any currently)
 	 */
@@ -140,8 +147,19 @@ createdb(const char *dbname, const char *dbpath, int encoding)
 	if (mkdir(loc, S_IRWXU) != 0)
 		elog(ERROR, "CREATE DATABASE: unable to create database directory '%s': %s", loc, strerror(errno));
 
+#ifdef OLD_FILE_NAMING
 	snprintf(buf, sizeof(buf), "cp %s%cbase%ctemplate1%c* '%s'",
 			 DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, loc);
+#else
+	{
+		char   *tmpl = GetDatabasePath(TemplateDbOid);
+
+		snprintf(buf, sizeof(buf), "cp %s%c* '%s'",
+			tmpl, SEP_CHAR, loc);
+		pfree(tmpl);
+	}
+#endif
+
 	ret = system(buf);
 	/* Some versions of SunOS seem to return ECHILD after a system() call */
 #if defined(sun)
@@ -204,12 +222,16 @@ dropdb(const char *dbname)
 	if (GetUserId() != db_owner && !use_super)
 		elog(ERROR, "DROP DATABASE: Permission denied");
 
+#ifdef OLD_FILE_NAMING
 	path = ExpandDatabasePath(dbpath);
 	if (path == NULL)
 		elog(ERROR,
 			 "The database path '%s' is invalid. "
 			 "This may be due to a character that is not allowed or because the chosen "
 			 "path isn't permitted for databases", path);
+#else
+	path = GetDatabasePath(db_id);
+#endif
 
 	/*
 	 * Obtain exclusive lock on pg_database.  We need this to ensure that
diff --git a/src/backend/commands/rename.c b/src/backend/commands/rename.c
index 0519df323dacf9ea79faa65044e1d16d7bd6a6ed..7fcf2e333f6d3bba5d73e97815678a2faa51f6cb 100644
--- a/src/backend/commands/rename.c
+++ b/src/backend/commands/rename.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.47 2000/09/06 14:15:16 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.48 2000/10/16 14:52:03 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -311,6 +311,7 @@ renamerel(const char *oldrelname, const char *newrelname)
 	if (relkind != RELKIND_INDEX)
 		TypeRename(oldrelname, newrelname);
 
+#ifdef OLD_FILE_NAMING
 	/*
 	 * Perform physical rename of files.  If this fails, we haven't yet
 	 * done anything irreversible.  NOTE that this MUST be the last step;
@@ -340,4 +341,5 @@ renamerel(const char *oldrelname, const char *newrelname)
 				 toldpath, tnewpath);
 		}
 	}
+#endif
 }
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 2f4c2a19fc3fff69c6d98fded41f09232431b561..6f9a16af35543772d8d6e685977ea6da13d31d7a 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.171 2000/10/11 17:58:01 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.172 2000/10/16 14:52:08 vadim Exp $
  *
  * NOTES
  *
@@ -60,6 +60,7 @@
 #include "getopt.h"
 #endif
 
+#include "catalog/pg_database.h"
 #include "commands/async.h"
 #include "lib/dllist.h"
 #include "libpq/auth.h"
@@ -278,8 +279,14 @@ checkDataDir(const char *DataDir)
 		exit(2);
 	}
 
+#ifdef OLD_FILE_NAMING
 	snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
 			 DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
+#else
+	snprintf(path, sizeof(path), "%s%cbase%c%u%c%u",
+			 DataDir, SEP_CHAR, SEP_CHAR, 
+			 TemplateDbOid, SEP_CHAR, RelOid_pg_class);
+#endif
 
 	fp = AllocateFile(path, PG_BINARY_R);
 	if (fp == NULL)
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 24a70d618858d19d63a14991a23ac30628610bd5..d5badefd084ebfb1be8a7ca458cc3dbdee4a4f8c 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.85 2000/09/29 03:55:45 inoue Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.86 2000/10/16 14:52:09 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -614,6 +614,9 @@ BufferAlloc(Relation reln,
 	/* record the database name and relation name for this buffer */
 	strcpy(buf->blind.dbname, DatabaseName);
 	strcpy(buf->blind.relname, RelationGetPhysicalRelationName(reln));
+#ifndef OLD_FILE_NAMING
+	buf->blind.rnode = reln->rd_node;
+#endif
 
 	INIT_BUFFERTAG(&(buf->tag), reln, blockNum);
 	if (!BufTableInsert(buf))
@@ -779,10 +782,12 @@ FlushBuffer(Buffer buffer, bool release)
 	Assert(PrivateRefCount[buffer - 1] > 0);	/* else caller didn't pin */
 
 	bufHdr = &BufferDescriptors[buffer - 1];
+
 	bufdb = bufHdr->tag.relId.dbId;
 
 	Assert(bufdb == MyDatabaseId || bufdb == (Oid) NULL);
 	bufrel = RelationIdCacheGetRelation(bufHdr->tag.relId.relId);
+
 	Assert(bufrel != (Relation) NULL);
 
 	SharedBufferChanged = true;
@@ -962,12 +967,18 @@ SetBufferDirtiedByMe(Buffer buffer, BufferDesc *bufHdr)
 
 		if (reln == (Relation) NULL)
 		{
+#ifdef OLD_FILE_NAMING
+			status = smgrblindmarkdirty(DEFAULT_SMGR,
+							BufferBlindLastDirtied[buffer - 1].dbname,
+							BufferBlindLastDirtied[buffer - 1].relname,
+							tagLastDirtied->relId.dbId,
+							tagLastDirtied->relId.relId,
+							tagLastDirtied->blockNum);
+#else
 			status = smgrblindmarkdirty(DEFAULT_SMGR,
-							   BufferBlindLastDirtied[buffer - 1].dbname,
-							  BufferBlindLastDirtied[buffer - 1].relname,
-										tagLastDirtied->relId.dbId,
-										tagLastDirtied->relId.relId,
-										tagLastDirtied->blockNum);
+							BufferBlindLastDirtied[buffer - 1].rnode,
+							tagLastDirtied->blockNum);
+#endif
 		}
 		else
 		{
@@ -1017,10 +1028,10 @@ ClearBufferDirtiedByMe(Buffer buffer, BufferDesc *bufHdr)
 	 * the data we just wrote.	This is unlikely, but possible if some
 	 * other backend replaced the buffer contents since we set our flag.
 	 */
-	if (bufHdr->tag.relId.dbId == tagLastDirtied->relId.dbId &&
-		bufHdr->tag.relId.relId == tagLastDirtied->relId.relId &&
-		bufHdr->tag.blockNum == tagLastDirtied->blockNum)
-		BufferDirtiedByMe[buffer - 1] = false;
+		if (bufHdr->tag.relId.dbId == tagLastDirtied->relId.dbId &&
+				bufHdr->tag.relId.relId == tagLastDirtied->relId.relId &&
+				bufHdr->tag.blockNum == tagLastDirtied->blockNum)
+			BufferDirtiedByMe[buffer - 1] = false;
 }
 
 /*
@@ -1136,13 +1147,21 @@ BufferSync()
 					 */
 					if (reln == (Relation) NULL)
 					{
+#ifdef OLD_FILE_NAMING
 						status = smgrblindwrt(DEFAULT_SMGR,
-											  bufHdr->blind.dbname,
-											  bufHdr->blind.relname,
-											  bufdb, bufrel,
-											  bufHdr->tag.blockNum,
-										 (char *) MAKE_PTR(bufHdr->data),
-											  true);	/* must fsync */
+											bufHdr->blind.dbname,
+											bufHdr->blind.relname,
+											bufdb, bufrel,
+											bufHdr->tag.blockNum,
+											(char *) MAKE_PTR(bufHdr->data),
+											true);	/* must fsync */
+#else
+						status = smgrblindwrt(DEFAULT_SMGR,
+											bufHdr->blind.rnode,
+											bufHdr->tag.blockNum,
+											(char *) MAKE_PTR(bufHdr->data),
+											true);	/* must fsync */
+#endif
 					}
 					else
 					{
@@ -1202,12 +1221,18 @@ BufferSync()
 			reln = RelationIdCacheGetRelation(BufferTagLastDirtied[i].relId.relId);
 			if (reln == (Relation) NULL)
 			{
+#ifdef OLD_FILE_NAMING
 				status = smgrblindmarkdirty(DEFAULT_SMGR,
-										BufferBlindLastDirtied[i].dbname,
-									   BufferBlindLastDirtied[i].relname,
-									  BufferTagLastDirtied[i].relId.dbId,
-									 BufferTagLastDirtied[i].relId.relId,
-									   BufferTagLastDirtied[i].blockNum);
+									BufferBlindLastDirtied[i].dbname,
+									BufferBlindLastDirtied[i].relname,
+									BufferTagLastDirtied[i].relId.dbId,
+									BufferTagLastDirtied[i].relId.relId,
+									BufferTagLastDirtied[i].blockNum);
+#else
+				status = smgrblindmarkdirty(DEFAULT_SMGR,
+									BufferBlindLastDirtied[i].rnode,
+									BufferTagLastDirtied[i].blockNum);
+#endif
 			}
 			else
 			{
@@ -1556,11 +1581,18 @@ BufferReplace(BufferDesc *bufHdr)
 	}
 	else
 	{
+#ifdef OLD_FILE_NAMING
 		status = smgrblindwrt(DEFAULT_SMGR, bufHdr->blind.dbname,
 							  bufHdr->blind.relname, bufdb, bufrel,
 							  bufHdr->tag.blockNum,
 							  (char *) MAKE_PTR(bufHdr->data),
 							  false);	/* no fsync */
+#else
+		status = smgrblindwrt(DEFAULT_SMGR, bufHdr->blind.rnode,
+							  bufHdr->tag.blockNum,
+							  (char *) MAKE_PTR(bufHdr->data),
+							  false);	/* no fsync */
+#endif
 	}
 
 	LockBuffer(BufferDescriptorGetBuffer(bufHdr), BUFFER_LOCK_UNLOCK);
@@ -1784,8 +1816,8 @@ blockNum=%d, flags=0x%x, refcount=%d %ld)",
 		for (i = 0; i < NBuffers; ++i, ++buf)
 		{
 			printf("[%-2d] (%s, %d) flags=0x%x, refcnt=%d %ld)\n",
-				   i, buf->blind.relname, buf->tag.blockNum,
-				   buf->flags, buf->refcount, PrivateRefCount[i]);
+					i, buf->blind.relname, buf->tag.blockNum,
+					buf->flags, buf->refcount, PrivateRefCount[i]);
 		}
 	}
 }
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 2207af4fa19f932cff04a583d5eefa23446c6c18..23551044c25d6c35d36918bd5d42ec73c6f3a067 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.74 2000/07/17 03:05:11 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.75 2000/10/16 14:52:12 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -75,8 +75,14 @@ static void mdclose_fd(int fd);
 static int	_mdfd_getrelnfd(Relation reln);
 static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags);
 static MdfdVec *_mdfd_getseg(Relation reln, int blkno);
+
+#ifdef OLD_FILE_NAMING
 static int _mdfd_blind_getseg(char *dbname, char *relname,
 				   Oid dbid, Oid relid, int blkno);
+#else
+static int _mdfd_blind_getseg(RelFileNode rnode, int blkno);
+#endif
+
 static int	_fdvec_alloc(void);
 static void _fdvec_free(int);
 static BlockNumber _mdnblocks(File file, Size blcksz);
@@ -128,7 +134,11 @@ mdcreate(Relation reln)
 
 	Assert(reln->rd_unlinked && reln->rd_fd < 0);
 
+#ifdef OLD_FILE_NAMING
 	path = relpath(RelationGetPhysicalRelationName(reln));
+#else
+	path = relpath(reln->rd_node);
+#endif
 	fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
 
 	/*
@@ -326,7 +336,11 @@ mdopen(Relation reln)
 	int			vfd;
 
 	Assert(reln->rd_fd < 0);
+#ifdef OLD_FILE_NAMING
 	path = relpath(RelationGetPhysicalRelationName(reln));
+#else
+	path = relpath(reln->rd_node);
+#endif
 
 	fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
 	if (fd < 0)
@@ -565,6 +579,7 @@ mdflush(Relation reln, BlockNumber blocknum, char *buffer)
  *		the file, making it more like mdflush().
  */
 int
+#ifdef OLD_FILE_NAMING
 mdblindwrt(char *dbname,
 		   char *relname,
 		   Oid dbid,
@@ -572,12 +587,22 @@ mdblindwrt(char *dbname,
 		   BlockNumber blkno,
 		   char *buffer,
 		   bool dofsync)
+#else
+mdblindwrt(RelFileNode rnode,
+		   BlockNumber blkno,
+		   char *buffer,
+		   bool dofsync)
+#endif
 {
 	int			status;
 	long		seekpos;
 	int			fd;
 
+#ifdef OLD_FILE_NAMING
 	fd = _mdfd_blind_getseg(dbname, relname, dbid, relid, blkno);
+#else
+	fd = _mdfd_blind_getseg(rnode, blkno);
+#endif
 
 	if (fd < 0)
 		return SM_FAIL;
@@ -651,16 +676,25 @@ mdmarkdirty(Relation reln, BlockNumber blkno)
  *		rather than building md/fd datastructures to postpone it till later.
  */
 int
+#ifdef OLD_FILE_NAMING
 mdblindmarkdirty(char *dbname,
 				 char *relname,
 				 Oid dbid,
 				 Oid relid,
 				 BlockNumber blkno)
+#else
+mdblindmarkdirty(RelFileNode rnode,
+				 BlockNumber blkno)
+#endif
 {
 	int			status;
 	int			fd;
 
+#ifdef OLD_FILE_NAMING
 	fd = _mdfd_blind_getseg(dbname, relname, dbid, relid, blkno);
+#else
+	fd = _mdfd_blind_getseg(rnode, blkno);
+#endif
 
 	if (fd < 0)
 		return SM_FAIL;
@@ -969,7 +1003,11 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
 			   *fullpath;
 
 	/* be sure we have enough space for the '.segno', if any */
+#ifdef OLD_FILE_NAMING
 	path = relpath(RelationGetPhysicalRelationName(reln));
+#else
+	path = relpath(reln->rd_node);
+#endif
 
 	if (segno > 0)
 	{
@@ -1084,8 +1122,12 @@ _mdfd_getseg(Relation reln, int blkno)
  */
 
 static int
+#ifdef OLD_FILE_NAMING
 _mdfd_blind_getseg(char *dbname, char *relname, Oid dbid, Oid relid,
 				   int blkno)
+#else
+_mdfd_blind_getseg(RelFileNode rnode, int blkno)
+#endif
 {
 	char	   *path;
 	int			fd;
@@ -1095,8 +1137,12 @@ _mdfd_blind_getseg(char *dbname, char *relname, Oid dbid, Oid relid,
 
 #endif
 
+#ifdef OLD_FILE_NAMING
 	/* construct the path to the relation */
 	path = relpath_blind(dbname, relname, dbid, relid);
+#else
+	path = relpath(rnode);
+#endif
 
 #ifndef LET_OS_MANAGE_FILESIZE
 	/* append the '.segno', if needed */
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c
index 1eb17a60b2ef0385118c82b9d74a03dbd38077b1..8bcb13fd4e2f9695f367194642ac48843b5c5c42 100644
--- a/src/backend/storage/smgr/smgr.c
+++ b/src/backend/storage/smgr/smgr.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.39 2000/10/02 21:45:33 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.40 2000/10/16 14:52:12 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -36,14 +36,23 @@ typedef struct f_smgr
 										   char *buffer);
 	int			(*smgr_flush) (Relation reln, BlockNumber blocknum,
 										   char *buffer);
+#ifdef OLD_FILE_NAMING
 	int			(*smgr_blindwrt) (char *dbname, char *relname,
 											  Oid dbid, Oid relid,
 										 BlockNumber blkno, char *buffer,
 											  bool dofsync);
+#else
+	int			(*smgr_blindwrt) (RelFileNode rnode, BlockNumber blkno, 
+										char *buffer, bool dofsync);
+#endif
 	int			(*smgr_markdirty) (Relation reln, BlockNumber blkno);
+#ifdef OLD_FILE_NAMING
 	int			(*smgr_blindmarkdirty) (char *dbname, char *relname,
 													Oid dbid, Oid relid,
 													BlockNumber blkno);
+#else
+	int			(*smgr_blindmarkdirty) (RelFileNode, BlockNumber blkno);
+#endif
 	int			(*smgr_nblocks) (Relation reln);
 	int			(*smgr_truncate) (Relation reln, int nblocks);
 	int			(*smgr_commit) (void);	/* may be NULL */
@@ -301,6 +310,7 @@ smgrflush(int16 which, Relation reln, BlockNumber blocknum, char *buffer)
  *		this page down to stable storage in this circumstance.	The
  *		write should be synchronous if dofsync is true.
  */
+#ifdef OLD_FILE_NAMING
 int
 smgrblindwrt(int16 which,
 			 char *dbname,
@@ -332,6 +342,27 @@ smgrblindwrt(int16 which,
 	return status;
 }
 
+#else
+
+int
+smgrblindwrt(int16 which,
+			 RelFileNode rnode,
+			 BlockNumber blkno,
+			 char *buffer,
+			 bool dofsync)
+{
+	int			status;
+
+	status = (*(smgrsw[which].smgr_blindwrt)) (rnode, blkno, buffer, dofsync);
+
+	if (status == SM_FAIL)
+		elog(ERROR, "cannot write block %d of %u/%u blind: %m",
+			 blkno, rnode.tblNode, rnode.relNode);
+
+	return status;
+}
+#endif
+
 /*
  *	smgrmarkdirty() -- Mark a page dirty (needs fsync).
  *
@@ -363,6 +394,7 @@ smgrmarkdirty(int16 which,
  *
  *		Just like smgrmarkdirty, except we don't have a reldesc.
  */
+#ifdef OLD_FILE_NAMING
 int
 smgrblindmarkdirty(int16 which,
 				   char *dbname,
@@ -393,6 +425,25 @@ smgrblindmarkdirty(int16 which,
 	return status;
 }
 
+#else
+
+int
+smgrblindmarkdirty(int16 which,
+				   RelFileNode rnode,
+				   BlockNumber blkno)
+{
+	int			status;
+
+	status = (*(smgrsw[which].smgr_blindmarkdirty)) (rnode, blkno);
+
+	if (status == SM_FAIL)
+		elog(ERROR, "cannot mark block %d of %u/%u blind: %m",
+			 blkno, rnode.tblNode, rnode.relNode);
+
+	return status;
+}
+#endif
+
 /*
  *	smgrnblocks() -- Calculate the number of POSTGRES blocks in the
  *					 supplied relation.
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index e39f1cfd12d4b7b71ccf7763f368342b0cd8f6ed..755359e2514a4333b15c26a7ed6f84e6843b140b 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.111 2000/09/12 04:49:13 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.112 2000/10/16 14:52:13 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1017,6 +1017,12 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
 	 */
 	RelationInitLockInfo(relation);		/* see lmgr.c */
 
+	if (IsSharedSystemRelationName(NameStr(relation->rd_rel->relname)))
+		relation->rd_node.tblNode = InvalidOid;
+	else
+		relation->rd_node.tblNode = MyDatabaseId;
+	relation->rd_node.relNode = relation->rd_rel->relfilenode;
+
 	/* ----------------
 	 *	open the relation and assign the file descriptor returned
 	 *	by the storage manager code to rd_fd.
@@ -1192,6 +1198,13 @@ formrdesc(char *relationName,
 	 */
 	RelationCacheInsert(relation);
 
+	if (IsSharedSystemRelationName(relationName))
+		relation->rd_node.tblNode = InvalidOid;
+	else
+		relation->rd_node.tblNode = MyDatabaseId;
+	relation->rd_node.relNode = 
+		relation->rd_rel->relfilenode = RelationGetRelid(relation);
+
 	/*
 	 * Determining this requires a scan on pg_class, but to do the scan
 	 * the rdesc for pg_class must already exist.  Therefore we must do
@@ -2438,6 +2451,8 @@ init_irels(void)
 		/* the file descriptor is not yet opened */
 		ird->rd_fd = -1;
 
+		ird->rd_node.tblNode = MyDatabaseId;
+
 		/* next, read the access method tuple form */
 		if ((nread = FileRead(fd, (char *) &len, sizeof(len))) != sizeof(len))
 		{
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index cc3a3825c408a6cf22af69d085acc00880e95c6e..cee8dfaac90acf553bc1250ce755c53adcc5641d 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.67 2000/10/02 19:42:54 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.68 2000/10/16 14:52:15 vadim Exp $
  *
  *
  *-------------------------------------------------------------------------
@@ -21,6 +21,10 @@
 #include <math.h>
 #include <unistd.h>
 
+#ifndef OLD_FILE_NAMING
+#include "catalog/catalog.h"
+#endif
+
 #include "access/heapam.h"
 #include "catalog/catname.h"
 #include "catalog/pg_database.h"
@@ -242,7 +246,12 @@ InitPostgres(const char *dbname, const char *username)
 	 */
 	if (bootstrap)
 	{
+		MyDatabaseId = TemplateDbOid;
+#ifdef OLD_FILE_NAMING
 		SetDatabasePath(ExpandDatabasePath(dbname));
+#else
+		SetDatabasePath(GetDatabasePath(MyDatabaseId));
+#endif
 		LockDisable(true);
 	}
 	else
@@ -276,9 +285,13 @@ InitPostgres(const char *dbname, const char *username)
 				 "Database \"%s\" does not exist in the system catalog.",
 				 dbname);
 
+#ifdef OLD_FILE_NAMING
 		fullpath = ExpandDatabasePath(datpath);
 		if (!fullpath)
 			elog(FATAL, "Database path could not be resolved.");
+#else
+		fullpath = GetDatabasePath(MyDatabaseId);
+#endif
 
 		/* Verify the database path */
 
diff --git a/src/backend/utils/misc/database.c b/src/backend/utils/misc/database.c
index 4be24e164f183d38681325fa211710889194019a..f415e5aee1821813588bcad9fb029e51f2d38aa3 100644
--- a/src/backend/utils/misc/database.c
+++ b/src/backend/utils/misc/database.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.39 2000/07/03 20:48:42 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.40 2000/10/16 14:52:19 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,6 +22,7 @@
 
 #include "access/xact.h"
 #include "catalog/catname.h"
+#include "catalog/catalog.h"
 #include "catalog/pg_database.h"
 #include "miscadmin.h"
 #include "utils/syscache.h"
@@ -143,8 +144,17 @@ GetRawDatabaseInfo(const char *name, Oid *db_id, char *path)
 	char	   *dbfname;
 	Form_pg_database tup_db;
 
+#ifdef OLD_FILE_NAMING
 	dbfname = (char *) palloc(strlen(DataDir) + 8 + strlen(DatabaseRelationName) + 2);
 	sprintf(dbfname, "%s/global/%s", DataDir, DatabaseRelationName);
+#else
+	{
+		RelFileNode	rnode;
+		rnode.tblNode = 0;
+		rnode.relNode = RelOid_pg_database;
+		dbfname = relpath(rnode);
+	}
+#endif
 
 	if ((dbfd = open(dbfname, O_RDONLY | PG_BINARY, 0)) < 0)
 		elog(FATAL, "cannot open %s: %s", dbfname, strerror(errno));
diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh
index 6b7e474d5e834aed6959eabf2e9d82329ba42071..86d8d0289ea0036137e81a4c5cb963416da0e18e 100644
--- a/src/bin/initdb/initdb.sh
+++ b/src/bin/initdb/initdb.sh
@@ -23,7 +23,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.104 2000/09/29 13:38:02 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.105 2000/10/16 14:52:21 vadim Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -414,8 +414,8 @@ fi
 #
 # CREATE TEMPLATE1 DATABASE
 
-rm -rf "$PGDATA"/base/template1 || exit_nicely
-mkdir "$PGDATA"/base/template1 || exit_nicely
+rm -rf "$PGDATA"/base/1 || exit_nicely
+mkdir "$PGDATA"/base/1 || exit_nicely
 
 if [ "$debug" = yes ]
 then
@@ -427,7 +427,7 @@ fi
 BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG"
 FIRSTRUN="-boot -x -C -F -D$PGDATA $BACKEND_TALK_ARG"
 
-echo "Creating template database in $PGDATA/base/template1"
+echo "Creating template database in $PGDATA/base/1"
 [ "$debug" = yes ] && echo "Running: $PGPATH/postgres $FIRSTRUN template1"
 
 cat "$TEMPLATE1_BKI" \
@@ -435,7 +435,7 @@ cat "$TEMPLATE1_BKI" \
 | "$PGPATH"/postgres $FIRSTRUN template1 \
 || exit_nicely
 
-echo $short_version > "$PGDATA"/base/template1/PG_VERSION || exit_nicely
+echo $short_version > "$PGDATA"/base/1/PG_VERSION || exit_nicely
 
 
 ##########################################################################
@@ -450,6 +450,7 @@ then
     cat "$GLOBAL_BKI" \
     | sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
           -e "s/PGUID/$POSTGRES_SUPERUSERID/g" \
+          -e "s/ENCODING/$MULTIBYTEID/g" \
     | "$PGPATH"/postgres $BACKENDARGS template1 \
     || exit_nicely
 
@@ -459,20 +460,6 @@ then
     cp "$POSTGRESQL_CONF_SAMPLE" "$PGDATA"/postgresql.conf || exit_nicely
     chmod 0600 "$PGDATA"/pg_hba.conf "$PGDATA"/postgresql.conf
 
-    echo "Adding template1 database to pg_database"
-
-    echo "open pg_database" > "$TEMPFILE"
-    echo "insert (template1 $POSTGRES_SUPERUSERID $MULTIBYTEID template1)" >> $TEMPFILE
-    #echo "show" >> "$TEMPFILE"
-    echo "close pg_database" >> "$TEMPFILE"
-
-    [ "$debug" = yes ] && echo "Running: $PGPATH/postgres $BACKENDARGS template1 < $TEMPFILE"
-
-    "$PGPATH"/postgres $BACKENDARGS template1 < "$TEMPFILE"
-    # Gotta remove that temp file before exiting on error.
-    retval="$?"
-    rm -f "$TEMPFILE" || exit_nicely
-    [ "$retval" -ne 0 ] && exit_nicely
 fi
 
 
diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h
index 5ed346681c52bc6cdbec3fd45f4b40e95bde754f..b1d51d520de8bb180377abfe15b90a71ce519364 100644
--- a/src/include/catalog/catalog.h
+++ b/src/include/catalog/catalog.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catalog.h,v 1.12 2000/04/12 17:16:27 momjian Exp $
+ * $Id: catalog.h,v 1.13 2000/10/16 14:52:26 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -16,9 +16,18 @@
 
 #include "access/tupdesc.h"
 
+#ifdef OLD_FILE_NAMING
+
 extern char *relpath(const char *relname);
 extern char *relpath_blind(const char *dbname, const char *relname,
 			  Oid dbid, Oid relid);
+#else
+#include "storage/relfilenode.h"
+
+extern char *relpath(RelFileNode rnode);
+extern char *GetDatabasePath(Oid tblNode);
+#endif
+
 extern bool IsSystemRelationName(const char *relname);
 extern bool IsSharedSystemRelationName(const char *relname);
 extern Oid	newoid(void);
diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h
index 260ff7d106fae6a3391d688a1318f7ebcaf5b62b..4b1d8dc34392893a1dd7cc4c9659c63d8144a7cc 100644
--- a/src/include/catalog/pg_attribute.h
+++ b/src/include/catalog/pg_attribute.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_attribute.h,v 1.64 2000/10/05 19:48:31 momjian Exp $
+ * $Id: pg_attribute.h,v 1.65 2000/10/16 14:52:26 vadim Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -426,45 +426,47 @@ DATA(insert OID = 0 ( 1249 tableoid			26 0  4  -7 0 -1 -1 t p f i f f));
 { 1259, {"reltype"},	   26, 0,	4,	2, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
 { 1259, {"relowner"},	   23, 0,	4,	3, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
 { 1259, {"relam"},		   26, 0,	4,	4, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
-{ 1259, {"relpages"},	   23, 0,	4,	5, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
-{ 1259, {"reltuples"},	   23, 0,	4,	6, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
-{ 1259, {"reltoastrelid"}, 26, 0,	4,	7, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
-{ 1259, {"reltoastidxid"}, 26, 0,	4,	8, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
-{ 1259, {"relhasindex"},   16, 0,	1,	9, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
-{ 1259, {"relisshared"},   16, 0,	1, 10, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
-{ 1259, {"relkind"},	   18, 0,	1, 11, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
-{ 1259, {"relnatts"},	   21, 0,	2, 12, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
-{ 1259, {"relchecks"},	   21, 0,	2, 13, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
-{ 1259, {"reltriggers"},   21, 0,	2, 14, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
-{ 1259, {"relukeys"},	   21, 0,	2, 15, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
-{ 1259, {"relfkeys"},	   21, 0,	2, 16, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
-{ 1259, {"relrefs"},	   21, 0,	2, 17, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
-{ 1259, {"relhaspkey"},    16, 0,	1, 18, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
-{ 1259, {"relhasrules"},   16, 0,	1, 19, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
-{ 1259, {"relhassubclass"},16, 0,	1, 20, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
-{ 1259, {"relacl"},		 1034, 0,  -1, 21, 0, -1, -1,	'\0', 'x', '\0', 'i', '\0', '\0' }
+{ 1259, {"relfilenode"},   26, 0,	4,	5, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
+{ 1259, {"relpages"},	   23, 0,	4,	6, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
+{ 1259, {"reltuples"},	   23, 0,	4,	7, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
+{ 1259, {"reltoastrelid"}, 26, 0,	4,	8, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
+{ 1259, {"reltoastidxid"}, 26, 0,	4,	9, 0, -1, -1, '\001', 'p', '\0', 'i', '\0', '\0' }, \
+{ 1259, {"relhasindex"},   16, 0,	1, 10, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
+{ 1259, {"relisshared"},   16, 0,	1, 11, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
+{ 1259, {"relkind"},	   18, 0,	1, 12, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
+{ 1259, {"relnatts"},	   21, 0,	2, 13, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
+{ 1259, {"relchecks"},	   21, 0,	2, 14, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
+{ 1259, {"reltriggers"},   21, 0,	2, 15, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
+{ 1259, {"relukeys"},	   21, 0,	2, 16, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
+{ 1259, {"relfkeys"},	   21, 0,	2, 17, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
+{ 1259, {"relrefs"},	   21, 0,	2, 18, 0, -1, -1, '\001', 'p', '\0', 's', '\0', '\0' }, \
+{ 1259, {"relhaspkey"},    16, 0,	1, 19, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
+{ 1259, {"relhasrules"},   16, 0,	1, 20, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
+{ 1259, {"relhassubclass"},16, 0,	1, 21, 0, -1, -1, '\001', 'p', '\0', 'c', '\0', '\0' }, \
+{ 1259, {"relacl"},		 1034, 0,  -1, 22, 0, -1, -1,	'\0', 'x', '\0', 'i', '\0', '\0' }
 
 DATA(insert OID = 0 ( 1259 relname			19 0 NAMEDATALEN   1 0 -1 -1 f p f i f f));
 DATA(insert OID = 0 ( 1259 reltype			26 0  4   2 0 -1 -1 t p f i f f));
 DATA(insert OID = 0 ( 1259 relowner			23 0  4   3 0 -1 -1 t p f i f f));
 DATA(insert OID = 0 ( 1259 relam			26 0  4   4 0 -1 -1 t p f i f f));
-DATA(insert OID = 0 ( 1259 relpages			23 0  4   5 0 -1 -1 t p f i f f));
-DATA(insert OID = 0 ( 1259 reltuples		23 0  4   6 0 -1 -1 t p f i f f));
-DATA(insert OID = 0 ( 1259 reltoastrelid	26 0  4   7 0 -1 -1 t p f i f f));
-DATA(insert OID = 0 ( 1259 reltoastidxid	26 0  4   8 0 -1 -1 t p f i f f));
-DATA(insert OID = 0 ( 1259 relhasindex		16 0  1   9 0 -1 -1 t p f c f f));
-DATA(insert OID = 0 ( 1259 relisshared		16 0  1  10 0 -1 -1 t p f c f f));
-DATA(insert OID = 0 ( 1259 relkind			18 0  1  11 0 -1 -1 t p f c f f));
-DATA(insert OID = 0 ( 1259 relnatts			21 0  2  12 0 -1 -1 t p f s f f));
-DATA(insert OID = 0 ( 1259 relchecks		21 0  2  13 0 -1 -1 t p f s f f));
-DATA(insert OID = 0 ( 1259 reltriggers		21 0  2  14 0 -1 -1 t p f s f f));
-DATA(insert OID = 0 ( 1259 relukeys			21 0  2  15 0 -1 -1 t p f s f f));
-DATA(insert OID = 0 ( 1259 relfkeys			21 0  2  16 0 -1 -1 t p f s f f));
-DATA(insert OID = 0 ( 1259 relrefs			21 0  2  17 0 -1 -1 t p f s f f));
-DATA(insert OID = 0 ( 1259 relhaspkey		16 0  1  18 0 -1 -1 t p f c f f));
-DATA(insert OID = 0 ( 1259 relhasrules		16 0  1  19 0 -1 -1 t p f c f f));
-DATA(insert OID = 0 ( 1259 relhassubclass	16 0  1  20 0 -1 -1 t p f c f f));
-DATA(insert OID = 0 ( 1259 relacl		  1034 0 -1  21 0 -1 -1 f x f i f f));
+DATA(insert OID = 0 ( 1259 relfilenode		26 0  4   5 0 -1 -1 t p f i f f));
+DATA(insert OID = 0 ( 1259 relpages			23 0  4   6 0 -1 -1 t p f i f f));
+DATA(insert OID = 0 ( 1259 reltuples		23 0  4   7 0 -1 -1 t p f i f f));
+DATA(insert OID = 0 ( 1259 reltoastrelid	26 0  4   8 0 -1 -1 t p f i f f));
+DATA(insert OID = 0 ( 1259 reltoastidxid	26 0  4   9 0 -1 -1 t p f i f f));
+DATA(insert OID = 0 ( 1259 relhasindex		16 0  1  10 0 -1 -1 t p f c f f));
+DATA(insert OID = 0 ( 1259 relisshared		16 0  1  11 0 -1 -1 t p f c f f));
+DATA(insert OID = 0 ( 1259 relkind			18 0  1  12 0 -1 -1 t p f c f f));
+DATA(insert OID = 0 ( 1259 relnatts			21 0  2  13 0 -1 -1 t p f s f f));
+DATA(insert OID = 0 ( 1259 relchecks		21 0  2  14 0 -1 -1 t p f s f f));
+DATA(insert OID = 0 ( 1259 reltriggers		21 0  2  15 0 -1 -1 t p f s f f));
+DATA(insert OID = 0 ( 1259 relukeys			21 0  2  16 0 -1 -1 t p f s f f));
+DATA(insert OID = 0 ( 1259 relfkeys			21 0  2  17 0 -1 -1 t p f s f f));
+DATA(insert OID = 0 ( 1259 relrefs			21 0  2  18 0 -1 -1 t p f s f f));
+DATA(insert OID = 0 ( 1259 relhaspkey		16 0  1  19 0 -1 -1 t p f c f f));
+DATA(insert OID = 0 ( 1259 relhasrules		16 0  1  20 0 -1 -1 t p f c f f));
+DATA(insert OID = 0 ( 1259 relhassubclass	16 0  1  21 0 -1 -1 t p f c f f));
+DATA(insert OID = 0 ( 1259 relacl		  1034 0 -1  22 0 -1 -1 f x f i f f));
 DATA(insert OID = 0 ( 1259 ctid				27 0  6  -1 0 -1 -1 f p f i f f));
 DATA(insert OID = 0 ( 1259 oid				26 0  4  -2 0 -1 -1 t p f i f f));
 DATA(insert OID = 0 ( 1259 xmin				28 0  4  -3 0 -1 -1 t p f i f f));
diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index 3fc4a7fd76cc3febf1df81be65eff4a43b25491b..543d4b3f2fcfe47907ca25da5d768aef50d30cc7 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_class.h,v 1.40 2000/09/12 04:49:15 momjian Exp $
+ * $Id: pg_class.h,v 1.41 2000/10/16 14:52:26 vadim Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -50,6 +50,7 @@ CATALOG(pg_class) BOOTSTRAP
 	Oid			reltype;
 	int4		relowner;
 	Oid			relam;
+	Oid			relfilenode;
 	int4		relpages;
 	int4		reltuples;
 	Oid			reltoastrelid;
@@ -99,60 +100,61 @@ typedef FormData_pg_class *Form_pg_class;
  *		relacl field.
  * ----------------
  */
-#define Natts_pg_class_fixed			20
-#define Natts_pg_class					21
+#define Natts_pg_class_fixed			21
+#define Natts_pg_class					22
 #define Anum_pg_class_relname			1
 #define Anum_pg_class_reltype			2
 #define Anum_pg_class_relowner			3
 #define Anum_pg_class_relam				4
-#define Anum_pg_class_relpages			5
-#define Anum_pg_class_reltuples			6
-#define Anum_pg_class_reltoastrelid		7
-#define Anum_pg_class_reltoastidxid		8
-#define Anum_pg_class_relhasindex		9
-#define Anum_pg_class_relisshared		10
-#define Anum_pg_class_relkind			11
-#define Anum_pg_class_relnatts			12
-#define Anum_pg_class_relchecks			13
-#define Anum_pg_class_reltriggers		14
-#define Anum_pg_class_relukeys			15
-#define Anum_pg_class_relfkeys			16
-#define Anum_pg_class_relrefs			17
-#define Anum_pg_class_relhaspkey		18
-#define Anum_pg_class_relhasrules		19
-#define Anum_pg_class_relhassubclass	20
-#define Anum_pg_class_relacl			21
+#define Anum_pg_class_relfilenode		5
+#define Anum_pg_class_relpages			6
+#define Anum_pg_class_reltuples			7
+#define Anum_pg_class_reltoastrelid		8
+#define Anum_pg_class_reltoastidxid		9
+#define Anum_pg_class_relhasindex		10
+#define Anum_pg_class_relisshared		11
+#define Anum_pg_class_relkind			12
+#define Anum_pg_class_relnatts			13
+#define Anum_pg_class_relchecks			14
+#define Anum_pg_class_reltriggers		15
+#define Anum_pg_class_relukeys			16
+#define Anum_pg_class_relfkeys			17
+#define Anum_pg_class_relrefs			18
+#define Anum_pg_class_relhaspkey		19
+#define Anum_pg_class_relhasrules		20
+#define Anum_pg_class_relhassubclass	21
+#define Anum_pg_class_relacl			22
 
 /* ----------------
  *		initial contents of pg_class
  * ----------------
  */
 
-DATA(insert OID = 1247 (  pg_type 71		  PGUID 0 0 0 0 0 f f r 17 0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1247 (  pg_type 71		  PGUID 0 1247 0 0 0 0 f f r 17 0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1249 (  pg_attribute 75	  PGUID 0 0 0 0 0 f f r 15 0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1249 (  pg_attribute 75	  PGUID 0 1249 0 0 0 0 f f r 15 0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1255 (  pg_proc 81		  PGUID 0 0 0 0 0 f f r 17 0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1255 (  pg_proc 81		  PGUID 0 1255 0 0 0 0 f f r 17 0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1259 (  pg_class 83		  PGUID 0 0 0 0 0 f f r 21 0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1259 (  pg_class 83		  PGUID 0 1259 0 0 0 0 f f r 22 0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1260 (  pg_shadow 86		  PGUID 0 0 0 0 0 f t r 8  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1260 (  pg_shadow 86		  PGUID 0 1260 0 0 0 0 f t r 8  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1261 (  pg_group 87		  PGUID 0 0 0 0 0 f t r 3  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1261 (  pg_group 87		  PGUID 0 1261 0 0 0 0 f t r 3  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1262 (  pg_database 88	  PGUID 0 0 0 0 0 f t r 4  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1262 (  pg_database 88	  PGUID 0 1262 0 0 0 0 f t r 4  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1264 (  pg_variable 90	  PGUID 0 0 0 0 0 f t s 1  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1264 (  pg_variable 90	  PGUID 0 1264 0 0 0 0 f t s 1  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1269 (  pg_log  99		  PGUID 0 0 0 0 0 f t s 1  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1269 (  pg_log  99		  PGUID 0 1269 0 0 0 0 f t s 1  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 376  (  pg_xactlock  0	  PGUID 0 0 0 0 0 f t s 1  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 376  (  pg_xactlock  0	  PGUID 0    0 0 0 0 0 f t s 1  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1215 (  pg_attrdef 109	  PGUID 0 0 0 0 0 t t r 4  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1215 (  pg_attrdef 109	  PGUID 0 1215 0 0 0 0 t t r 4  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1216 (  pg_relcheck 110	  PGUID 0 0 0 0 0 t t r 4  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1216 (  pg_relcheck 110	  PGUID 0 1216 0 0 0 0 t t r 4  0 0 0 0 0 f f f _null_ ));
 DESCR("");
-DATA(insert OID = 1219 (  pg_trigger 111	  PGUID 0 0 0 0 0 t t r 13  0 0 0 0 0 f f f _null_ ));
+DATA(insert OID = 1219 (  pg_trigger 111	  PGUID 0 1219 0 0 0 0 t t r 13  0 0 0 0 0 f f f _null_ ));
 DESCR("");
 
 #define RelOid_pg_type			1247
diff --git a/src/include/catalog/pg_database.h b/src/include/catalog/pg_database.h
index 8c96bd2a070d52711afbe6938daa4cc122249388..99d4217d3e01d4a5306520b0a8e0e4a13e53b3d4 100644
--- a/src/include/catalog/pg_database.h
+++ b/src/include/catalog/pg_database.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_database.h,v 1.9 2000/01/26 05:57:57 momjian Exp $
+ * $Id: pg_database.h,v 1.10 2000/10/16 14:52:26 vadim Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -55,4 +55,10 @@ typedef FormData_pg_database *Form_pg_database;
 #define Anum_pg_database_datdba			2
 #define Anum_pg_database_encoding		3
 #define Anum_pg_database_datpath		4
+
+DATA(insert OID = 1 (  template1 PGUID ENCODING template1 ));
+DESCR("");
+
+#define TemplateDbOid			1
+
 #endif	 /* PG_DATABASE_H */
diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h
index 2347db17bd04bfaee0f08db7ca2c6590040886b2..4f4a516afdfe9aca17b8d9853847cf65a576202b 100644
--- a/src/include/storage/buf_internals.h
+++ b/src/include/storage/buf_internals.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: buf_internals.h,v 1.37 2000/04/12 17:16:51 momjian Exp $
+ * $Id: buf_internals.h,v 1.38 2000/10/16 14:52:28 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -61,6 +61,7 @@ typedef struct buftag
 	(a)->relId = (xx_reln)->rd_lockInfo.lockRelId \
 )
 
+#ifdef OLD_FILE_NAMING
 /* If we have to write a buffer "blind" (without a relcache entry),
  * the BufferTag is not enough information.  BufferBlindId carries the
  * additional information needed.
@@ -71,6 +72,17 @@ typedef struct bufblindid
 	char		relname[NAMEDATALEN];	/* name of reln */
 }			BufferBlindId;
 
+#else
+
+typedef struct bufblindid
+{
+	char		dbname[NAMEDATALEN];	/* name of db in which buf belongs */
+	char		relname[NAMEDATALEN];	/* name of reln */
+	RelFileNode	rnode;
+} BufferBlindId;
+
+#endif
+
 #define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers)
 #define INVALID_DESCRIPTOR (-3)
 
diff --git a/src/include/storage/relfilenode.h b/src/include/storage/relfilenode.h
index 405dee967c27f5a95c4cbaabe51a9feba6dbfd7c..de4d1e1beea1ee13b97ec3ba4537cacc0a450159 100644
--- a/src/include/storage/relfilenode.h
+++ b/src/include/storage/relfilenode.h
@@ -2,13 +2,17 @@
 #define RELFILENODE_H
 
 /*
- * This is temporal place holder for Relation File Node till
- * reloid.version/unique_id file naming is not implemented
+ * This is all what we need to know to find relation file.
+ * tblNode is identificator of tablespace and because of
+ * currently our tablespaces are equal to databases this is
+ * database OID. relNode is currently relation OID on creation
+ * but may be changed later if required. relNode is stored in
+ * pg_class.relfilenode.
  */
 typedef struct RelFileNode
 {
-	Oid					dbId;		/* database */
-	Oid					relId;		/* relation */
+	Oid					tblNode;		/* tablespace */
+	Oid					relNode;		/* relation */
 } RelFileNode;
 
 #endif	/* RELFILENODE_H */
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index e9f8824f55c0ffb047536c65e2f208a4f31d7557..7caac813e9acb7bafb999dc0e3075bfe59b86dba 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -7,13 +7,14 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: smgr.h,v 1.21 2000/06/05 07:29:06 tgl Exp $
+ * $Id: smgr.h,v 1.22 2000/10/16 14:52:28 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef SMGR_H
 #define SMGR_H
 
+#include "storage/relfilenode.h"
 #include "storage/block.h"
 #include "storage/spin.h"
 #include "utils/rel.h"
@@ -35,14 +36,21 @@ extern int smgrwrite(int16 which, Relation reln, BlockNumber blocknum,
 		  char *buffer);
 extern int smgrflush(int16 which, Relation reln, BlockNumber blocknum,
 		  char *buffer);
+#ifdef OLD_FILE_NAMING
 extern int smgrblindwrt(int16 which, char *dbname, char *relname,
 			 Oid dbid, Oid relid,
 			 BlockNumber blkno, char *buffer,
 			 bool dofsync);
-extern int	smgrmarkdirty(int16 which, Relation reln, BlockNumber blkno);
 extern int smgrblindmarkdirty(int16 which, char *dbname, char *relname,
 				   Oid dbid, Oid relid,
 				   BlockNumber blkno);
+#else
+extern int smgrblindwrt(int16 which, RelFileNode rnode,
+						BlockNumber blkno, char *buffer, bool dofsync);
+extern int smgrblindmarkdirty(int16 which, RelFileNode rnode,
+						BlockNumber blkno);
+#endif
+extern int	smgrmarkdirty(int16 which, Relation reln, BlockNumber blkno);
 extern int	smgrnblocks(int16 which, Relation reln);
 extern int	smgrtruncate(int16 which, Relation reln, int nblocks);
 extern int	smgrcommit(void);
@@ -62,12 +70,18 @@ extern int	mdclose(Relation reln);
 extern int	mdread(Relation reln, BlockNumber blocknum, char *buffer);
 extern int	mdwrite(Relation reln, BlockNumber blocknum, char *buffer);
 extern int	mdflush(Relation reln, BlockNumber blocknum, char *buffer);
+extern int	mdmarkdirty(Relation reln, BlockNumber blkno);
+#ifdef OLD_FILE_NAMING
 extern int mdblindwrt(char *dbname, char *relname, Oid dbid, Oid relid,
 		   BlockNumber blkno, char *buffer,
 		   bool dofsync);
-extern int	mdmarkdirty(Relation reln, BlockNumber blkno);
 extern int mdblindmarkdirty(char *dbname, char *relname, Oid dbid, Oid relid,
 				 BlockNumber blkno);
+#else
+extern int mdblindwrt(RelFileNode rnode, BlockNumber blkno,
+						char *buffer, bool dofsync);
+extern int mdblindmarkdirty(RelFileNode rnode, BlockNumber blkno);
+#endif
 extern int	mdnblocks(Relation reln);
 extern int	mdtruncate(Relation reln, int nblocks);
 extern int	mdcommit(void);