1 /*-------------------------------------------------------------------------
4 * routines to support running postgres in 'bootstrap' mode
5 * bootstrap mode is used to create the initial template database
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.99 2000/11/21 09:39:57 vadim Exp $
13 *-------------------------------------------------------------------------
22 #define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
28 #include "access/genam.h"
29 #include "access/heapam.h"
30 #include "bootstrap/bootstrap.h"
31 #include "catalog/catname.h"
32 #include "catalog/index.h"
33 #include "catalog/pg_type.h"
34 #include "libpq/pqsignal.h"
35 #include "miscadmin.h"
36 #include "tcop/tcopprot.h"
37 #include "utils/builtins.h"
38 #include "utils/exc.h"
39 #include "utils/fmgroids.h"
40 #include "utils/guc.h"
41 #include "utils/lsyscache.h"
44 #define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
46 extern void StartupXLOG(void);
47 extern void ShutdownXLOG(void);
48 extern void BootStrapXLOG(void);
50 extern char XLogDir[];
51 extern char ControlFilePath[];
53 extern int Int_yyparse(void);
54 static hashnode *AddStr(char *str, int strlength, int mderef);
55 static Form_pg_attribute AllocateAttribute(void);
56 static bool BootstrapAlreadySeen(Oid id);
57 static int CompHash(char *str, int len);
58 static hashnode *FindStr(char *str, int length, hashnode *mderef);
59 static Oid gettype(char *type);
60 static void cleanup(void);
67 * In the lexical analyzer, we need to get the reference number quickly from
68 * the string, and the string from the reference number. Thus we have
69 * as our data structure a hash table, where the hashing key taken from
70 * the particular string. The hash table is chained. One of the fields
71 * of the hash table node is an index into the array of character pointers.
72 * The unique index number that every string is assigned is simply the
73 * position of its string pointer in the array of string pointers.
76 #define STRTABLESIZE 10000
77 #define HASHTABLESIZE 503
79 /* Hash function numbers */
84 char *strtable[STRTABLESIZE];
85 hashnode *hashtable[HASHTABLESIZE];
87 static int strtable_end = -1; /* Tells us last occupied string space */
90 * Basic information associated with each type. This is used before
93 * XXX several of these input/output functions do catalog scans
94 * (e.g., F_REGPROCIN scans pg_proc). this obviously creates some
95 * order dependencies in the catalog creation process.
99 char name[NAMEDATALEN];
107 static struct typinfo Procid[] = {
108 {"bool", BOOLOID, 0, 1, F_BOOLIN, F_BOOLOUT},
109 {"bytea", BYTEAOID, 0, -1, F_BYTEAIN, F_BYTEAOUT},
110 {"char", CHAROID, 0, 1, F_CHARIN, F_CHAROUT},
111 {"name", NAMEOID, 0, NAMEDATALEN, F_NAMEIN, F_NAMEOUT},
112 {"int2", INT2OID, 0, 2, F_INT2IN, F_INT2OUT},
113 {"int2vector", INT2VECTOROID, 0, INDEX_MAX_KEYS * 2, F_INT2VECTORIN, F_INT2VECTOROUT},
114 {"int4", INT4OID, 0, 4, F_INT4IN, F_INT4OUT},
115 {"regproc", REGPROCOID, 0, 4, F_REGPROCIN, F_REGPROCOUT},
116 {"text", TEXTOID, 0, -1, F_TEXTIN, F_TEXTOUT},
117 {"oid", OIDOID, 0, 4, F_OIDIN, F_OIDOUT},
118 {"tid", TIDOID, 0, 6, F_TIDIN, F_TIDOUT},
119 {"xid", XIDOID, 0, 4, F_XIDIN, F_XIDOUT},
120 {"cid", CIDOID, 0, 4, F_CIDIN, F_CIDOUT},
121 {"oidvector", 30, 0, INDEX_MAX_KEYS * 4, F_OIDVECTORIN, F_OIDVECTOROUT},
122 {"smgr", 210, 0, 2, F_SMGRIN, F_SMGROUT},
123 {"_int4", 1007, INT4OID, -1, F_ARRAY_IN, F_ARRAY_OUT},
124 {"_aclitem", 1034, 1033, -1, F_ARRAY_IN, F_ARRAY_OUT}
127 static int n_types = sizeof(Procid) / sizeof(struct typinfo);
132 FormData_pg_type am_typ;
135 static struct typmap **Typ = (struct typmap **) NULL;
136 static struct typmap *Ap = (struct typmap *) NULL;
138 static int Warnings = 0;
139 static char Blanks[MAXATTR];
141 static char *relname; /* current relation name */
143 Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */
144 static Datum values[MAXATTR]; /* corresponding attribute values */
145 int numattr; /* number of attributes for cur. rel */
149 static MemoryContext nogc = NULL; /* special no-gc mem context */
155 * At bootstrap time, we first declare all the indices to be built, and
156 * then build them. The IndexList structure stores enough information
157 * to allow us to build the indices after they've been declared.
160 typedef struct _IndexList
165 struct _IndexList *il_next;
168 static IndexList *ILHead = (IndexList *) NULL;
171 /* ----------------------------------------------------------------
173 * ----------------------------------------------------------------
177 * error handling / abort routines
188 usage help for the bootstrap backen
193 fprintf(stderr, "Usage: postgres -boot [-d] [-C] [-F] [-O] [-Q] ");
194 fprintf(stderr, "[-P portno] [dbName]\n");
195 fprintf(stderr, " d: debug mode\n");
196 fprintf(stderr, " C: disable version checking\n");
197 fprintf(stderr, " F: turn off fsync\n");
198 fprintf(stderr, " O: set BootstrapProcessing mode\n");
199 fprintf(stderr, " P portno: specify port number\n");
207 BootstrapMain(int argc, char *argv[])
208 /* ----------------------------------------------------------------
209 * The main loop for handling the backend in bootstrap mode
210 * the bootstrap mode is used to initialize the template database
211 * the bootstrap backend doesn't speak SQL, but instead expects
212 * commands in a special bootstrap language.
214 * The arguments passed in to BootstrapMain are the run-time arguments
215 * without the argument '-boot', the caller is required to have
216 * removed -boot from the run-time args
217 * ----------------------------------------------------------------
223 int xlogop = BS_XLOG_NOP;
224 char *potential_DataDir = NULL;
230 /* --------------------
232 * -------------------
235 MyProcPid = getpid();
238 * Fire up essential subsystems: error and memory management
240 * If we are running under the postmaster, this is done already.
242 if (!IsUnderPostmaster)
244 EnableExceptionHandling(true);
249 * process command arguments
253 /* Set defaults, to be overriden by explicit options below */
257 if (!IsUnderPostmaster)
260 potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
263 while ((flag = getopt(argc, argv, "D:dCQx:pB:F")) != EOF)
268 potential_DataDir = optarg;
271 DebugMode = true; /* print out debugging info while
284 xlogop = atoi(optarg);
287 /* indicates fork from postmaster */
290 NBuffers = atoi(optarg);
298 if (argc - optind > 1)
300 else if (argc - optind == 1)
301 dbName = argv[optind];
303 SetProcessingMode(BootstrapProcessing);
304 IgnoreSystemIndexes(true);
306 if (!IsUnderPostmaster)
308 if (!potential_DataDir)
310 fprintf(stderr, "%s does not know where to find the database system "
311 "data. You must specify the directory that contains the "
312 "database system either by specifying the -D invocation "
313 "option or by setting the PGDATA environment variable.\n\n",
317 SetDataDir(potential_DataDir);
323 dbName = getenv("USER");
326 fputs("bootstrap backend: failed, no db name specified\n", stderr);
327 fputs(" and no USER enviroment variable\n", stderr);
334 if (!IsUnderPostmaster)
336 pqsignal(SIGINT, (pqsigfunc) die);
337 pqsignal(SIGHUP, (pqsigfunc) die);
338 pqsignal(SIGTERM, (pqsigfunc) die);
344 snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
345 snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
346 SetProcessingMode(NormalProcessing);
347 if (xlogop == BS_XLOG_NOP)
349 else if (xlogop == BS_XLOG_BOOTSTRAP)
356 if (xlogop == BS_XLOG_CHECKPOINT)
358 extern void CreateDummyCaches(void);
360 CreateCheckPoint(false);
362 else if (xlogop == BS_XLOG_STARTUP)
364 else if (xlogop == BS_XLOG_SHUTDOWN)
367 elog(STOP, "Unsupported XLOG op %d", xlogop);
370 SetProcessingMode(BootstrapProcessing);
373 * backend initialization
375 InitPostgres(dbName, NULL);
378 for (i = 0; i < MAXATTR; i++)
380 attrtypes[i] = (Form_pg_attribute) NULL;
383 for (i = 0; i < STRTABLESIZE; ++i)
385 for (i = 0; i < HASHTABLESIZE; ++i)
389 * abort processing resumes here
392 pqsignal(SIGHUP, handle_warn);
394 if (sigsetjmp(Warn_restart, 1) != 0)
397 AbortCurrentTransaction();
406 * the sed script boot.sed renamed yyparse to Int_yyparse for the
407 * bootstrap parser to avoid conflicts with the normal SQL parser
411 SetProcessingMode(NormalProcessing);
412 CreateCheckPoint(true);
413 SetProcessingMode(BootstrapProcessing);
415 /* clean up processing */
416 StartTransactionCommand();
419 /* not reached, here to make compiler happy */
424 /* ----------------------------------------------------------------
425 * MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
426 * ----------------------------------------------------------------
434 boot_openrel(char *relname)
442 if (strlen(relname) >= NAMEDATALEN - 1)
443 relname[NAMEDATALEN - 1] = '\0';
445 if (Typ == (struct typmap **) NULL)
447 rel = heap_openr(TypeRelationName, NoLock);
448 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
450 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
453 app = Typ = ALLOC(struct typmap *, i + 1);
455 *app++ = ALLOC(struct typmap, 1);
456 *app = (struct typmap *) NULL;
457 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
459 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
461 (*app)->am_oid = tup->t_data->t_oid;
462 memcpy((char *) &(*app)->am_typ,
463 (char *) GETSTRUCT(tup),
464 sizeof((*app)->am_typ));
468 heap_close(rel, NoLock);
475 printf("Amopen: relation %s. attrsize %d\n", relname ? relname : "(null)",
476 (int) ATTRIBUTE_TUPLE_SIZE);
478 reldesc = heap_openr(relname, NoLock);
479 numattr = reldesc->rd_rel->relnatts;
480 for (i = 0; i < numattr; i++)
482 if (attrtypes[i] == NULL)
483 attrtypes[i] = AllocateAttribute();
484 memmove((char *) attrtypes[i],
485 (char *) reldesc->rd_att->attrs[i],
486 ATTRIBUTE_TUPLE_SIZE);
488 /* Some old pg_attribute tuples might not have attisset. */
491 * If the attname is attisset, don't look for it - it may not be
494 if (namestrcmp(&attrtypes[i]->attname, "attisset") == 0)
495 attrtypes[i]->attisset = get_attisset(RelationGetRelid(reldesc),
496 NameStr(attrtypes[i]->attname));
498 attrtypes[i]->attisset = false;
502 Form_pg_attribute at = attrtypes[i];
504 printf("create attribute %d name %s len %d num %d type %d\n",
505 i, NameStr(at->attname), at->attlen, at->attnum,
524 if (strcmp(RelationGetRelationName(reldesc), name) != 0)
525 elog(ERROR, "closerel: close of '%s' when '%s' was expected",
526 name, relname ? relname : "(null)");
529 elog(ERROR, "closerel: close of '%s' before any relation was opened",
535 elog(ERROR, "Warning: no opened relation to close.\n");
539 printf("Amclose: relation %s.\n", relname ? relname : "(null)");
540 heap_close(reldesc, NoLock);
541 reldesc = (Relation) NULL;
550 * define a <field,type> pair
551 * if there are n fields in a relation to be created, this routine
552 * will be called n times
556 DefineAttr(char *name, char *type, int attnum)
563 fputs("Warning: no open relations allowed with 't' command.\n", stderr);
567 typeoid = gettype(type);
568 if (attrtypes[attnum] == (Form_pg_attribute) NULL)
569 attrtypes[attnum] = AllocateAttribute();
570 if (Typ != (struct typmap **) NULL)
572 attrtypes[attnum]->atttypid = Ap->am_oid;
573 namestrcpy(&attrtypes[attnum]->attname, name);
575 printf("<%s %s> ", NameStr(attrtypes[attnum]->attname), type);
576 attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
577 attlen = attrtypes[attnum]->attlen = Ap->am_typ.typlen;
578 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
579 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;;
580 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
584 attrtypes[attnum]->atttypid = Procid[typeoid].oid;
585 namestrcpy(&attrtypes[attnum]->attname, name);
587 printf("<%s %s> ", NameStr(attrtypes[attnum]->attname), type);
588 attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
589 attlen = attrtypes[attnum]->attlen = Procid[typeoid].len;
590 attrtypes[attnum]->attstorage = 'p';
593 * Cheat like mad to fill in these items from the length only.
594 * This only has to work for types used in the system catalogs...
599 attrtypes[attnum]->attbyval = true;
600 attrtypes[attnum]->attalign = 'c';
603 attrtypes[attnum]->attbyval = true;
604 attrtypes[attnum]->attalign = 's';
607 attrtypes[attnum]->attbyval = true;
608 attrtypes[attnum]->attalign = 'i';
611 attrtypes[attnum]->attbyval = false;
612 attrtypes[attnum]->attalign = 'i';
616 attrtypes[attnum]->attcacheoff = -1;
617 attrtypes[attnum]->atttypmod = -1;
623 * assumes that 'oid' will not be zero.
627 InsertOneTuple(Oid objectid)
636 printf("InsertOneTuple oid %u, %d attrs\n", objectid, numattr);
640 tupDesc = CreateTupleDesc(numattr, attrtypes);
641 tuple = heap_formtuple(tupDesc, values, Blanks);
642 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
644 if (objectid != (Oid) 0)
645 tuple->t_data->t_oid = objectid;
646 heap_insert(reldesc, tuple);
647 heap_freetuple(tuple);
650 printf("End InsertOneTuple, objectid=%u\n", objectid);
655 * Reset blanks for next tuple
657 for (i = 0; i < numattr; i++)
666 InsertOneValue(Oid objectid, char *value, int i)
673 printf("Inserting value: '%s'\n", value);
674 if (i < 0 || i >= MAXATTR)
676 printf("i out of range: %d\n", i);
680 if (Typ != (struct typmap **) NULL)
687 while (*app && (*app)->am_oid != reldesc->rd_att->attrs[i]->atttypid)
692 printf("Unable to find atttypid in Typ list! %u\n",
693 reldesc->rd_att->attrs[i]->atttypid
697 values[i] = OidFunctionCall3(ap->am_typ.typinput,
698 CStringGetDatum(value),
699 ObjectIdGetDatum(ap->am_typ.typelem),
701 prt = DatumGetCString(OidFunctionCall3(ap->am_typ.typoutput,
703 ObjectIdGetDatum(ap->am_typ.typelem),
711 for (typeindex = 0; typeindex < n_types; typeindex++)
713 if (Procid[typeindex].oid == attrtypes[i]->atttypid)
716 if (typeindex >= n_types)
717 elog(ERROR, "can't find type OID %u", attrtypes[i]->atttypid);
719 printf("Typ == NULL, typeindex = %u idx = %d\n", typeindex, i);
720 values[i] = OidFunctionCall3(Procid[typeindex].inproc,
721 CStringGetDatum(value),
722 ObjectIdGetDatum(Procid[typeindex].elem),
724 prt = DatumGetCString(OidFunctionCall3(Procid[typeindex].outproc,
726 ObjectIdGetDatum(Procid[typeindex].elem),
734 puts("End InsertValue");
747 printf("Inserting null\n");
748 if (i < 0 || i >= MAXATTR)
749 elog(FATAL, "i out of range (too many attrs): %d\n", i);
750 values[i] = PointerGetDatum(NULL);
754 #define MORE_THAN_THE_NUMBER_OF_CATALOGS 256
757 BootstrapAlreadySeen(Oid id)
759 static Oid seenArray[MORE_THAN_THE_NUMBER_OF_CATALOGS];
760 static int nseen = 0;
766 for (i = 0; i < nseen; i++)
768 if (seenArray[i] == id)
776 seenArray[nseen] = id;
789 static int beenhere = 0;
795 elog(FATAL, "Memory manager fault: cleanup called twice.\n");
798 if (reldesc != (Relation) NULL)
799 heap_close(reldesc, NoLock);
800 CommitTransactionCommand();
817 if (Typ != (struct typmap **) NULL)
819 for (app = Typ; *app != (struct typmap *) NULL; app++)
821 if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
824 return (*app)->am_oid;
830 for (i = 0; i <= n_types; i++)
832 if (strncmp(type, Procid[i].name, NAMEDATALEN) == 0)
836 printf("bootstrap.c: External Type: %s\n", type);
837 rel = heap_openr(TypeRelationName, NoLock);
838 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
840 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
843 app = Typ = ALLOC(struct typmap *, i + 1);
845 *app++ = ALLOC(struct typmap, 1);
846 *app = (struct typmap *) NULL;
847 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
849 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
851 (*app)->am_oid = tup->t_data->t_oid;
852 memmove((char *) &(*app++)->am_typ,
853 (char *) GETSTRUCT(tup),
854 sizeof((*app)->am_typ));
857 heap_close(rel, NoLock);
858 return gettype(type);
860 elog(ERROR, "Error: unknown type '%s'.\n", type);
862 /* not reached, here to make compiler happy */
870 static Form_pg_attribute /* XXX */
873 Form_pg_attribute attribute = (Form_pg_attribute) malloc(ATTRIBUTE_TUPLE_SIZE);
875 if (!PointerIsValid(attribute))
876 elog(FATAL, "AllocateAttribute: malloc failed");
877 MemSet(attribute, 0, ATTRIBUTE_TUPLE_SIZE);
884 * XXX arrays of "basetype" are always "_basetype".
885 * this is an evil hack inherited from rel. 3.1.
886 * XXX array dimension is thrown away because we
887 * don't support fixed-dimension arrays. again,
890 * the string passed in must have a '[' character in it
892 * the string returned is a pointer to static storage and should NOT
893 * be freed by the CALLER.
897 MapArrayTypeName(char *s)
901 static char newStr[NAMEDATALEN]; /* array type names < NAMEDATALEN
904 if (s == NULL || s[0] == '\0')
909 for (i = 0; i < NAMEDATALEN - 1 && s[i] != '['; i++, j++)
919 * returns the string table position of the identifier
920 * passed to it. We add it to the table if we can't find it.
924 EnterString(char *str)
931 node = FindStr(str, len, 0);
936 node = AddStr(str, len, 0);
943 * when given an idnum into the 'string-table' return the string
944 * associated with the idnum
948 LexIDStr(int ident_num)
950 return strtable[ident_num];
957 * Compute a hash function for a given string. We look at the first,
958 * the last, and the middle character of a string to try to get spread
959 * the strings out. The function is rather arbitrary, except that we
960 * are mod'ing by a prime number.
964 CompHash(char *str, int len)
968 result = (NUM * str[0] + NUMSQR * str[len - 1] + NUMCUBE * str[(len - 1) / 2]);
970 return result % HASHTABLESIZE;
977 * This routine looks for the specified string in the hash
978 * table. It returns a pointer to the hash node found,
979 * or NULL if the string is not in the table.
983 FindStr(char *str, int length, hashnode *mderef)
987 node = hashtable[CompHash(str, length)];
992 * We must differentiate between string constants that might have
993 * the same value as a identifier and the identifier itself.
995 if (!strcmp(str, strtable[node->strnum]))
997 return node; /* no need to check */
1002 /* Couldn't find it in the list */
1009 * This function adds the specified string, along with its associated
1010 * data, to the hash table and the string table. We return the node
1011 * so that the calling routine can find out the unique id that AddStr
1012 * has assigned to this string.
1016 AddStr(char *str, int strlength, int mderef)
1024 if (++strtable_end == STRTABLESIZE)
1026 /* Error, string table overflow, so we Punt */
1028 "There are too many string constants and identifiers for the compiler to handle.");
1034 * Some of the utilites (eg, define type, create relation) assume that
1035 * the string they're passed is a NAMEDATALEN. We get array bound
1036 * read violations from purify if we don't allocate at least
1037 * NAMEDATALEN bytes for strings of this sort. Because we're lazy, we
1038 * allocate at least NAMEDATALEN bytes all the time.
1041 if ((len = strlength + 1) < NAMEDATALEN)
1044 strtable[strtable_end] = malloc((unsigned) len);
1045 strcpy(strtable[strtable_end], str);
1047 /* Now put a node in the hash table */
1049 newnode = (hashnode *) malloc(sizeof(hashnode) * 1);
1050 newnode->strnum = strtable_end;
1051 newnode->next = NULL;
1053 /* Find out where it goes */
1055 hashresult = CompHash(str, strlength);
1056 if (hashtable[hashresult] == NULL)
1057 hashtable[hashresult] = newnode;
1059 { /* There is something in the list */
1060 trail = hashtable[hashresult];
1062 while (temp != NULL)
1067 trail->next = newnode;
1075 * index_register() -- record an index that has been set up for building
1078 * At bootstrap time, we define a bunch of indices on system catalogs.
1079 * We postpone actually building the indices until just before we're
1080 * finished with initialization, however. This is because more classes
1081 * and indices may be defined, and we want to be sure that all of them
1082 * are present in the index.
1085 index_register(char *heap,
1087 IndexInfo *indexInfo)
1090 MemoryContext oldcxt;
1093 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1094 * bootstrap time. we'll declare the indices now, but want to create
1099 nogc = AllocSetContextCreate((MemoryContext) NULL,
1101 ALLOCSET_DEFAULT_MINSIZE,
1102 ALLOCSET_DEFAULT_INITSIZE,
1103 ALLOCSET_DEFAULT_MAXSIZE);
1105 oldcxt = MemoryContextSwitchTo(nogc);
1107 newind = (IndexList *) palloc(sizeof(IndexList));
1108 newind->il_heap = pstrdup(heap);
1109 newind->il_ind = pstrdup(ind);
1110 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1112 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1113 /* predicate will likely be null anyway, but may as well copy it */
1114 newind->il_info->ii_Predicate = copyObject(indexInfo->ii_Predicate);
1116 newind->il_next = ILHead;
1119 MemoryContextSwitchTo(oldcxt);
1125 for (; ILHead != (IndexList *) NULL; ILHead = ILHead->il_next)
1130 heap = heap_openr(ILHead->il_heap, NoLock);
1131 ind = index_openr(ILHead->il_ind);
1132 index_build(heap, ind, ILHead->il_info, NULL);
1135 * In normal processing mode, index_build would close the heap and
1136 * index, but in bootstrap mode it will not.
1140 * All of the rest of this routine is needed only because in
1141 * bootstrap processing we don't increment xact id's. The normal
1142 * DefineIndex code replaces a pg_class tuple with updated info
1143 * including the relhasindex flag (which we need to have updated).
1144 * Unfortunately, there are always two indices defined on each
1145 * catalog causing us to update the same pg_class tuple twice for
1146 * each catalog getting an index during bootstrap resulting in the
1147 * ghost tuple problem (see heap_update). To get around this we
1148 * change the relhasindex field ourselves in this routine keeping
1149 * track of what catalogs we already changed so that we don't
1150 * modify those tuples twice. The normal mechanism for updating
1151 * pg_class is disabled during bootstrap.
1155 if (!BootstrapAlreadySeen(RelationGetRelid(heap)))
1156 UpdateStats(RelationGetRelid(heap), 0);
1158 /* XXX Probably we ought to close the heap and index here? */