PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
bootstrap.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for bootstrap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAXATTR   40
 
#define BOOTCOL_NULL_AUTO   1
 
#define BOOTCOL_NULL_FORCE_NULL   2
 
#define BOOTCOL_NULL_FORCE_NOT_NULL   3
 

Functions

void AuxiliaryProcessMain (int argc, char *argv[]) pg_attribute_noreturn()
 
void err_out (void)
 
void closerel (char *name)
 
void boot_openrel (char *name)
 
void DefineAttr (char *name, char *type, int attnum, int nullness)
 
void InsertOneTuple (Oid objectid)
 
void InsertOneValue (char *value, int i)
 
void InsertOneNull (int i)
 
char * MapArrayTypeName (const char *s)
 
void index_register (Oid heap, Oid ind, IndexInfo *indexInfo)
 
void build_indices (void)
 
void boot_get_type_io_data (Oid typid, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *typinput, Oid *typoutput)
 
int boot_yyparse (void)
 
int boot_yylex (void)
 
void boot_yyerror (const char *str) pg_attribute_noreturn()
 

Variables

Relation boot_reldesc
 
Form_pg_attribute attrtypes [MAXATTR]
 
int numattr
 

Macro Definition Documentation

#define BOOTCOL_NULL_AUTO   1

Definition at line 26 of file bootstrap.h.

Referenced by DefineAttr().

#define BOOTCOL_NULL_FORCE_NOT_NULL   3

Definition at line 28 of file bootstrap.h.

Referenced by DefineAttr().

#define BOOTCOL_NULL_FORCE_NULL   2

Definition at line 27 of file bootstrap.h.

Referenced by DefineAttr().

#define MAXATTR   40

Definition at line 24 of file bootstrap.h.

Referenced by BootstrapModeMain(), InsertOneNull(), and InsertOneValue().

Function Documentation

void AuxiliaryProcessMain ( int  argc,
char *  argv[] 
)

Definition at line 194 of file bootstrap.c.

References Assert, BackgroundWriterMain(), BaseInit(), before_shmem_exit(), BgWriterProcess, bootstrap_data_checksum_version, bootstrap_signals(), BootstrapModeMain(), BootstrapProcess, BootstrapProcessing, BootStrapXLOG(), ChangeToDataDir(), CheckerModeMain(), CheckerProcess, CheckpointerMain(), CheckpointerProcess, CreateDataDirLockFile(), DataDir, elog, ereport, errcode(), errmsg(), ERROR, flag(), free, getopt(), IgnoreSystemIndexes, init_ps_display(), InitAuxiliaryProcess(), InitBufferPoolBackend(), InitializeGUCOptions(), InitializeMaxBackends(), InitStandaloneProcess(), InitXLOGAccess(), IsUnderPostmaster, MaxBackends, MAXPGPATH, MyAuxProcType, name, NormalProcessing, NULL, optarg, optind, OutputFileName, PANIC, ParseLongOption(), pfree(), PG_DATA_CHECKSUM_VERSION, PGC_POSTMASTER, PGC_S_ARGV, pgstat_bestart(), pgstat_initialize(), proc_exit(), ProcSignalInit(), progname, psprintf(), pstrdup(), SelectConfigFiles(), SetConfigOption(), SetProcessingMode, ShutdownAuxiliaryProcess(), StartupProcess, StartupProcessMain(), strlcpy(), userDoption, ValidatePgVersion(), value, WalReceiverMain(), WalReceiverProcess, WalWriterMain(), WalWriterProcess, and write_stderr.

Referenced by main(), and StartChildProcess().

195 {
196  char *progname = argv[0];
197  int flag;
198  char *userDoption = NULL;
199 
200  /*
201  * Initialize process environment (already done if under postmaster, but
202  * not if standalone).
203  */
204  if (!IsUnderPostmaster)
205  InitStandaloneProcess(argv[0]);
206 
207  /*
208  * process command arguments
209  */
210 
211  /* Set defaults, to be overridden by explicit options below */
212  if (!IsUnderPostmaster)
214 
215  /* Ignore the initial --boot argument, if present */
216  if (argc > 1 && strcmp(argv[1], "--boot") == 0)
217  {
218  argv++;
219  argc--;
220  }
221 
222  /* If no -x argument, we are a CheckerProcess */
224 
225  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:x:-:")) != -1)
226  {
227  switch (flag)
228  {
229  case 'B':
230  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
231  break;
232  case 'D':
233  userDoption = pstrdup(optarg);
234  break;
235  case 'd':
236  {
237  /* Turn on debugging for the bootstrap process. */
238  char *debugstr;
239 
240  debugstr = psprintf("debug%s", optarg);
241  SetConfigOption("log_min_messages", debugstr,
243  SetConfigOption("client_min_messages", debugstr,
245  pfree(debugstr);
246  }
247  break;
248  case 'F':
249  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
250  break;
251  case 'k':
253  break;
254  case 'r':
256  break;
257  case 'x':
258  MyAuxProcType = atoi(optarg);
259  break;
260  case 'c':
261  case '-':
262  {
263  char *name,
264  *value;
265 
266  ParseLongOption(optarg, &name, &value);
267  if (!value)
268  {
269  if (flag == '-')
270  ereport(ERROR,
271  (errcode(ERRCODE_SYNTAX_ERROR),
272  errmsg("--%s requires a value",
273  optarg)));
274  else
275  ereport(ERROR,
276  (errcode(ERRCODE_SYNTAX_ERROR),
277  errmsg("-c %s requires a value",
278  optarg)));
279  }
280 
282  free(name);
283  if (value)
284  free(value);
285  break;
286  }
287  default:
288  write_stderr("Try \"%s --help\" for more information.\n",
289  progname);
290  proc_exit(1);
291  break;
292  }
293  }
294 
295  if (argc != optind)
296  {
297  write_stderr("%s: invalid command-line arguments\n", progname);
298  proc_exit(1);
299  }
300 
301  /*
302  * Identify myself via ps
303  */
304  if (IsUnderPostmaster)
305  {
306  const char *statmsg;
307 
308  switch (MyAuxProcType)
309  {
310  case StartupProcess:
311  statmsg = "startup process";
312  break;
313  case BgWriterProcess:
314  statmsg = "writer process";
315  break;
316  case CheckpointerProcess:
317  statmsg = "checkpointer process";
318  break;
319  case WalWriterProcess:
320  statmsg = "wal writer process";
321  break;
322  case WalReceiverProcess:
323  statmsg = "wal receiver process";
324  break;
325  default:
326  statmsg = "??? process";
327  break;
328  }
329  init_ps_display(statmsg, "", "", "");
330  }
331 
332  /* Acquire configuration parameters, unless inherited from postmaster */
333  if (!IsUnderPostmaster)
334  {
335  if (!SelectConfigFiles(userDoption, progname))
336  proc_exit(1);
337  }
338 
339  /* Validate we have been given a reasonable-looking DataDir */
340  Assert(DataDir);
342 
343  /* Change into DataDir (if under postmaster, should be done already) */
344  if (!IsUnderPostmaster)
345  ChangeToDataDir();
346 
347  /* If standalone, create lockfile for data directory */
348  if (!IsUnderPostmaster)
349  CreateDataDirLockFile(false);
350 
352  IgnoreSystemIndexes = true;
353 
354  /* Initialize MaxBackends (if under postmaster, was done already) */
355  if (!IsUnderPostmaster)
357 
358  BaseInit();
359 
360  /*
361  * When we are an auxiliary process, we aren't going to do the full
362  * InitPostgres pushups, but there are a couple of things that need to get
363  * lit up even in an auxiliary process.
364  */
365  if (IsUnderPostmaster)
366  {
367  /*
368  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
369  * this was already done by SubPostmasterMain().
370  */
371 #ifndef EXEC_BACKEND
373 #endif
374 
375  /*
376  * Assign the ProcSignalSlot for an auxiliary process. Since it
377  * doesn't have a BackendId, the slot is statically allocated based on
378  * the auxiliary process type (MyAuxProcType). Backends use slots
379  * indexed in the range from 1 to MaxBackends (inclusive), so we use
380  * MaxBackends + AuxProcType + 1 as the index of the slot for an
381  * auxiliary process.
382  *
383  * This will need rethinking if we ever want more than one of a
384  * particular auxiliary process type.
385  */
387 
388  /* finish setting up bufmgr.c */
390 
391  /* Initialize backend status information */
393  pgstat_bestart();
394 
395  /* register a before-shutdown callback for LWLock cleanup */
397  }
398 
399  /*
400  * XLOG operations
401  */
403 
404  switch (MyAuxProcType)
405  {
406  case CheckerProcess:
407  /* don't set signals, they're useless here */
408  CheckerModeMain();
409  proc_exit(1); /* should never return */
410 
411  case BootstrapProcess:
412 
413  /*
414  * There was a brief instant during which mode was Normal; this is
415  * okay. We need to be in bootstrap mode during BootStrapXLOG for
416  * the sake of multixact initialization.
417  */
420  BootStrapXLOG();
422  proc_exit(1); /* should never return */
423 
424  case StartupProcess:
425  /* don't set signals, startup process has its own agenda */
427  proc_exit(1); /* should never return */
428 
429  case BgWriterProcess:
430  /* don't set signals, bgwriter has its own agenda */
432  proc_exit(1); /* should never return */
433 
434  case CheckpointerProcess:
435  /* don't set signals, checkpointer has its own agenda */
437  proc_exit(1); /* should never return */
438 
439  case WalWriterProcess:
440  /* don't set signals, walwriter has its own agenda */
441  InitXLOGAccess();
442  WalWriterMain();
443  proc_exit(1); /* should never return */
444 
445  case WalReceiverProcess:
446  /* don't set signals, walreceiver has its own agenda */
447  WalReceiverMain();
448  proc_exit(1); /* should never return */
449 
450  default:
451  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
452  proc_exit(1);
453  }
454 }
void InitAuxiliaryProcess(void)
Definition: proc.c:482
void WalWriterMain(void)
Definition: walwriter.c:98
char * pstrdup(const char *in)
Definition: mcxt.c:1077
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:220
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9385
void StartupProcessMain(void)
Definition: startup.c:179
void ValidatePgVersion(const char *path)
Definition: miscinit.c:1358
#define write_stderr(str)
Definition: parallel.c:180
void proc_exit(int code)
Definition: ipc.c:99
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SetProcessingMode(mode)
Definition: miscadmin.h:374
void BootStrapXLOG(void)
Definition: xlog.c:4951
void BaseInit(void)
Definition: postinit.c:517
bool IgnoreSystemIndexes
Definition: miscinit.c:74
static void bootstrap_signals(void)
Definition: bootstrap.c:525
const char * progname
Definition: pg_standby.c:37
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:476
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
void WalReceiverMain(void)
Definition: walreceiver.c:188
void pfree(void *pointer)
Definition: mcxt.c:950
int optind
Definition: getopt.c:51
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1081
void InitXLOGAccess(void)
Definition: xlog.c:8145
#define MAXPGPATH
static struct @121 value
int MaxBackends
Definition: globals.c:127
char OutputFileName[MAXPGPATH]
Definition: globals.c:62
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6683
bool IsUnderPostmaster
Definition: globals.c:101
char * flag(int b)
Definition: test-ctype.c:33
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:320
void ChangeToDataDir(void)
Definition: miscinit.c:116
void pgstat_initialize(void)
Definition: pgstat.c:2745
#define ereport(elevel, rest)
Definition: elog.h:122
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:544
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:4700
AuxProcType MyAuxProcType
Definition: bootstrap.c:68
void CheckpointerMain(void)
Definition: checkpointer.c:193
#define free(a)
Definition: header.h:65
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
void InitializeMaxBackends(void)
Definition: postinit.c:495
const char * name
Definition: encode.c:521
void BackgroundWriterMain(void)
Definition: bgwriter.c:110
static const char * userDoption
Definition: postgres.c:154
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:105
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:196
int errmsg(const char *fmt,...)
Definition: elog.c:797
void pgstat_bestart(void)
Definition: pgstat.c:2785
char * optarg
Definition: getopt.c:53
static void CheckerModeMain(void)
Definition: bootstrap.c:463
char * DataDir
Definition: globals.c:60
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2461
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:49
#define elog
Definition: elog.h:219
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:244
void InitializeGUCOptions(void)
Definition: guc.c:4478
void boot_get_type_io_data ( Oid  typid,
int16 typlen,
bool typbyval,
char *  typalign,
char *  typdelim,
Oid typioparam,
Oid typinput,
Oid typoutput 
)

Definition at line 944 of file bootstrap.c.

References typinfo::align, typmap::am_oid, typmap::am_typ, typinfo::byval, typinfo::elem, elog, ERROR, typinfo::inproc, typinfo::len, n_types, NULL, OidIsValid, typinfo::outproc, and Typ.

Referenced by get_type_io_data(), and InsertOneValue().

952 {
953  if (Typ != NULL)
954  {
955  /* We have the boot-time contents of pg_type, so use it */
956  struct typmap **app;
957  struct typmap *ap;
958 
959  app = Typ;
960  while (*app && (*app)->am_oid != typid)
961  ++app;
962  ap = *app;
963  if (ap == NULL)
964  elog(ERROR, "type OID %u not found in Typ list", typid);
965 
966  *typlen = ap->am_typ.typlen;
967  *typbyval = ap->am_typ.typbyval;
968  *typalign = ap->am_typ.typalign;
969  *typdelim = ap->am_typ.typdelim;
970 
971  /* XXX this logic must match getTypeIOParam() */
972  if (OidIsValid(ap->am_typ.typelem))
973  *typioparam = ap->am_typ.typelem;
974  else
975  *typioparam = typid;
976 
977  *typinput = ap->am_typ.typinput;
978  *typoutput = ap->am_typ.typoutput;
979  }
980  else
981  {
982  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
983  int typeindex;
984 
985  for (typeindex = 0; typeindex < n_types; typeindex++)
986  {
987  if (TypInfo[typeindex].oid == typid)
988  break;
989  }
990  if (typeindex >= n_types)
991  elog(ERROR, "type OID %u not found in TypInfo", typid);
992 
993  *typlen = TypInfo[typeindex].len;
994  *typbyval = TypInfo[typeindex].byval;
995  *typalign = TypInfo[typeindex].align;
996  /* We assume typdelim is ',' for all boot-time types */
997  *typdelim = ',';
998 
999  /* XXX this logic must match getTypeIOParam() */
1000  if (OidIsValid(TypInfo[typeindex].elem))
1001  *typioparam = TypInfo[typeindex].elem;
1002  else
1003  *typioparam = typid;
1004 
1005  *typinput = TypInfo[typeindex].inproc;
1006  *typoutput = TypInfo[typeindex].outproc;
1007  }
1008 }
int16 len
Definition: bootstrap.c:90
char align
Definition: bootstrap.c:92
Oid inproc
Definition: bootstrap.c:95
#define OidIsValid(objectId)
Definition: c.h:538
#define ERROR
Definition: elog.h:43
Oid elem
Definition: bootstrap.c:89
static struct typmap ** Typ
Definition: bootstrap.c:160
#define NULL
Definition: c.h:229
FormData_pg_type am_typ
Definition: bootstrap.c:157
static const int n_types
Definition: bootstrap.c:152
static const struct typinfo TypInfo[]
Definition: bootstrap.c:99
bool byval
Definition: bootstrap.c:91
Oid am_oid
Definition: bootstrap.c:156
Oid outproc
Definition: bootstrap.c:96
#define elog
Definition: elog.h:219
void boot_openrel ( char *  name)

Definition at line 561 of file bootstrap.c.

References ALLOC, AllocateAttribute(), typmap::am_oid, ATTRIBUTE_FIXED_PART_SIZE, attrtypes, closerel(), DEBUG4, elog, ForwardScanDirection, GETSTRUCT, heap_beginscan_catalog(), heap_close, heap_endscan(), heap_getnext(), heap_open(), heap_openrv(), HeapTupleGetOid, i, makeRangeVar(), memmove, NAMEDATALEN, NameStr, NoLock, NULL, numattr, RelationData::rd_att, RelationData::rd_rel, TupleDescAttr, Typ, and TypeRelationId.

562 {
563  int i;
564  struct typmap **app;
565  Relation rel;
566  HeapScanDesc scan;
567  HeapTuple tup;
568 
569  if (strlen(relname) >= NAMEDATALEN)
570  relname[NAMEDATALEN - 1] = '\0';
571 
572  if (Typ == NULL)
573  {
574  /* We can now load the pg_type data */
576  scan = heap_beginscan_catalog(rel, 0, NULL);
577  i = 0;
578  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
579  ++i;
580  heap_endscan(scan);
581  app = Typ = ALLOC(struct typmap *, i + 1);
582  while (i-- > 0)
583  *app++ = ALLOC(struct typmap, 1);
584  *app = NULL;
585  scan = heap_beginscan_catalog(rel, 0, NULL);
586  app = Typ;
587  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
588  {
589  (*app)->am_oid = HeapTupleGetOid(tup);
590  memcpy((char *) &(*app)->am_typ,
591  (char *) GETSTRUCT(tup),
592  sizeof((*app)->am_typ));
593  app++;
594  }
595  heap_endscan(scan);
596  heap_close(rel, NoLock);
597  }
598 
599  if (boot_reldesc != NULL)
600  closerel(NULL);
601 
602  elog(DEBUG4, "open relation %s, attrsize %d",
603  relname, (int) ATTRIBUTE_FIXED_PART_SIZE);
604 
605  boot_reldesc = heap_openrv(makeRangeVar(NULL, relname, -1), NoLock);
606  numattr = boot_reldesc->rd_rel->relnatts;
607  for (i = 0; i < numattr; i++)
608  {
609  if (attrtypes[i] == NULL)
611  memmove((char *) attrtypes[i],
612  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
614 
615  {
617 
618  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
619  i, NameStr(at->attname), at->attlen, at->attnum,
620  at->atttypid);
621  }
622  }
623 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1580
int numattr
Definition: bootstrap.c:73
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
Relation boot_reldesc
Definition: bootstrap.c:70
#define heap_close(r, l)
Definition: heapam.h:97
Form_pg_class rd_rel
Definition: rel.h:114
void closerel(char *name)
Definition: bootstrap.c:630
#define TypeRelationId
Definition: pg_type.h:34
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
#define memmove(d, s, c)
Definition: c.h:1059
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1405
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
static struct typmap ** Typ
Definition: bootstrap.c:160
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1810
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
TupleDesc rd_att
Definition: rel.h:115
Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1318
#define NULL
Definition: c.h:229
#define ALLOC(t, c)
Definition: bootstrap.c:52
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1018
Oid am_oid
Definition: bootstrap.c:156
int i
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:419
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:72
void boot_yyerror ( const char *  str)
int boot_yylex ( void  )
int boot_yyparse ( void  )

Referenced by BootstrapModeMain().

void build_indices ( void  )

Definition at line 1116 of file bootstrap.c.

References heap_close, heap_open(), _IndexList::il_heap, _IndexList::il_ind, _IndexList::il_info, _IndexList::il_next, index_build(), index_close(), index_open(), NoLock, and NULL.

1117 {
1118  for (; ILHead != NULL; ILHead = ILHead->il_next)
1119  {
1120  Relation heap;
1121  Relation ind;
1122 
1123  /* need not bother with locks during bootstrap */
1124  heap = heap_open(ILHead->il_heap, NoLock);
1125  ind = index_open(ILHead->il_ind, NoLock);
1126 
1127  index_build(heap, ind, ILHead->il_info, false, false);
1128 
1129  index_close(ind, NoLock);
1130  heap_close(heap, NoLock);
1131  }
1132 }
struct _IndexList * il_next
Definition: bootstrap.c:179
Oid il_ind
Definition: bootstrap.c:177
static IndexList * ILHead
Definition: bootstrap.c:182
#define heap_close(r, l)
Definition: heapam.h:97
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:178
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isprimary, bool isreindex)
Definition: index.c:2006
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define NULL
Definition: c.h:229
Oid il_heap
Definition: bootstrap.c:176
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:151
void closerel ( char *  name)

Definition at line 630 of file bootstrap.c.

References DEBUG4, elog, ERROR, heap_close, NoLock, NULL, and RelationGetRelationName.

Referenced by boot_openrel(), cleanup(), and DefineAttr().

631 {
632  if (name)
633  {
634  if (boot_reldesc)
635  {
636  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
637  elog(ERROR, "close of %s when %s was expected",
639  }
640  else
641  elog(ERROR, "close of %s before any relation was opened",
642  name);
643  }
644 
645  if (boot_reldesc == NULL)
646  elog(ERROR, "no open relation to close");
647  else
648  {
649  elog(DEBUG4, "close relation %s",
652  boot_reldesc = NULL;
653  }
654 }
Relation boot_reldesc
Definition: bootstrap.c:70
#define heap_close(r, l)
Definition: heapam.h:97
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define RelationGetRelationName(relation)
Definition: rel.h:436
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
#define elog
Definition: elog.h:219
void DefineAttr ( char *  name,
char *  type,
int  attnum,
int  nullness 
)

Definition at line 667 of file bootstrap.c.

References typinfo::align, AllocateAttribute(), typmap::am_oid, typmap::am_typ, Assert, ATTRIBUTE_FIXED_PART_SIZE, attrtypes, BOOTCOL_NULL_AUTO, BOOTCOL_NULL_FORCE_NOT_NULL, BOOTCOL_NULL_FORCE_NULL, typinfo::byval, closerel(), typinfo::collation, DEBUG4, elog, gettype(), i, InvalidOid, typinfo::len, MARKNOTNULL, MemSet, NameStr, namestrcpy(), NULL, typinfo::oid, typinfo::storage, and WARNING.

668 {
669  Oid typeoid;
670 
671  if (boot_reldesc != NULL)
672  {
673  elog(WARNING, "no open relations allowed with CREATE command");
674  closerel(NULL);
675  }
676 
677  if (attrtypes[attnum] == NULL)
678  attrtypes[attnum] = AllocateAttribute();
680 
681  namestrcpy(&attrtypes[attnum]->attname, name);
682  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
683  attrtypes[attnum]->attnum = attnum + 1; /* fillatt */
684 
685  typeoid = gettype(type);
686 
687  if (Typ != NULL)
688  {
689  attrtypes[attnum]->atttypid = Ap->am_oid;
690  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
691  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
692  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
693  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
694  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
695  /* if an array type, assume 1-dimensional attribute */
696  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
697  attrtypes[attnum]->attndims = 1;
698  else
699  attrtypes[attnum]->attndims = 0;
700  }
701  else
702  {
703  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
704  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
705  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
706  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
707  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
708  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
709  /* if an array type, assume 1-dimensional attribute */
710  if (TypInfo[typeoid].elem != InvalidOid &&
711  attrtypes[attnum]->attlen < 0)
712  attrtypes[attnum]->attndims = 1;
713  else
714  attrtypes[attnum]->attndims = 0;
715  }
716 
717  attrtypes[attnum]->attstattarget = -1;
718  attrtypes[attnum]->attcacheoff = -1;
719  attrtypes[attnum]->atttypmod = -1;
720  attrtypes[attnum]->attislocal = true;
721 
722  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
723  {
724  attrtypes[attnum]->attnotnull = true;
725  }
726  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
727  {
728  attrtypes[attnum]->attnotnull = false;
729  }
730  else
731  {
732  Assert(nullness == BOOTCOL_NULL_AUTO);
733 
734  /*
735  * Mark as "not null" if type is fixed-width and prior columns are
736  * too. This corresponds to case where column can be accessed
737  * directly via C struct declaration.
738  *
739  * oidvector and int2vector are also treated as not-nullable, even
740  * though they are no longer fixed-width.
741  */
742 #define MARKNOTNULL(att) \
743  ((att)->attlen > 0 || \
744  (att)->atttypid == OIDVECTOROID || \
745  (att)->atttypid == INT2VECTOROID)
746 
747  if (MARKNOTNULL(attrtypes[attnum]))
748  {
749  int i;
750 
751  /* check earlier attributes */
752  for (i = 0; i < attnum; i++)
753  {
754  if (!attrtypes[i]->attnotnull)
755  break;
756  }
757  if (i == attnum)
758  attrtypes[attnum]->attnotnull = true;
759  }
760  }
761 }
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
int16 len
Definition: bootstrap.c:90
char align
Definition: bootstrap.c:92
Relation boot_reldesc
Definition: bootstrap.c:70
#define BOOTCOL_NULL_AUTO
Definition: bootstrap.h:26
#define MARKNOTNULL(att)
#define MemSet(start, val, len)
Definition: c.h:858
unsigned int Oid
Definition: postgres_ext.h:31
void closerel(char *name)
Definition: bootstrap.c:630
static struct typmap * Ap
Definition: bootstrap.c:161
int namestrcpy(Name name, const char *str)
Definition: name.c:216
#define DEBUG4
Definition: elog.h:22
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition: bootstrap.h:28
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
#define WARNING
Definition: elog.h:40
Oid collation
Definition: bootstrap.c:94
static struct typmap ** Typ
Definition: bootstrap.c:160
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
char storage
Definition: bootstrap.c:93
FormData_pg_type am_typ
Definition: bootstrap.c:157
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1018
static const struct typinfo TypInfo[]
Definition: bootstrap.c:99
const char * name
Definition: encode.c:521
bool byval
Definition: bootstrap.c:91
static Oid gettype(char *type)
Definition: bootstrap.c:878
Oid am_oid
Definition: bootstrap.c:156
int i
#define NameStr(name)
Definition: c.h:499
Oid oid
Definition: bootstrap.c:88
#define elog
Definition: elog.h:219
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:72
void err_out ( void  )
void index_register ( Oid  heap,
Oid  ind,
IndexInfo indexInfo 
)

Definition at line 1066 of file bootstrap.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), Assert, copyObject, IndexInfo::ii_ExclusionOps, IndexInfo::ii_ExclusionProcs, IndexInfo::ii_ExclusionStrats, IndexInfo::ii_Expressions, IndexInfo::ii_ExpressionsState, IndexInfo::ii_Predicate, IndexInfo::ii_PredicateState, _IndexList::il_heap, _IndexList::il_ind, _IndexList::il_info, _IndexList::il_next, ILHead, MemoryContextSwitchTo(), NIL, NULL, and palloc().

Referenced by index_create().

1069 {
1070  IndexList *newind;
1071  MemoryContext oldcxt;
1072 
1073  /*
1074  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1075  * bootstrap time. we'll declare the indexes now, but want to create them
1076  * later.
1077  */
1078 
1079  if (nogc == NULL)
1081  "BootstrapNoGC",
1083 
1084  oldcxt = MemoryContextSwitchTo(nogc);
1085 
1086  newind = (IndexList *) palloc(sizeof(IndexList));
1087  newind->il_heap = heap;
1088  newind->il_ind = ind;
1089  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1090 
1091  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1092  /* expressions will likely be null, but may as well copy it */
1093  newind->il_info->ii_Expressions =
1094  copyObject(indexInfo->ii_Expressions);
1095  newind->il_info->ii_ExpressionsState = NIL;
1096  /* predicate will likely be null, but may as well copy it */
1097  newind->il_info->ii_Predicate =
1098  copyObject(indexInfo->ii_Predicate);
1099  newind->il_info->ii_PredicateState = NULL;
1100  /* no exclusion constraints at bootstrap time, so no need to copy */
1101  Assert(indexInfo->ii_ExclusionOps == NULL);
1102  Assert(indexInfo->ii_ExclusionProcs == NULL);
1103  Assert(indexInfo->ii_ExclusionStrats == NULL);
1104 
1105  newind->il_next = ILHead;
1106  ILHead = newind;
1107 
1108  MemoryContextSwitchTo(oldcxt);
1109 }
struct _IndexList * il_next
Definition: bootstrap.c:179
#define NIL
Definition: pg_list.h:69
Oid il_ind
Definition: bootstrap.c:177
List * ii_Predicate
Definition: execnodes.h:138
ExprState * ii_PredicateState
Definition: execnodes.h:139
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static IndexList * ILHead
Definition: bootstrap.c:182
Oid * ii_ExclusionProcs
Definition: execnodes.h:141
static MemoryContext nogc
Definition: bootstrap.c:166
List * ii_ExpressionsState
Definition: execnodes.h:137
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
IndexInfo * il_info
Definition: bootstrap.c:178
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
#define NULL
Definition: c.h:229
List * ii_Expressions
Definition: execnodes.h:136
#define Assert(condition)
Definition: c.h:676
Oid il_heap
Definition: bootstrap.c:176
Oid * ii_ExclusionOps
Definition: execnodes.h:140
void * palloc(Size size)
Definition: mcxt.c:849
#define copyObject(obj)
Definition: nodes.h:622
uint16 * ii_ExclusionStrats
Definition: execnodes.h:142
void InsertOneNull ( int  i)

Definition at line 842 of file bootstrap.c.

References Assert, DEBUG4, elog, ERROR, i, MAXATTR, NameStr, NULL, PointerGetDatum, RelationData::rd_att, RelationGetRelationName, and TupleDescAttr.

843 {
844  elog(DEBUG4, "inserting column %d NULL", i);
845  Assert(i >= 0 && i < MAXATTR);
846  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
847  elog(ERROR,
848  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
852  Nulls[i] = true;
853 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
Relation boot_reldesc
Definition: bootstrap.c:70
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:436
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:115
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
static Datum values[MAXATTR]
Definition: bootstrap.c:163
int i
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
static bool Nulls[MAXATTR]
Definition: bootstrap.c:164
void InsertOneTuple ( Oid  objectid)

Definition at line 772 of file bootstrap.c.

References attrtypes, CreateTupleDesc(), DEBUG4, elog, heap_form_tuple(), heap_freetuple(), HeapTupleSetOid, i, numattr, pfree(), RelationGetForm, and simple_heap_insert().

773 {
774  HeapTuple tuple;
775  TupleDesc tupDesc;
776  int i;
777 
778  elog(DEBUG4, "inserting row oid %u, %d columns", objectid, numattr);
779 
780  tupDesc = CreateTupleDesc(numattr,
781  RelationGetForm(boot_reldesc)->relhasoids,
782  attrtypes);
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 */
787 
789  heap_freetuple(tuple);
790  elog(DEBUG4, "row inserted");
791 
792  /*
793  * Reset null markers for next tuple
794  */
795  for (i = 0; i < numattr; i++)
796  Nulls[i] = false;
797 }
int numattr
Definition: bootstrap.c:73
#define RelationGetForm(relation)
Definition: rel.h:410
Relation boot_reldesc
Definition: bootstrap.c:70
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
TupleDesc CreateTupleDesc(int natts, bool hasoid, Form_pg_attribute *attrs)
Definition: tupdesc.c:81
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
#define HeapTupleSetOid(tuple, oid)
Definition: htup_details.h:698
void pfree(void *pointer)
Definition: mcxt.c:950
Oid simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2955
static Datum values[MAXATTR]
Definition: bootstrap.c:163
int i
#define elog
Definition: elog.h:219
static bool Nulls[MAXATTR]
Definition: bootstrap.c:164
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:72
void InsertOneValue ( char *  value,
int  i 
)

Definition at line 804 of file bootstrap.c.

References AssertArg, boot_get_type_io_data(), DEBUG4, elog, ereport, errmsg_internal(), i, MAXATTR, OidInputFunctionCall(), OidOutputFunctionCall(), RelationData::rd_att, and TupleDescAttr.

805 {
806  Oid typoid;
807  int16 typlen;
808  bool typbyval;
809  char typalign;
810  char typdelim;
811  Oid typioparam;
812  Oid typinput;
813  Oid typoutput;
814 
815  AssertArg(i >= 0 && i < MAXATTR);
816 
817  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
818 
819  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
820 
821  boot_get_type_io_data(typoid,
822  &typlen, &typbyval, &typalign,
823  &typdelim, &typioparam,
824  &typinput, &typoutput);
825 
826  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
827 
828  /*
829  * We use ereport not elog here so that parameters aren't evaluated unless
830  * the message is going to be printed, which generally it isn't
831  */
832  ereport(DEBUG4,
833  (errmsg_internal("inserted -> %s",
834  OidOutputFunctionCall(typoutput, values[i]))));
835 }
signed short int16
Definition: c.h:255
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
Relation boot_reldesc
Definition: bootstrap.c:70
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
static struct @121 value
#define MAXATTR
Definition: bootstrap.h:24
#define ereport(elevel, rest)
Definition: elog.h:122
#define AssertArg(condition)
Definition: c.h:678
TupleDesc rd_att
Definition: rel.h:115
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
static Datum values[MAXATTR]
Definition: bootstrap.c:163
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1747
int i
#define elog
Definition: elog.h:219
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1738
void boot_get_type_io_data(Oid typid, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *typinput, Oid *typoutput)
Definition: bootstrap.c:944
char* MapArrayTypeName ( const char *  s)

Definition at line 1037 of file bootstrap.c.

References i, NAMEDATALEN, and pstrdup().

1038 {
1039  int i,
1040  j;
1041  char newStr[NAMEDATALEN];
1042 
1043  newStr[0] = '_';
1044  j = 1;
1045  for (i = 0; i < NAMEDATALEN - 2 && s[i] != '['; i++, j++)
1046  newStr[j] = s[i];
1047 
1048  newStr[j] = '\0';
1049 
1050  return pstrdup(newStr);
1051 }
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define NAMEDATALEN
int i

Variable Documentation

Definition at line 72 of file bootstrap.c.

Referenced by boot_openrel(), BootstrapModeMain(), DefineAttr(), and InsertOneTuple().

Relation boot_reldesc

Definition at line 70 of file bootstrap.c.

int numattr

Definition at line 73 of file bootstrap.c.

Referenced by boot_openrel(), InsertOneTuple(), and tsvector_update_trigger().