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-2010, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.255 2010/01/02 16:57:36 momjian Exp $
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_type.h"
30 #include "libpq/pqsignal.h"
31 #include "miscadmin.h"
32 #include "nodes/makefuncs.h"
33 #include "postmaster/bgwriter.h"
34 #include "postmaster/walwriter.h"
35 #include "storage/bufmgr.h"
36 #include "storage/ipc.h"
37 #include "storage/proc.h"
38 #include "storage/procsignal.h"
39 #include "tcop/tcopprot.h"
40 #include "utils/builtins.h"
41 #include "utils/fmgroids.h"
42 #include "utils/memutils.h"
43 #include "utils/ps_status.h"
44 #include "utils/tqual.h"
50 #define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
52 static void CheckerModeMain(void);
53 static void BootstrapModeMain(void);
54 static void bootstrap_signals(void);
55 static void ShutdownAuxiliaryProcess(int code, Datum arg);
56 static Form_pg_attribute AllocateAttribute(void);
57 static Oid gettype(char *type);
58 static void cleanup(void);
65 Relation boot_reldesc; /* current relation descriptor */
67 Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */
68 int numattr; /* number of attributes for cur. rel */
72 * Basic information associated with each type. This is used before
75 * XXX several of these input/output functions do catalog scans
76 * (e.g., F_REGPROCIN scans pg_proc). this obviously creates some
77 * order dependencies in the catalog creation process.
81 char name[NAMEDATALEN];
92 static const struct typinfo TypInfo[] = {
93 {"bool", BOOLOID, 0, 1, true, 'c', 'p',
95 {"bytea", BYTEAOID, 0, -1, false, 'i', 'x',
96 F_BYTEAIN, F_BYTEAOUT},
97 {"char", CHAROID, 0, 1, true, 'c', 'p',
99 {"int2", INT2OID, 0, 2, true, 's', 'p',
100 F_INT2IN, F_INT2OUT},
101 {"int4", INT4OID, 0, 4, true, 'i', 'p',
102 F_INT4IN, F_INT4OUT},
103 {"float4", FLOAT4OID, 0, 4, FLOAT4PASSBYVAL, 'i', 'p',
104 F_FLOAT4IN, F_FLOAT4OUT},
105 {"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'c', 'p',
106 F_NAMEIN, F_NAMEOUT},
107 {"regclass", REGCLASSOID, 0, 4, true, 'i', 'p',
108 F_REGCLASSIN, F_REGCLASSOUT},
109 {"regproc", REGPROCOID, 0, 4, true, 'i', 'p',
110 F_REGPROCIN, F_REGPROCOUT},
111 {"regtype", REGTYPEOID, 0, 4, true, 'i', 'p',
112 F_REGTYPEIN, F_REGTYPEOUT},
113 {"text", TEXTOID, 0, -1, false, 'i', 'x',
114 F_TEXTIN, F_TEXTOUT},
115 {"oid", OIDOID, 0, 4, true, 'i', 'p',
117 {"tid", TIDOID, 0, 6, false, 's', 'p',
119 {"xid", XIDOID, 0, 4, true, 'i', 'p',
121 {"cid", CIDOID, 0, 4, true, 'i', 'p',
123 {"int2vector", INT2VECTOROID, INT2OID, -1, false, 'i', 'p',
124 F_INT2VECTORIN, F_INT2VECTOROUT},
125 {"oidvector", OIDVECTOROID, OIDOID, -1, false, 'i', 'p',
126 F_OIDVECTORIN, F_OIDVECTOROUT},
127 {"_int4", INT4ARRAYOID, INT4OID, -1, false, 'i', 'x',
128 F_ARRAY_IN, F_ARRAY_OUT},
129 {"_text", 1009, TEXTOID, -1, false, 'i', 'x',
130 F_ARRAY_IN, F_ARRAY_OUT},
131 {"_oid", 1028, OIDOID, -1, false, 'i', 'x',
132 F_ARRAY_IN, F_ARRAY_OUT},
133 {"_char", 1002, CHAROID, -1, false, 'i', 'x',
134 F_ARRAY_IN, F_ARRAY_OUT},
135 {"_aclitem", 1034, ACLITEMOID, -1, false, 'i', 'x',
136 F_ARRAY_IN, F_ARRAY_OUT}
139 static const int n_types = sizeof(TypInfo) / sizeof(struct typinfo);
144 FormData_pg_type am_typ;
147 static struct typmap **Typ = NULL;
148 static struct typmap *Ap = NULL;
150 static Datum values[MAXATTR]; /* current row's attribute values */
151 static bool Nulls[MAXATTR];
153 static MemoryContext nogc = NULL; /* special no-gc mem context */
156 * At bootstrap time, we first declare all the indices to be built, and
157 * then build them. The IndexList structure stores enough information
158 * to allow us to build the indices after they've been declared.
161 typedef struct _IndexList
166 struct _IndexList *il_next;
169 static IndexList *ILHead = NULL;
173 * AuxiliaryProcessMain
175 * The main entry point for auxiliary processes, such as the bgwriter,
176 * walwriter, bootstrapper and the shared memory checker code.
178 * This code is here just because of historical reasons.
181 AuxiliaryProcessMain(int argc, char *argv[])
183 char *progname = argv[0];
185 AuxProcType auxType = CheckerProcess;
186 char *userDoption = NULL;
191 MyProcPid = getpid();
193 MyStartTime = time(NULL);
196 * Fire up essential subsystems: error and memory management
198 * If we are running under the postmaster, this is done already.
200 if (!IsUnderPostmaster)
203 /* Compute paths, if we didn't inherit them from postmaster */
204 if (my_exec_path[0] == '\0')
206 if (find_my_exec(progname, my_exec_path) < 0)
207 elog(FATAL, "%s: could not locate my own executable path",
212 * process command arguments
215 /* Set defaults, to be overriden by explicit options below */
216 if (!IsUnderPostmaster)
217 InitializeGUCOptions();
219 /* Ignore the initial --boot argument, if present */
220 if (argc > 1 && strcmp(argv[1], "--boot") == 0)
226 while ((flag = getopt(argc, argv, "B:c:d:D:Fr:x:-:")) != -1)
231 SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
234 userDoption = optarg;
238 /* Turn on debugging for the bootstrap process. */
239 char *debugstr = palloc(strlen("debug") + strlen(optarg) + 1);
241 sprintf(debugstr, "debug%s", optarg);
242 SetConfigOption("log_min_messages", debugstr,
243 PGC_POSTMASTER, PGC_S_ARGV);
244 SetConfigOption("client_min_messages", debugstr,
245 PGC_POSTMASTER, PGC_S_ARGV);
250 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
253 strlcpy(OutputFileName, optarg, MAXPGPATH);
256 auxType = atoi(optarg);
264 ParseLongOption(optarg, &name, &value);
269 (errcode(ERRCODE_SYNTAX_ERROR),
270 errmsg("--%s requires a value",
274 (errcode(ERRCODE_SYNTAX_ERROR),
275 errmsg("-c %s requires a value",
279 SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
286 write_stderr("Try \"%s --help\" for more information.\n",
295 write_stderr("%s: invalid command-line arguments\n", progname);
300 * Identify myself via ps
302 if (IsUnderPostmaster)
309 statmsg = "startup process";
311 case BgWriterProcess:
312 statmsg = "writer process";
314 case WalWriterProcess:
315 statmsg = "wal writer process";
318 statmsg = "??? process";
321 init_ps_display(statmsg, "", "", "");
324 /* Acquire configuration parameters, unless inherited from postmaster */
325 if (!IsUnderPostmaster)
327 if (!SelectConfigFiles(userDoption, progname))
329 /* If timezone is not set, determine what the OS uses */
330 pg_timezone_initialize();
331 /* If timezone_abbreviations is not set, select default */
332 pg_timezone_abbrev_initialize();
335 /* Validate we have been given a reasonable-looking DataDir */
337 ValidatePgVersion(DataDir);
339 /* Change into DataDir (if under postmaster, should be done already) */
340 if (!IsUnderPostmaster)
343 /* If standalone, create lockfile for data directory */
344 if (!IsUnderPostmaster)
345 CreateDataDirLockFile(false);
347 SetProcessingMode(BootstrapProcessing);
348 IgnoreSystemIndexes = true;
353 * When we are an auxiliary process, we aren't going to do the full
354 * InitPostgres pushups, but there are a couple of things that need to get
355 * lit up even in an auxiliary process.
357 if (IsUnderPostmaster)
360 * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
361 * this was already done by SubPostmasterMain().
364 InitAuxiliaryProcess();
368 * Assign the ProcSignalSlot for an auxiliary process. Since it
369 * doesn't have a BackendId, the slot is statically allocated based on
370 * the auxiliary process type (auxType). Backends use slots indexed
371 * in the range from 1 to MaxBackends (inclusive), so we use
372 * MaxBackends + AuxProcType + 1 as the index of the slot for an
375 * This will need rethinking if we ever want more than one of a
376 * particular auxiliary process type.
378 ProcSignalInit(MaxBackends + auxType + 1);
380 /* finish setting up bufmgr.c */
381 InitBufferPoolBackend();
383 /* register a shutdown callback for LWLock cleanup */
384 on_shmem_exit(ShutdownAuxiliaryProcess, 0);
390 SetProcessingMode(NormalProcessing);
397 proc_exit(1); /* should never return */
399 case BootstrapProcess:
404 proc_exit(1); /* should never return */
407 /* don't set signals, startup process has its own agenda */
408 StartupProcessMain();
409 proc_exit(1); /* should never return */
411 case BgWriterProcess:
412 /* don't set signals, bgwriter has its own agenda */
413 BackgroundWriterMain();
414 proc_exit(1); /* should never return */
416 case WalWriterProcess:
417 /* don't set signals, walwriter has its own agenda */
420 proc_exit(1); /* should never return */
423 elog(PANIC, "unrecognized process type: %d", auxType);
429 * In shared memory checker mode, all we really want to do is create shared
430 * memory and semaphores (just to prove we can do it with the current GUC
434 CheckerModeMain(void)
437 * We must be getting invoked for bootstrap mode
439 Assert(!IsUnderPostmaster);
441 SetProcessingMode(BootstrapProcessing);
444 * Do backend-like initialization for bootstrap mode
447 InitPostgres(NULL, InvalidOid, NULL, NULL);
452 * The main entry point for running the backend in bootstrap mode
454 * The bootstrap mode is used to initialize the template database.
455 * The bootstrap backend doesn't speak SQL, but instead expects
456 * commands in a special bootstrap language.
459 BootstrapModeMain(void)
463 Assert(!IsUnderPostmaster);
465 SetProcessingMode(BootstrapProcessing);
468 * Do backend-like initialization for bootstrap mode
471 InitPostgres(NULL, InvalidOid, NULL, NULL);
473 /* Initialize stuff for bootstrap-file processing */
474 for (i = 0; i < MAXATTR; i++)
481 * Process bootstrap input.
485 /* Perform a checkpoint to ensure everything's down to disk */
486 SetProcessingMode(NormalProcessing);
487 CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
489 /* Clean up and exit */
495 /* ----------------------------------------------------------------
497 * ----------------------------------------------------------------
501 * Set up signal handling for a bootstrap process
504 bootstrap_signals(void)
506 if (IsUnderPostmaster)
509 * If possible, make this process a group leader, so that the
510 * postmaster can signal any child processes too.
514 elog(FATAL, "setsid() failed: %m");
518 * Properly accept or ignore signals the postmaster might send us
520 pqsignal(SIGHUP, SIG_IGN);
521 pqsignal(SIGINT, SIG_IGN); /* ignore query-cancel */
522 pqsignal(SIGTERM, die);
523 pqsignal(SIGQUIT, quickdie);
524 pqsignal(SIGALRM, SIG_IGN);
525 pqsignal(SIGPIPE, SIG_IGN);
526 pqsignal(SIGUSR1, SIG_IGN);
527 pqsignal(SIGUSR2, SIG_IGN);
530 * Reset some signals that are accepted by postmaster but not here
532 pqsignal(SIGCHLD, SIG_DFL);
533 pqsignal(SIGTTIN, SIG_DFL);
534 pqsignal(SIGTTOU, SIG_DFL);
535 pqsignal(SIGCONT, SIG_DFL);
536 pqsignal(SIGWINCH, SIG_DFL);
539 * Unblock signals (they were blocked when the postmaster forked us)
541 PG_SETMASK(&UnBlockSig);
545 /* Set up appropriately for interactive use */
546 pqsignal(SIGHUP, die);
547 pqsignal(SIGINT, die);
548 pqsignal(SIGTERM, die);
549 pqsignal(SIGQUIT, die);
554 * Begin shutdown of an auxiliary process. This is approximately the equivalent
555 * of ShutdownPostgres() in postinit.c. We can't run transactions in an
556 * auxiliary process, so most of the work of AbortTransaction() is not needed,
557 * but we do need to make sure we've released any LWLocks we are holding.
558 * (This is only critical during an error exit.)
561 ShutdownAuxiliaryProcess(int code, Datum arg)
566 /* ----------------------------------------------------------------
567 * MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
568 * ----------------------------------------------------------------
576 boot_openrel(char *relname)
584 if (strlen(relname) >= NAMEDATALEN)
585 relname[NAMEDATALEN - 1] = '\0';
589 /* We can now load the pg_type data */
590 rel = heap_open(TypeRelationId, NoLock);
591 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
593 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
596 app = Typ = ALLOC(struct typmap *, i + 1);
598 *app++ = ALLOC(struct typmap, 1);
600 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
602 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
604 (*app)->am_oid = HeapTupleGetOid(tup);
605 memcpy((char *) &(*app)->am_typ,
606 (char *) GETSTRUCT(tup),
607 sizeof((*app)->am_typ));
611 heap_close(rel, NoLock);
614 if (boot_reldesc != NULL)
617 elog(DEBUG4, "open relation %s, attrsize %d",
618 relname, (int) ATTRIBUTE_FIXED_PART_SIZE);
620 boot_reldesc = heap_openrv(makeRangeVar(NULL, relname, -1), NoLock);
621 numattr = boot_reldesc->rd_rel->relnatts;
622 for (i = 0; i < numattr; i++)
624 if (attrtypes[i] == NULL)
625 attrtypes[i] = AllocateAttribute();
626 memmove((char *) attrtypes[i],
627 (char *) boot_reldesc->rd_att->attrs[i],
628 ATTRIBUTE_FIXED_PART_SIZE);
631 Form_pg_attribute at = attrtypes[i];
633 elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
634 i, NameStr(at->attname), at->attlen, at->attnum,
651 if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
652 elog(ERROR, "close of %s when %s was expected",
653 name, RelationGetRelationName(boot_reldesc));
656 elog(ERROR, "close of %s before any relation was opened",
660 if (boot_reldesc == NULL)
661 elog(ERROR, "no open relation to close");
664 elog(DEBUG4, "close relation %s",
665 RelationGetRelationName(boot_reldesc));
666 heap_close(boot_reldesc, NoLock);
676 * define a <field,type> pair
677 * if there are n fields in a relation to be created, this routine
678 * will be called n times
682 DefineAttr(char *name, char *type, int attnum)
686 if (boot_reldesc != NULL)
688 elog(WARNING, "no open relations allowed with CREATE command");
692 if (attrtypes[attnum] == NULL)
693 attrtypes[attnum] = AllocateAttribute();
694 MemSet(attrtypes[attnum], 0, ATTRIBUTE_FIXED_PART_SIZE);
696 namestrcpy(&attrtypes[attnum]->attname, name);
697 elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
698 attrtypes[attnum]->attnum = attnum + 1; /* fillatt */
700 typeoid = gettype(type);
704 attrtypes[attnum]->atttypid = Ap->am_oid;
705 attrtypes[attnum]->attlen = Ap->am_typ.typlen;
706 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
707 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
708 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
709 /* if an array type, assume 1-dimensional attribute */
710 if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
711 attrtypes[attnum]->attndims = 1;
713 attrtypes[attnum]->attndims = 0;
717 attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
718 attrtypes[attnum]->attlen = TypInfo[typeoid].len;
719 attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
720 attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
721 attrtypes[attnum]->attalign = TypInfo[typeoid].align;
722 /* if an array type, assume 1-dimensional attribute */
723 if (TypInfo[typeoid].elem != InvalidOid &&
724 attrtypes[attnum]->attlen < 0)
725 attrtypes[attnum]->attndims = 1;
727 attrtypes[attnum]->attndims = 0;
730 attrtypes[attnum]->attstattarget = -1;
731 attrtypes[attnum]->attdistinct = 0;
732 attrtypes[attnum]->attcacheoff = -1;
733 attrtypes[attnum]->atttypmod = -1;
734 attrtypes[attnum]->attislocal = true;
737 * Mark as "not null" if type is fixed-width and prior columns are too.
738 * This corresponds to case where column can be accessed directly via C
739 * struct declaration.
741 * oidvector and int2vector are also treated as not-nullable, even though
742 * they are no longer fixed-width.
744 #define MARKNOTNULL(att) \
745 ((att)->attlen > 0 || \
746 (att)->atttypid == OIDVECTOROID || \
747 (att)->atttypid == INT2VECTOROID)
749 if (MARKNOTNULL(attrtypes[attnum]))
753 for (i = 0; i < attnum; i++)
755 if (!MARKNOTNULL(attrtypes[i]))
759 attrtypes[attnum]->attnotnull = true;
767 * If objectid is not zero, it is a specific OID to assign to the tuple.
768 * Otherwise, an OID will be assigned (if necessary) by heap_insert.
772 InsertOneTuple(Oid objectid)
778 elog(DEBUG4, "inserting row oid %u, %d columns", objectid, numattr);
780 tupDesc = CreateTupleDesc(numattr,
781 RelationGetForm(boot_reldesc)->relhasoids,
783 tuple = heap_form_tuple(tupDesc, values, Nulls);
784 if (objectid != (Oid) 0)
785 HeapTupleSetOid(tuple, objectid);
786 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
788 simple_heap_insert(boot_reldesc, tuple);
789 heap_freetuple(tuple);
790 elog(DEBUG4, "row inserted");
793 * Reset null markers for next tuple
795 for (i = 0; i < numattr; i++)
804 InsertOneValue(char *value, int i)
816 AssertArg(i >= 0 || i < MAXATTR);
818 elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
820 typoid = boot_reldesc->rd_att->attrs[i]->atttypid;
822 boot_get_type_io_data(typoid,
823 &typlen, &typbyval, &typalign,
824 &typdelim, &typioparam,
825 &typinput, &typoutput);
827 values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
828 prt = OidOutputFunctionCall(typoutput, values[i]);
829 elog(DEBUG4, "inserted -> %s", prt);
840 elog(DEBUG4, "inserting column %d NULL", i);
841 Assert(i >= 0 || i < MAXATTR);
842 values[i] = PointerGetDatum(NULL);
853 if (boot_reldesc != NULL)
860 * NB: this is really ugly; it will return an integer index into TypInfo[],
861 * and not an OID at all, until the first reference to a type not known in
862 * TypInfo[]. At that point it will read and cache pg_type in the Typ array,
863 * and subsequently return a real OID (and set the global pointer Ap to
864 * point at the found row in Typ). So caller must check whether Typ is
865 * still NULL to determine what the return value is!
879 for (app = Typ; *app != NULL; app++)
881 if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
884 return (*app)->am_oid;
890 for (i = 0; i < n_types; i++)
892 if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
895 elog(DEBUG4, "external type: %s", type);
896 rel = heap_open(TypeRelationId, NoLock);
897 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
899 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
902 app = Typ = ALLOC(struct typmap *, i + 1);
904 *app++ = ALLOC(struct typmap, 1);
906 scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
908 while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
910 (*app)->am_oid = HeapTupleGetOid(tup);
911 memmove((char *) &(*app++)->am_typ,
912 (char *) GETSTRUCT(tup),
913 sizeof((*app)->am_typ));
916 heap_close(rel, NoLock);
917 return gettype(type);
919 elog(ERROR, "unrecognized type \"%s\"", type);
920 /* not reached, here to make compiler happy */
925 * boot_get_type_io_data
927 * Obtain type I/O information at bootstrap time. This intentionally has
928 * almost the same API as lsyscache.c's get_type_io_data, except that
929 * we only support obtaining the typinput and typoutput routines, not
930 * the binary I/O routines. It is exported so that array_in and array_out
931 * can be made to work during early bootstrap.
935 boot_get_type_io_data(Oid typid,
946 /* We have the boot-time contents of pg_type, so use it */
951 while (*app && (*app)->am_oid != typid)
955 elog(ERROR, "type OID %u not found in Typ list", typid);
957 *typlen = ap->am_typ.typlen;
958 *typbyval = ap->am_typ.typbyval;
959 *typalign = ap->am_typ.typalign;
960 *typdelim = ap->am_typ.typdelim;
962 /* XXX this logic must match getTypeIOParam() */
963 if (OidIsValid(ap->am_typ.typelem))
964 *typioparam = ap->am_typ.typelem;
968 *typinput = ap->am_typ.typinput;
969 *typoutput = ap->am_typ.typoutput;
973 /* We don't have pg_type yet, so use the hard-wired TypInfo array */
976 for (typeindex = 0; typeindex < n_types; typeindex++)
978 if (TypInfo[typeindex].oid == typid)
981 if (typeindex >= n_types)
982 elog(ERROR, "type OID %u not found in TypInfo", typid);
984 *typlen = TypInfo[typeindex].len;
985 *typbyval = TypInfo[typeindex].byval;
986 *typalign = TypInfo[typeindex].align;
987 /* We assume typdelim is ',' for all boot-time types */
990 /* XXX this logic must match getTypeIOParam() */
991 if (OidIsValid(TypInfo[typeindex].elem))
992 *typioparam = TypInfo[typeindex].elem;
996 *typinput = TypInfo[typeindex].inproc;
997 *typoutput = TypInfo[typeindex].outproc;
1004 * Note: bootstrap never sets any per-column ACLs, so we only need
1005 * ATTRIBUTE_FIXED_PART_SIZE space per attribute.
1008 static Form_pg_attribute
1009 AllocateAttribute(void)
1011 Form_pg_attribute attribute = (Form_pg_attribute) malloc(ATTRIBUTE_FIXED_PART_SIZE);
1013 if (!PointerIsValid(attribute))
1014 elog(FATAL, "out of memory");
1015 MemSet(attribute, 0, ATTRIBUTE_FIXED_PART_SIZE);
1022 * XXX arrays of "basetype" are always "_basetype".
1023 * this is an evil hack inherited from rel. 3.1.
1024 * XXX array dimension is thrown away because we
1025 * don't support fixed-dimension arrays. again,
1026 * sickness from 3.1.
1028 * the string passed in must have a '[' character in it
1030 * the string returned is a pointer to static storage and should NOT
1031 * be freed by the CALLER.
1035 MapArrayTypeName(char *s)
1039 static char newStr[NAMEDATALEN]; /* array type names < NAMEDATALEN long */
1041 if (s == NULL || s[0] == '\0')
1046 for (i = 0; i < NAMEDATALEN - 1 && s[i] != '['; i++, j++)
1056 * index_register() -- record an index that has been set up for building
1059 * At bootstrap time, we define a bunch of indexes on system catalogs.
1060 * We postpone actually building the indexes until just before we're
1061 * finished with initialization, however. This is because the indexes
1062 * themselves have catalog entries, and those have to be included in the
1063 * indexes on those catalogs. Doing it in two phases is the simplest
1064 * way of making sure the indexes have the right contents at the end.
1067 index_register(Oid heap,
1069 IndexInfo *indexInfo)
1072 MemoryContext oldcxt;
1075 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1076 * bootstrap time. we'll declare the indexes now, but want to create them
1081 nogc = AllocSetContextCreate(NULL,
1083 ALLOCSET_DEFAULT_MINSIZE,
1084 ALLOCSET_DEFAULT_INITSIZE,
1085 ALLOCSET_DEFAULT_MAXSIZE);
1087 oldcxt = MemoryContextSwitchTo(nogc);
1089 newind = (IndexList *) palloc(sizeof(IndexList));
1090 newind->il_heap = heap;
1091 newind->il_ind = ind;
1092 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1094 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1095 /* expressions will likely be null, but may as well copy it */
1096 newind->il_info->ii_Expressions = (List *)
1097 copyObject(indexInfo->ii_Expressions);
1098 newind->il_info->ii_ExpressionsState = NIL;
1099 /* predicate will likely be null, but may as well copy it */
1100 newind->il_info->ii_Predicate = (List *)
1101 copyObject(indexInfo->ii_Predicate);
1102 newind->il_info->ii_PredicateState = NIL;
1103 /* no exclusion constraints at bootstrap time, so no need to copy */
1104 Assert(indexInfo->ii_ExclusionOps == NULL);
1105 Assert(indexInfo->ii_ExclusionProcs == NULL);
1106 Assert(indexInfo->ii_ExclusionStrats == NULL);
1108 newind->il_next = ILHead;
1111 MemoryContextSwitchTo(oldcxt);
1116 * build_indices -- fill in all the indexes registered earlier
1121 for (; ILHead != NULL; ILHead = ILHead->il_next)
1126 /* need not bother with locks during bootstrap */
1127 heap = heap_open(ILHead->il_heap, NoLock);
1128 ind = index_open(ILHead->il_ind, NoLock);
1130 index_build(heap, ind, ILHead->il_info, false);
1132 index_close(ind, NoLock);
1133 heap_close(heap, NoLock);