Add new datlastsysoid to pg_database.
authorPhilip Warner <pjw@rhyme.com.au>
Sun, 22 Oct 2000 17:55:49 +0000 (17:55 +0000)
committerPhilip Warner <pjw@rhyme.com.au>
Sun, 22 Oct 2000 17:55:49 +0000 (17:55 +0000)
This field stores the last allocated OID after the database was created.
Used by pg_dump in deciding what is user-defined vs. system-defined.

src/backend/commands/dbcommands.c
src/bin/initdb/initdb.sh
src/include/catalog/catversion.h
src/include/catalog/pg_attribute.h
src/include/catalog/pg_class.h
src/include/catalog/pg_database.h

index f12ce4e56c73417d54500f60174613c9b21a5c7a..d68033d897526b643cb3207e655523c482a8f74a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.61 2000/10/16 14:52:03 vadim Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.62 2000/10/22 17:55:36 pjw Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -44,7 +44,6 @@ static bool
            get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP);
 
 
-
 /*
  * CREATE DATABASE
  */
@@ -62,7 +61,8 @@ createdb(const char *dbname, const char *dbpath, int encoding)
    HeapTuple   tuple;
    TupleDesc   pg_database_dsc;
    Datum       new_record[Natts_pg_database];
-   char        new_record_nulls[Natts_pg_database] = {' ', ' ', ' ', ' '};
+   char        new_record_nulls[Natts_pg_database] = {' ', ' ', ' ', ' ', ' '};
+   Oid         dboid;
 
    if (!get_user_info(GetUserId(), &use_super, &use_createdb))
        elog(ERROR, "current user name is invalid");
@@ -91,6 +91,8 @@ 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);
+#else
+   locbuf[0] = 0; /* Avoid junk in strings */
 #endif
 
    /*
@@ -99,16 +101,26 @@ createdb(const char *dbname, const char *dbpath, int encoding)
    pg_database_rel = heap_openr(DatabaseRelationName, AccessExclusiveLock);
    pg_database_dsc = RelationGetDescr(pg_database_rel);
 
+   /* 
+    * Preassign OID for pg_database tuple, so that we know current
+    * OID counter value
+    */
+   dboid = newoid();
+
    /* Form tuple */
    new_record[Anum_pg_database_datname - 1] = DirectFunctionCall1(namein,
                                                    CStringGetDatum(dbname));
    new_record[Anum_pg_database_datdba - 1] = Int32GetDatum(GetUserId());
    new_record[Anum_pg_database_encoding - 1] = Int32GetDatum(encoding);
+   new_record[Anum_pg_database_datlastsysoid - 1] = ObjectIdGetDatum(dboid); /* Save current OID val */
    new_record[Anum_pg_database_datpath - 1] = DirectFunctionCall1(textin,
                                                    CStringGetDatum(locbuf));
 
    tuple = heap_formtuple(pg_database_dsc, new_record, new_record_nulls);
 
+   tuple->t_data->t_oid = dboid;   /* override heap_insert */
+
+
    /*
     * Update table
     */
@@ -180,6 +192,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
        else
            elog(ERROR, "CREATE DATABASE: Could not initialize database directory. Delete failed as well");
    }
+
 }
 
 
@@ -391,8 +404,6 @@ get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP)
    return HeapTupleIsValid(tuple);
 }
 
-
-
 static bool
 get_user_info(Oid use_sysid, bool *use_super, bool *use_createdb)
 {
index 86d8d0289ea0036137e81a4c5cb963416da0e18e..fc5e8f042375ac6590b507ab8708592a651005c5 100644 (file)
@@ -23,7 +23,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.105 2000/10/16 14:52:21 vadim Exp $
+# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.106 2000/10/22 17:55:45 pjw Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -597,6 +597,11 @@ cat $TEMPFILE \
    | "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
 rm -f "$TEMPFILE" || exit_nicely
 
+echo "Setting lastsysoid."
+echo "Update pg_database Set datlastsysoid = (Select max(oid) From pg_description) \
+        Where datname = 'template1'" \
+       | "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
+
 echo "Vacuuming database."
 echo "VACUUM ANALYZE" \
    | "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
index 15574e122bf3a7669875a9e9b4f69ee13720b7d4..c16c6ae83ecc6c3f3082543e386d4816d5508a08 100644 (file)
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catversion.h,v 1.50 2000/10/13 00:33:47 pjw Exp $
+ * $Id: catversion.h,v 1.51 2000/10/22 17:55:49 pjw Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 200010131
+#define CATALOG_VERSION_NO 200010231
 
 #endif
index 4b1d8dc34392893a1dd7cc4c9659c63d8144a7cc..de3ccdf5d83cabbfc48a3b1e421f921cb08b538a 100644 (file)
@@ -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.65 2000/10/16 14:52:26 vadim Exp $
+ * $Id: pg_attribute.h,v 1.66 2000/10/22 17:55:49 pjw Exp $
  *
  * NOTES
  *   the genbki.sh script reads this file and generates .bki
@@ -281,7 +281,8 @@ DATA(insert OID = 0 ( 1247 tableoid         26 0  4  -7 0 -1 -1 t p f i f f));
 DATA(insert OID = 0 ( 1262 datname         19 0 NAMEDATALEN   1 0 -1 -1 f p f i f f));
 DATA(insert OID = 0 ( 1262 datdba          23 0  4   2 0 -1 -1 t p f i f f));
 DATA(insert OID = 0 ( 1262 encoding            23 0  4   3 0 -1 -1 t p f i f f));
-DATA(insert OID = 0 ( 1262 datpath         25 0 -1   4 0 -1 -1 f x f i f f));
+DATA(insert OID = 0 ( 1262 datlastsysoid    26 0  4   4 0 -1 -1 t p f i f f));
+DATA(insert OID = 0 ( 1262 datpath         25 0 -1   5 0 -1 -1 f x f i f f));
 DATA(insert OID = 0 ( 1262 ctid                27 0  6  -1 0 -1 -1 f p f i f f));
 DATA(insert OID = 0 ( 1262 oid             26 0  4  -2 0 -1 -1 t p f i f f));
 DATA(insert OID = 0 ( 1262 xmin                28 0  4  -3 0 -1 -1 t p f i f f));
index 6bf2d129e5d2e7e7ca7c48e61451568de6dcc606..a9592e7ddb852ebc35ac2fe39640d1c26201f2ce 100644 (file)
@@ -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.42 2000/10/16 16:19:14 momjian Exp $
+ * $Id: pg_class.h,v 1.43 2000/10/22 17:55:49 pjw Exp $
  *
  * NOTES
  *   the genbki.sh script reads this file and generates .bki
@@ -142,7 +142,7 @@ DATA(insert OID = 1260 (  pg_shadow 86        PGUID 0 1260 0 0 0 0 f t r 8  0 0 0 0
 DESCR("");
 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 1262 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 5  0 0 0 0 0 f f f _null_ ));
 DESCR("");
 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("");
index 27acca85f448cae3a3940a4576c6598df890a42d..ca89738bbfe6b1fe03bc8856367db461b3471972 100644 (file)
@@ -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.11 2000/10/20 11:01:17 vadim Exp $
+ * $Id: pg_database.h,v 1.12 2000/10/22 17:55:49 pjw Exp $
  *
  * NOTES
  *   the genbki.sh script reads this file and generates .bki
@@ -36,6 +36,7 @@ CATALOG(pg_database) BOOTSTRAP
    NameData    datname;
    int4        datdba;
    int4        encoding;
+   int4        datlastsysoid;
    text        datpath;        /* VARIABLE LENGTH FIELD */
 } FormData_pg_database;
 
@@ -50,13 +51,14 @@ typedef FormData_pg_database *Form_pg_database;
  *     compiler constants for pg_database
  * ----------------
  */
-#define Natts_pg_database              4
+#define Natts_pg_database          5   
 #define Anum_pg_database_datname       1
 #define Anum_pg_database_datdba            2
 #define Anum_pg_database_encoding      3
-#define Anum_pg_database_datpath       4
+#define Anum_pg_database_datlastsysoid  4
+#define Anum_pg_database_datpath       5
 
-DATA(insert OID = 1 (  template1 PGUID ENCODING template1 ));
+DATA(insert OID = 1 (  template1 PGUID ENCODING template1 ));
 DESCR("");
 
 #define TemplateDbOid          1