Skip to content

Commit 4ac1742

Browse files
committed
Add new datlastsysoid to pg_database.
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.
1 parent 7e02371 commit 4ac1742

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

src/backend/commands/dbcommands.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.61 2000/10/16 14:52:03 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.62 2000/10/22 17:55:36 pjw Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -44,7 +44,6 @@ static bool
4444
get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP);
4545

4646

47-
4847
/*
4948
* CREATE DATABASE
5049
*/
@@ -62,7 +61,8 @@ createdb(const char *dbname, const char *dbpath, int encoding)
6261
HeapTuple tuple;
6362
TupleDesc pg_database_dsc;
6463
Datum new_record[Natts_pg_database];
65-
char new_record_nulls[Natts_pg_database] = {' ', ' ', ' ', ' '};
64+
char new_record_nulls[Natts_pg_database] = {' ', ' ', ' ', ' ', ' '};
65+
Oid dboid;
6666

6767
if (!get_user_info(GetUserId(), &use_super, &use_createdb))
6868
elog(ERROR, "current user name is invalid");
@@ -91,6 +91,8 @@ createdb(const char *dbname, const char *dbpath, int encoding)
9191
"The database path '%s' is invalid. "
9292
"This may be due to a character that is not allowed or because the chosen "
9393
"path isn't permitted for databases", dbpath);
94+
#else
95+
locbuf[0] = 0; /* Avoid junk in strings */
9496
#endif
9597

9698
/*
@@ -99,16 +101,26 @@ createdb(const char *dbname, const char *dbpath, int encoding)
99101
pg_database_rel = heap_openr(DatabaseRelationName, AccessExclusiveLock);
100102
pg_database_dsc = RelationGetDescr(pg_database_rel);
101103

104+
/*
105+
* Preassign OID for pg_database tuple, so that we know current
106+
* OID counter value
107+
*/
108+
dboid = newoid();
109+
102110
/* Form tuple */
103111
new_record[Anum_pg_database_datname - 1] = DirectFunctionCall1(namein,
104112
CStringGetDatum(dbname));
105113
new_record[Anum_pg_database_datdba - 1] = Int32GetDatum(GetUserId());
106114
new_record[Anum_pg_database_encoding - 1] = Int32GetDatum(encoding);
115+
new_record[Anum_pg_database_datlastsysoid - 1] = ObjectIdGetDatum(dboid); /* Save current OID val */
107116
new_record[Anum_pg_database_datpath - 1] = DirectFunctionCall1(textin,
108117
CStringGetDatum(locbuf));
109118

110119
tuple = heap_formtuple(pg_database_dsc, new_record, new_record_nulls);
111120

121+
tuple->t_data->t_oid = dboid; /* override heap_insert */
122+
123+
112124
/*
113125
* Update table
114126
*/
@@ -180,6 +192,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
180192
else
181193
elog(ERROR, "CREATE DATABASE: Could not initialize database directory. Delete failed as well");
182194
}
195+
183196
}
184197

185198

@@ -391,8 +404,6 @@ get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP)
391404
return HeapTupleIsValid(tuple);
392405
}
393406

394-
395-
396407
static bool
397408
get_user_info(Oid use_sysid, bool *use_super, bool *use_createdb)
398409
{

src/bin/initdb/initdb.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424
# Copyright (c) 1994, Regents of the University of California
2525
#
26-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.105 2000/10/16 14:52:21 vadim Exp $
26+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.106 2000/10/22 17:55:45 pjw Exp $
2727
#
2828
#-------------------------------------------------------------------------
2929

@@ -597,6 +597,11 @@ cat $TEMPFILE \
597597
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
598598
rm -f "$TEMPFILE" || exit_nicely
599599

600+
echo "Setting lastsysoid."
601+
echo "Update pg_database Set datlastsysoid = (Select max(oid) From pg_description) \
602+
Where datname = 'template1'" \
603+
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
604+
600605
echo "Vacuuming database."
601606
echo "VACUUM ANALYZE" \
602607
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.50 2000/10/13 00:33:47 pjw Exp $
40+
* $Id: catversion.h,v 1.51 2000/10/22 17:55:49 pjw Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200010131
56+
#define CATALOG_VERSION_NO 200010231
5757

5858
#endif

src/include/catalog/pg_attribute.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_attribute.h,v 1.65 2000/10/16 14:52:26 vadim Exp $
11+
* $Id: pg_attribute.h,v 1.66 2000/10/22 17:55:49 pjw Exp $
1212
*
1313
* NOTES
1414
* 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));
281281
DATA(insert OID = 0 ( 1262 datname 19 0 NAMEDATALEN 1 0 -1 -1 f p f i f f));
282282
DATA(insert OID = 0 ( 1262 datdba 23 0 4 2 0 -1 -1 t p f i f f));
283283
DATA(insert OID = 0 ( 1262 encoding 23 0 4 3 0 -1 -1 t p f i f f));
284-
DATA(insert OID = 0 ( 1262 datpath 25 0 -1 4 0 -1 -1 f x f i f f));
284+
DATA(insert OID = 0 ( 1262 datlastsysoid 26 0 4 4 0 -1 -1 t p f i f f));
285+
DATA(insert OID = 0 ( 1262 datpath 25 0 -1 5 0 -1 -1 f x f i f f));
285286
DATA(insert OID = 0 ( 1262 ctid 27 0 6 -1 0 -1 -1 f p f i f f));
286287
DATA(insert OID = 0 ( 1262 oid 26 0 4 -2 0 -1 -1 t p f i f f));
287288
DATA(insert OID = 0 ( 1262 xmin 28 0 4 -3 0 -1 -1 t p f i f f));

src/include/catalog/pg_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_class.h,v 1.42 2000/10/16 16:19:14 momjian Exp $
11+
* $Id: pg_class.h,v 1.43 2000/10/22 17:55:49 pjw Exp $
1212
*
1313
* NOTES
1414
* 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
142142
DESCR("");
143143
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_ ));
144144
DESCR("");
145-
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_ ));
145+
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_ ));
146146
DESCR("");
147147
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_ ));
148148
DESCR("");

src/include/catalog/pg_database.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_database.h,v 1.11 2000/10/20 11:01:17 vadim Exp $
11+
* $Id: pg_database.h,v 1.12 2000/10/22 17:55:49 pjw Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -36,6 +36,7 @@ CATALOG(pg_database) BOOTSTRAP
3636
NameData datname;
3737
int4 datdba;
3838
int4 encoding;
39+
int4 datlastsysoid;
3940
text datpath; /* VARIABLE LENGTH FIELD */
4041
} FormData_pg_database;
4142

@@ -50,13 +51,14 @@ typedef FormData_pg_database *Form_pg_database;
5051
* compiler constants for pg_database
5152
* ----------------
5253
*/
53-
#define Natts_pg_database 4
54+
#define Natts_pg_database 5
5455
#define Anum_pg_database_datname 1
5556
#define Anum_pg_database_datdba 2
5657
#define Anum_pg_database_encoding 3
57-
#define Anum_pg_database_datpath 4
58+
#define Anum_pg_database_datlastsysoid 4
59+
#define Anum_pg_database_datpath 5
5860

59-
DATA(insert OID = 1 ( template1 PGUID ENCODING template1 ));
61+
DATA(insert OID = 1 ( template1 PGUID ENCODING 0 template1 ));
6062
DESCR("");
6163

6264
#define TemplateDbOid 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy