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-2011, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/bootstrap/bootstrap.c
13 *-------------------------------------------------------------------------
24 #include "access/genam.h"
25 #include "access/heapam.h"
26 #include "access/xact.h"
27 #include "bootstrap/bootstrap.h"
28 #include "catalog/index.h"
29 #include "catalog/pg_collation.h"
30 #include "catalog/pg_type.h"
31 #include "libpq/pqsignal.h"
32 #include "miscadmin.h"
33 #include "nodes/makefuncs.h"
34 #include "postmaster/bgwriter.h"
35 #include "postmaster/walwriter.h"
36 #include "replication/walreceiver.h"
37 #include "storage/bufmgr.h"
38 #include "storage/ipc.h"
39 #include "storage/proc.h"
40 #include "storage/procsignal.h"
41 #include "tcop/tcopprot.h"
42 #include "utils/builtins.h"
43 #include "utils/fmgroids.h"
44 #include "utils/memutils.h"
45 #include "utils/ps_status.h"
46 #include "utils/relmapper.h"
47 #include "utils/tqual.h"
53 #define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
55 static void CheckerModeMain(void);
56 static void BootstrapModeMain(void);
57 static void bootstrap_signals(void);
58 static void ShutdownAuxiliaryProcess(int code, Datum arg);
59 static Form_pg_attribute AllocateAttribute(void);
60 static Oid gettype(char *type);
61 static void cleanup(void);
68 Relation boot_reldesc; /* current relation descriptor */
70 Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */
71 int numattr; /* number of attributes for cur. rel */
75 * Basic information associated with each type. This is used before
76 * pg_type is filled, so it has to cover the datatypes used as column types
77 * in the core "bootstrapped" catalogs.
79 * XXX several of these input/output functions do catalog scans
80 * (e.g., F_REGPROCIN scans pg_proc). this obviously creates some
81 * order dependencies in the catalog creation process.
85 char name[NAMEDATALEN];
97 static const struct typinfo TypInfo[] = {
98 {"bool", BOOLOID, 0, 1, true, 'c', 'p', InvalidOid,
100 {"bytea", BYTEAOID, 0, -1, false, 'i', 'x', InvalidOid,
101 F_BYTEAIN, F_BYTEAOUT},
102 {"char", CHAROID, 0, 1, true, 'c', 'p', InvalidOid,
103 F_CHARIN, F_CHAROUT},
104 {"int2", INT2OID, 0, 2, true, 's', 'p', InvalidOid,
105 F_INT2IN, F_INT2OUT},
106 {"int4", INT4OID, 0, 4, true, 'i', 'p', InvalidOid,
107 F_INT4IN, F_INT4OUT},
108 {"float4", FLOAT4OID, 0, 4, FLOAT4PASSBYVAL, 'i', 'p', InvalidOid,
109 F_FLOAT4IN, F_FLOAT4OUT},
110 {"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'c', 'p', InvalidOid,
111 F_NAMEIN, F_NAMEOUT},
112 {"regclass", REGCLASSOID, 0, 4, true, 'i', 'p', InvalidOid,
113 F_REGCLASSIN, F_REGCLASSOUT},
114 {"regproc", REGPROCOID, 0, 4, true, 'i', 'p', InvalidOid,
115 F_REGPROCIN, F_REGPROCOUT},
116 {"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
117 F_REGTYPEIN, F_REGTYPEOUT},
118 {"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
119 F_TEXTIN, F_TEXTOUT},
120 {"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
122 {"tid", TIDOID, 0, 6, false, 's', 'p', InvalidOid,
124 {"xid", XIDOID, 0, 4, true, 'i', 'p', InvalidOid,
126 {"cid", CIDOID, 0, 4, true, 'i', 'p', InvalidOid,
128 {"pg_node_tree", PGNODETREEOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
129 F_PG_NODE_TREE_IN, F_PG_NODE_TREE_OUT},
130 {"int2vector", INT2VECTOROID, INT2OID, -1, false, 'i', 'p', InvalidOid,
131 F_INT2VECTORIN, F_INT2VECTOROUT},
132 {"oidvector", OIDVECTOROID, OIDOID, -1, false, 'i', 'p', InvalidOid,
133 F_OIDVECTORIN, F_OIDVECTOROUT},
134 {"_int4", INT4ARRAYOID, INT4OID, -1, false, 'i', 'x', InvalidOid,
135 F_ARRAY_IN, F_ARRAY_OUT},
136 {"_text", 1009, TEXTOID, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
137 F_ARRAY_IN, F_ARRAY_OUT},
138 {"_oid", 1028, OIDOID, -1, false, 'i', 'x', InvalidOid,
139 F_ARRAY_IN, F_ARRAY_OUT},
140 {"_char", 1002, CHAROID, -1, false, 'i', 'x', InvalidOid,
141 F_ARRAY_IN, F_ARRAY_OUT},
142 {"_aclitem", 1034, ACLITEMOID, -1, false, 'i', 'x', InvalidOid,
143 F_ARRAY_IN, F_ARRAY_OUT}
146 static const int n_types = sizeof(TypInfo) / sizeof(struct typinfo);
151 FormData_pg_type am_typ;
154 static struct typmap **Typ = NULL;
155 static struct typmap *Ap = NULL;
157 static Datum values[MAXATTR]; /* current row's attribute values */
158 static bool Nulls[MAXATTR];
160 static MemoryContext nogc = NULL; /* special no-gc mem context */
163 * At bootstrap time, we first declare all the indices to be built, and
164 * then build them. The IndexList structure stores enough information
165 * to allow us to build the indices after they've been declared.
168 typedef struct _IndexList
173 struct _IndexList *il_next;
176 static IndexList *ILHead = NULL;
180 * AuxiliaryProcessMain
182 * The main entry point for auxiliary processes, such as the bgwriter,
183 * walwriter, walreceiver, bootstrapper and the shared memory checker code.
185 * This code is here just because of historical reasons.
188 AuxiliaryProcessMain(int argc, char *argv[])
190 char *progname = argv[0];
192 AuxProcType auxType = CheckerProcess;
193 char *userDoption = NULL;
198 MyProcPid = getpid();
200 MyStartTime = time(NULL);
203 * Fire up essential subsystems: error and memory management
205 * If we are running under the postmaster, this is done already.
207 if (!IsUnderPostmaster)
210 /* Compute paths, if we didn't inherit them from postmaster */
211 if (my_exec_path[0] == '\0')
213 if (find_my_exec(progname, my_exec_path) < 0)
214 elog(FATAL, "%s: could not locate my own executable path",
219 * process command arguments
222 /* Set defaults, to be overriden by explicit options below */
223 if (!IsUnderPostmaster)
224 InitializeGUCOptions();
226 /* Ignore the initial --boot argument, if present */
227 if (argc > 1 && strcmp(argv[1], "--boot") == 0)
233 while ((flag = getopt(argc, argv, "B:c:d:D:Fr:x:-:")) != -1)
238 SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
241 userDoption = optarg;
245 /* Turn on debugging for the bootstrap process. */
246 char *debugstr = palloc(strlen("debug") + strlen(optarg) + 1);
248 sprintf(debugstr, "debug%s", optarg);
249 SetConfigOption("log_min_messages", debugstr,
250 PGC_POSTMASTER, PGC_S_ARGV);
251 SetConfigOption("client_min_messages", debugstr,
252 PGC_POSTMASTER, PGC_S_ARGV);
257 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
260 strlcpy(OutputFileName, optarg, MAXPGPATH);
263 auxType = atoi(optarg);
271 ParseLongOption(optarg, &name, &value);
276 (errcode(ERRCODE_SYNTAX_ERROR),
277 errmsg("--%s requires a value",
281 (errcode(ERRCODE_SYNTAX_ERROR),
282 errmsg("-c %s requires a value",
286 SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
293 write_stderr("Try \"%s --help\" for more information.\n",
302 write_stderr("%s: invalid command-line arguments\n", progname);
307 * Identify myself via ps
309 if (IsUnderPostmaster)
316 statmsg = "startup process";
318 case BgWriterProcess:
319 statmsg = "writer process";
321 case WalWriterProcess:
322 statmsg = "wal writer process";
324 case WalReceiverProcess:
325 statmsg = "wal receiver process";
328 statmsg = "??? process";
331 init_ps_display(statmsg, "", "", "");
334 /* Acquire configuration parameters, unless inherited from postmaster */
335 if (!IsUnderPostmaster)
337 if (!SelectConfigFiles(userDoption, progname))
339 /* If timezone is not set, determine what the OS uses */
340 pg_timezone_initialize();
341 /* If timezone_abbreviations is not set, select default */
342 pg_timezone_abbrev_initialize();
345 /* Validate we have been given a reasonable-looking DataDir */
347 ValidatePgVersion(DataDir);
349 /* Change into DataDir (if under postmaster, should be done already) */
350 if (!IsUnderPostmaster)
353 /* If standalone, create lockfile for data directory */
354 if (!IsUnderPostmaster)
355 CreateDataDirLockFile(false);
357 SetProcessingMode(BootstrapProcessing);
358 IgnoreSystemIndexes = true;
363 * When we are an auxiliary process, we aren't going to do the full
364 * InitPostgres pushups, but there are a couple of things that need to get
365 * lit up even in an auxiliary process.
367 if (IsUnderPostmaster)
370 * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
371 * this was already done by SubPostmasterMain().
374 InitAuxiliaryProcess();
378 * Assign the ProcSignalSlot for an auxiliary process. Since it
379 * doesn't have a BackendId, the slot is statically allocated based on
380 * the auxiliary process type (auxType). Backends use slots indexed
381 * in the range from 1 to MaxBackends (inclusive), so we use
382 * MaxBackends + AuxProcType + 1 as the index of the slot for an
385 * This will need rethinking if we ever want more than one of a
386 * particular auxiliary process type.
388 ProcSignalInit(MaxBackends + auxType + 1);
390 /* finish setting up bufmgr.c */
391 InitBufferPoolBackend();
393 /* register a shutdown callback for LWLock cleanup */
394 on_shmem_exit(ShutdownAuxiliaryProcess, 0);
400 SetProcessingMode(NormalProcessing);
405 /* don't set signals, they're useless here */
407 proc_exit(1); /* should never return */
409 case BootstrapProcess:
413 proc_exit(1); /* should never return */
416 /* don't set signals, startup process has its own agenda */
417 StartupProcessMain();
418 proc_exit(1); /* should never return */
420 case BgWriterProcess:
421 /* don't set signals, bgwriter has its own agenda */
422 BackgroundWriterMain();
423 proc_exit(1); /* should never return */
425 case WalWriterProcess:
426 /* don't set signals, walwriter has its own agenda */
429 proc_exit(1); /* should never return */
431 case WalReceiverProcess:
432 /* don't set signals, walreceiver has its own agenda */
434 proc_exit(1); /* should never return */
437 elog(PANIC, "unrecognized process type: %d", auxType);
443 * In shared memory checker mode, all we really want to do is create shared
444 * memory and semaphores (just to prove we can do it with the current GUC
445 * settings). Since, in fact, that was already done by BaseInit(),
446 * we have nothing more to do here.
449 CheckerModeMain(void)
455 * The main entry point for running the backend in bootstrap mode
457 * The bootstrap mode is used to initialize the template database.
458 * The bootstrap backend doesn't speak SQL, but instead expects
459 * commands in a special bootstrap language.
462 BootstrapModeMain(void)
466 Assert(!IsUnderPostmaster);
468 SetProcessingMode(BootstrapProcessing);
471 * Do backend-like initialization for bootstrap mode
475 InitPostgres(NULL, InvalidOid, NULL, NULL);
477 /* Initialize stuff for bootstrap-file processing */
478 for (i = 0; i < MAXATTR; i++)
485 * Process bootstrap input.
490 * We should now know about all mapped relations, so it's okay to write
491 * out the initial relation mapping files.
493 RelationMapFinishBootstrap();
495 /* Clean up and exit */
501 /* ----------------------------------------------------------------
503 * ----------------------------------------------------------------
507 * Set up signal handling for a bootstrap process
510 bootstrap_signals(void)
512 if (IsUnderPostmaster)
515 * If possible, make this process a group leader, so that the
516 * postmaster can signal any child processes too.
520 elog(FATAL, "setsid() failed: %m");
524 * Properly accept or ignore signals the postmaster might send us
526 pqsignal(SIGHUP, SIG_IGN);
527 pqsignal(SIGINT, SIG_IGN); /* ignore query-cancel */
528 pqsignal(SIGTERM, die);
529 pqsignal(SIGQUIT, quickdie);
530 pqsignal(SIGALRM, SIG_IGN);
531 pqsignal(SIGPIPE, SIG_IGN);
532 pqsignal(SIGUSR1, SIG_IGN);
533 pqsignal(SIGUSR2, SIG_IGN);
536 * Reset some signals that are accepted by postmaster but not here
538 pqsignal(SIGCHLD, SIG_DFL);
539 pqsignal(SIGTTIN, SIG_DFL);
540 pqsignal(SIGTTOU, SIG_DFL);
541 pqsignal(SIGCONT, SIG_DFL);
542 pqsignal(SIGWINCH, SIG_DFL);
545 * Unblock signals (they were blocked when the postmaster forked us)
547 PG_SETMASK(&UnBlockSig);
551 /* Set up appropriately for interactive use */
552 pqsignal(SIGHUP, die);
553 pqsignal(SIGINT, die);
554 pqsignal(SIGTERM, die);
555 pqsignal(SIGQUIT, die);
560 * Begin shutdown of an auxiliary process. This is approximately the equivalent
561 * of ShutdownPostgres() in postinit.c. We can't run transactions in an
562 * auxiliary process, so most of the work of AbortTransaction() is not needed,
563 * but we do need to make sure we've released any LWLocks we are holding.
564 * (This is only critical during an error exit.)
567 ShutdownAuxiliaryProcess(int code, Datum arg)
572 /* ----------------------------------------------------------------
573 * MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
574 * ----------------------------------------------------------------
582 boot_openrel(char *relname)
590 if (strlen(relname) >= NAMEDATALEN)
591 relname[NAMEDATALEN - 1] = '\0';
595 /* We can now load the pg_type data */
596 rel = heap_open(TypeRelationId, NoLock);
597 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
599 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
602 app = Typ = ALLOC(struct typmap *, i + 1);
604 *app++ = ALLOC(struct typmap, 1);
606 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
608 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
610 (*app)->am_oid = HeapTupleGetOid(tup);
611 memcpy((char *) &(*app)->am_typ,
612 (char *) GETSTRUCT(tup),
613 sizeof((*app)->am_typ));
617 heap_close(rel, NoLock);
620 if (boot_reldesc != NULL)
623 elog(DEBUG4, "open relation %s, attrsize %d",
624 relname, (int) ATTRIBUTE_FIXED_PART_SIZE);
626 boot_reldesc = heap_openrv(makeRangeVar(NULL, relname, -1), NoLock);
627 numattr = boot_reldesc->rd_rel->relnatts;
628 for (i = 0; i < numattr; i++)
630 if (attrtypes[i] == NULL)
631 attrtypes[i] = AllocateAttribute();
632 memmove((char *) attrtypes[i],
633 (char *) boot_reldesc->rd_att->attrs[i],
634 ATTRIBUTE_FIXED_PART_SIZE);
637 Form_pg_attribute at = attrtypes[i];
639 elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
640 i, NameStr(at->attname), at->attlen, at->attnum,
657 if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
658 elog(ERROR, "close of %s when %s was expected",
659 name, RelationGetRelationName(boot_reldesc));
662 elog(ERROR, "close of %s before any relation was opened",
666 if (boot_reldesc == NULL)
667 elog(ERROR, "no open relation to close");
670 elog(DEBUG4, "close relation %s",
671 RelationGetRelationName(boot_reldesc));
672 heap_close(boot_reldesc, NoLock);
682 * define a <field,type> pair
683 * if there are n fields in a relation to be created, this routine
684 * will be called n times
688 DefineAttr(char *name, char *type, int attnum)
692 if (boot_reldesc != NULL)
694 elog(WARNING, "no open relations allowed with CREATE command");
698 if (attrtypes[attnum] == NULL)
699 attrtypes[attnum] = AllocateAttribute();
700 MemSet(attrtypes[attnum], 0, ATTRIBUTE_FIXED_PART_SIZE);
702 namestrcpy(&attrtypes[attnum]->attname, name);
703 elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
704 attrtypes[attnum]->attnum = attnum + 1; /* fillatt */
706 typeoid = gettype(type);
710 attrtypes[attnum]->atttypid = Ap->am_oid;
711 attrtypes[attnum]->attlen = Ap->am_typ.typlen;
712 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
713 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
714 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
715 attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
716 /* if an array type, assume 1-dimensional attribute */
717 if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
718 attrtypes[attnum]->attndims = 1;
720 attrtypes[attnum]->attndims = 0;
724 attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
725 attrtypes[attnum]->attlen = TypInfo[typeoid].len;
726 attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
727 attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
728 attrtypes[attnum]->attalign = TypInfo[typeoid].align;
729 attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
730 /* if an array type, assume 1-dimensional attribute */
731 if (TypInfo[typeoid].elem != InvalidOid &&
732 attrtypes[attnum]->attlen < 0)
733 attrtypes[attnum]->attndims = 1;
735 attrtypes[attnum]->attndims = 0;
738 attrtypes[attnum]->attstattarget = -1;
739 attrtypes[attnum]->attcacheoff = -1;
740 attrtypes[attnum]->atttypmod = -1;
741 attrtypes[attnum]->attislocal = true;
744 * Mark as "not null" if type is fixed-width and prior columns are too.
745 * This corresponds to case where column can be accessed directly via C
746 * struct declaration.
748 * oidvector and int2vector are also treated as not-nullable, even though
749 * they are no longer fixed-width.
751 #define MARKNOTNULL(att) \
752 ((att)->attlen > 0 || \
753 (att)->atttypid == OIDVECTOROID || \
754 (att)->atttypid == INT2VECTOROID)
756 if (MARKNOTNULL(attrtypes[attnum]))
760 for (i = 0; i < attnum; i++)
762 if (!MARKNOTNULL(attrtypes[i]))
766 attrtypes[attnum]->attnotnull = true;
774 * If objectid is not zero, it is a specific OID to assign to the tuple.
775 * Otherwise, an OID will be assigned (if necessary) by heap_insert.
779 InsertOneTuple(Oid objectid)
785 elog(DEBUG4, "inserting row oid %u, %d columns", objectid, numattr);
787 tupDesc = CreateTupleDesc(numattr,
788 RelationGetForm(boot_reldesc)->relhasoids,
790 tuple = heap_form_tuple(tupDesc, values, Nulls);
791 if (objectid != (Oid) 0)
792 HeapTupleSetOid(tuple, objectid);
793 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
795 simple_heap_insert(boot_reldesc, tuple);
796 heap_freetuple(tuple);
797 elog(DEBUG4, "row inserted");
800 * Reset null markers for next tuple
802 for (i = 0; i < numattr; i++)
811 InsertOneValue(char *value, int i)
823 AssertArg(i >= 0 || i < MAXATTR);
825 elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
827 typoid = boot_reldesc->rd_att->attrs[i]->atttypid;
829 boot_get_type_io_data(typoid,
830 &typlen, &typbyval, &typalign,
831 &typdelim, &typioparam,
832 &typinput, &typoutput);
834 values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
835 prt = OidOutputFunctionCall(typoutput, values[i]);
836 elog(DEBUG4, "inserted -> %s", prt);
847 elog(DEBUG4, "inserting column %d NULL", i);
848 Assert(i >= 0 || i < MAXATTR);
849 values[i] = PointerGetDatum(NULL);
860 if (boot_reldesc != NULL)
867 * NB: this is really ugly; it will return an integer index into TypInfo[],
868 * and not an OID at all, until the first reference to a type not known in
869 * TypInfo[]. At that point it will read and cache pg_type in the Typ array,
870 * and subsequently return a real OID (and set the global pointer Ap to
871 * point at the found row in Typ). So caller must check whether Typ is
872 * still NULL to determine what the return value is!
886 for (app = Typ; *app != NULL; app++)
888 if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
891 return (*app)->am_oid;
897 for (i = 0; i < n_types; i++)
899 if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
902 elog(DEBUG4, "external type: %s", type);
903 rel = heap_open(TypeRelationId, NoLock);
904 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
906 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
909 app = Typ = ALLOC(struct typmap *, i + 1);
911 *app++ = ALLOC(struct typmap, 1);
913 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
915 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
917 (*app)->am_oid = HeapTupleGetOid(tup);
918 memmove((char *) &(*app++)->am_typ,
919 (char *) GETSTRUCT(tup),
920 sizeof((*app)->am_typ));
923 heap_close(rel, NoLock);
924 return gettype(type);
926 elog(ERROR, "unrecognized type \"%s\"", type);
927 /* not reached, here to make compiler happy */
932 * boot_get_type_io_data
934 * Obtain type I/O information at bootstrap time. This intentionally has
935 * almost the same API as lsyscache.c's get_type_io_data, except that
936 * we only support obtaining the typinput and typoutput routines, not
937 * the binary I/O routines. It is exported so that array_in and array_out
938 * can be made to work during early bootstrap.
942 boot_get_type_io_data(Oid typid,
953 /* We have the boot-time contents of pg_type, so use it */
958 while (*app && (*app)->am_oid != typid)
962 elog(ERROR, "type OID %u not found in Typ list", typid);
964 *typlen = ap->am_typ.typlen;
965 *typbyval = ap->am_typ.typbyval;
966 *typalign = ap->am_typ.typalign;
967 *typdelim = ap->am_typ.typdelim;
969 /* XXX this logic must match getTypeIOParam() */
970 if (OidIsValid(ap->am_typ.typelem))
971 *typioparam = ap->am_typ.typelem;
975 *typinput = ap->am_typ.typinput;
976 *typoutput = ap->am_typ.typoutput;
980 /* We don't have pg_type yet, so use the hard-wired TypInfo array */
983 for (typeindex = 0; typeindex < n_types; typeindex++)
985 if (TypInfo[typeindex].oid == typid)
988 if (typeindex >= n_types)
989 elog(ERROR, "type OID %u not found in TypInfo", typid);
991 *typlen = TypInfo[typeindex].len;
992 *typbyval = TypInfo[typeindex].byval;
993 *typalign = TypInfo[typeindex].align;
994 /* We assume typdelim is ',' for all boot-time types */
997 /* XXX this logic must match getTypeIOParam() */
998 if (OidIsValid(TypInfo[typeindex].elem))
999 *typioparam = TypInfo[typeindex].elem;
1001 *typioparam = typid;
1003 *typinput = TypInfo[typeindex].inproc;
1004 *typoutput = TypInfo[typeindex].outproc;
1011 * Note: bootstrap never sets any per-column ACLs, so we only need
1012 * ATTRIBUTE_FIXED_PART_SIZE space per attribute.
1015 static Form_pg_attribute
1016 AllocateAttribute(void)
1018 Form_pg_attribute attribute = (Form_pg_attribute) malloc(ATTRIBUTE_FIXED_PART_SIZE);
1020 if (!PointerIsValid(attribute))
1021 elog(FATAL, "out of memory");
1022 MemSet(attribute, 0, ATTRIBUTE_FIXED_PART_SIZE);
1029 * XXX arrays of "basetype" are always "_basetype".
1030 * this is an evil hack inherited from rel. 3.1.
1031 * XXX array dimension is thrown away because we
1032 * don't support fixed-dimension arrays. again,
1033 * sickness from 3.1.
1035 * the string passed in must have a '[' character in it
1037 * the string returned is a pointer to static storage and should NOT
1038 * be freed by the CALLER.
1042 MapArrayTypeName(char *s)
1046 static char newStr[NAMEDATALEN]; /* array type names < NAMEDATALEN long */
1048 if (s == NULL || s[0] == '\0')
1053 for (i = 0; i < NAMEDATALEN - 1 && s[i] != '['; i++, j++)
1063 * index_register() -- record an index that has been set up for building
1066 * At bootstrap time, we define a bunch of indexes on system catalogs.
1067 * We postpone actually building the indexes until just before we're
1068 * finished with initialization, however. This is because the indexes
1069 * themselves have catalog entries, and those have to be included in the
1070 * indexes on those catalogs. Doing it in two phases is the simplest
1071 * way of making sure the indexes have the right contents at the end.
1074 index_register(Oid heap,
1076 IndexInfo *indexInfo)
1079 MemoryContext oldcxt;
1082 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1083 * bootstrap time. we'll declare the indexes now, but want to create them
1088 nogc = AllocSetContextCreate(NULL,
1090 ALLOCSET_DEFAULT_MINSIZE,
1091 ALLOCSET_DEFAULT_INITSIZE,
1092 ALLOCSET_DEFAULT_MAXSIZE);
1094 oldcxt = MemoryContextSwitchTo(nogc);
1096 newind = (IndexList *) palloc(sizeof(IndexList));
1097 newind->il_heap = heap;
1098 newind->il_ind = ind;
1099 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1101 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1102 /* expressions will likely be null, but may as well copy it */
1103 newind->il_info->ii_Expressions = (List *)
1104 copyObject(indexInfo->ii_Expressions);
1105 newind->il_info->ii_ExpressionsState = NIL;
1106 /* predicate will likely be null, but may as well copy it */
1107 newind->il_info->ii_Predicate = (List *)
1108 copyObject(indexInfo->ii_Predicate);
1109 newind->il_info->ii_PredicateState = NIL;
1110 /* no exclusion constraints at bootstrap time, so no need to copy */
1111 Assert(indexInfo->ii_ExclusionOps == NULL);
1112 Assert(indexInfo->ii_ExclusionProcs == NULL);
1113 Assert(indexInfo->ii_ExclusionStrats == NULL);
1115 newind->il_next = ILHead;
1118 MemoryContextSwitchTo(oldcxt);
1123 * build_indices -- fill in all the indexes registered earlier
1128 for (; ILHead != NULL; ILHead = ILHead->il_next)
1133 /* need not bother with locks during bootstrap */
1134 heap = heap_open(ILHead->il_heap, NoLock);
1135 ind = index_open(ILHead->il_ind, NoLock);
1137 index_build(heap, ind, ILHead->il_info, false, false);
1139 index_close(ind, NoLock);
1140 heap_close(heap, NoLock);