PostgreSQL Source Code  git master
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 closerel (char *name)
 
void boot_openrel (char *name)
 
void DefineAttr (char *name, char *type, int attnum, int nullness)
 
void InsertOneTuple (void)
 
void InsertOneValue (char *value, int i)
 
void InsertOneNull (int i)
 
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

◆ BOOTCOL_NULL_AUTO

#define BOOTCOL_NULL_AUTO   1

Definition at line 26 of file bootstrap.h.

Referenced by DefineAttr().

◆ BOOTCOL_NULL_FORCE_NOT_NULL

#define BOOTCOL_NULL_FORCE_NOT_NULL   3

Definition at line 28 of file bootstrap.h.

Referenced by DefineAttr().

◆ BOOTCOL_NULL_FORCE_NULL

#define BOOTCOL_NULL_FORCE_NULL   2

Definition at line 27 of file bootstrap.h.

Referenced by DefineAttr().

◆ MAXATTR

#define MAXATTR   40

Definition at line 24 of file bootstrap.h.

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

Function Documentation

◆ AuxiliaryProcessMain()

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

Definition at line 198 of file bootstrap.c.

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

Referenced by BackendRun(), main(), and StartChildProcess().

199 {
200  char *progname = argv[0];
201  int flag;
202  char *userDoption = NULL;
203 
204  /*
205  * Initialize process environment (already done if under postmaster, but
206  * not if standalone).
207  */
208  if (!IsUnderPostmaster)
209  InitStandaloneProcess(argv[0]);
210 
211  /*
212  * process command arguments
213  */
214 
215  /* Set defaults, to be overridden by explicit options below */
216  if (!IsUnderPostmaster)
218 
219  /* Ignore the initial --boot argument, if present */
220  if (argc > 1 && strcmp(argv[1], "--boot") == 0)
221  {
222  argv++;
223  argc--;
224  }
225 
226  /* If no -x argument, we are a CheckerProcess */
228 
229  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:x:X:-:")) != -1)
230  {
231  switch (flag)
232  {
233  case 'B':
234  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
235  break;
236  case 'D':
237  userDoption = pstrdup(optarg);
238  break;
239  case 'd':
240  {
241  /* Turn on debugging for the bootstrap process. */
242  char *debugstr;
243 
244  debugstr = psprintf("debug%s", optarg);
245  SetConfigOption("log_min_messages", debugstr,
247  SetConfigOption("client_min_messages", debugstr,
249  pfree(debugstr);
250  }
251  break;
252  case 'F':
253  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
254  break;
255  case 'k':
257  break;
258  case 'r':
260  break;
261  case 'x':
262  MyAuxProcType = atoi(optarg);
263  break;
264  case 'X':
265  {
266  int WalSegSz = strtoul(optarg, NULL, 0);
267 
268  if (!IsValidWalSegSize(WalSegSz))
269  ereport(ERROR,
270  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
271  errmsg("-X requires a power of two value between 1 MB and 1 GB")));
272  SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL,
274  }
275  break;
276  case 'c':
277  case '-':
278  {
279  char *name,
280  *value;
281 
282  ParseLongOption(optarg, &name, &value);
283  if (!value)
284  {
285  if (flag == '-')
286  ereport(ERROR,
287  (errcode(ERRCODE_SYNTAX_ERROR),
288  errmsg("--%s requires a value",
289  optarg)));
290  else
291  ereport(ERROR,
292  (errcode(ERRCODE_SYNTAX_ERROR),
293  errmsg("-c %s requires a value",
294  optarg)));
295  }
296 
298  free(name);
299  if (value)
300  free(value);
301  break;
302  }
303  default:
304  write_stderr("Try \"%s --help\" for more information.\n",
305  progname);
306  proc_exit(1);
307  break;
308  }
309  }
310 
311  if (argc != optind)
312  {
313  write_stderr("%s: invalid command-line arguments\n", progname);
314  proc_exit(1);
315  }
316 
317  /*
318  * Identify myself via ps
319  */
320  if (IsUnderPostmaster)
321  {
322  const char *statmsg;
323 
324  switch (MyAuxProcType)
325  {
326  case StartupProcess:
328  break;
329  case BgWriterProcess:
331  break;
332  case CheckpointerProcess:
334  break;
335  case WalWriterProcess:
337  break;
338  case WalReceiverProcess:
340  break;
341  default:
342  statmsg = "??? process";
343  break;
344  }
345  init_ps_display(statmsg, "", "", "");
346  }
347 
348  /* Acquire configuration parameters, unless inherited from postmaster */
349  if (!IsUnderPostmaster)
350  {
351  if (!SelectConfigFiles(userDoption, progname))
352  proc_exit(1);
353  }
354 
355  /*
356  * Validate we have been given a reasonable-looking DataDir and change
357  * into it (if under postmaster, should be done already).
358  */
359  if (!IsUnderPostmaster)
360  {
361  checkDataDir();
362  ChangeToDataDir();
363  }
364 
365  /* If standalone, create lockfile for data directory */
366  if (!IsUnderPostmaster)
367  CreateDataDirLockFile(false);
368 
370  IgnoreSystemIndexes = true;
371 
372  /* Initialize MaxBackends (if under postmaster, was done already) */
373  if (!IsUnderPostmaster)
375 
376  BaseInit();
377 
378  /*
379  * When we are an auxiliary process, we aren't going to do the full
380  * InitPostgres pushups, but there are a couple of things that need to get
381  * lit up even in an auxiliary process.
382  */
383  if (IsUnderPostmaster)
384  {
385  /*
386  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
387  * this was already done by SubPostmasterMain().
388  */
389 #ifndef EXEC_BACKEND
391 #endif
392 
393  /*
394  * Assign the ProcSignalSlot for an auxiliary process. Since it
395  * doesn't have a BackendId, the slot is statically allocated based on
396  * the auxiliary process type (MyAuxProcType). Backends use slots
397  * indexed in the range from 1 to MaxBackends (inclusive), so we use
398  * MaxBackends + AuxProcType + 1 as the index of the slot for an
399  * auxiliary process.
400  *
401  * This will need rethinking if we ever want more than one of a
402  * particular auxiliary process type.
403  */
405 
406  /* finish setting up bufmgr.c */
408 
409  /*
410  * Auxiliary processes don't run transactions, but they may need a
411  * resource owner anyway to manage buffer pins acquired outside
412  * transactions (and, perhaps, other things in future).
413  */
415 
416  /* Initialize backend status information */
418  pgstat_bestart();
419 
420  /* register a before-shutdown callback for LWLock cleanup */
422  }
423 
424  /*
425  * XLOG operations
426  */
428 
429  switch (MyAuxProcType)
430  {
431  case CheckerProcess:
432  /* don't set signals, they're useless here */
433  CheckerModeMain();
434  proc_exit(1); /* should never return */
435 
436  case BootstrapProcess:
437 
438  /*
439  * There was a brief instant during which mode was Normal; this is
440  * okay. We need to be in bootstrap mode during BootStrapXLOG for
441  * the sake of multixact initialization.
442  */
445  BootStrapXLOG();
447  proc_exit(1); /* should never return */
448 
449  case StartupProcess:
450  /* don't set signals, startup process has its own agenda */
452  proc_exit(1); /* should never return */
453 
454  case BgWriterProcess:
455  /* don't set signals, bgwriter has its own agenda */
457  proc_exit(1); /* should never return */
458 
459  case CheckpointerProcess:
460  /* don't set signals, checkpointer has its own agenda */
462  proc_exit(1); /* should never return */
463 
464  case WalWriterProcess:
465  /* don't set signals, walwriter has its own agenda */
466  InitXLOGAccess();
467  WalWriterMain();
468  proc_exit(1); /* should never return */
469 
470  case WalReceiverProcess:
471  /* don't set signals, walreceiver has its own agenda */
472  WalReceiverMain();
473  proc_exit(1); /* should never return */
474 
475  default:
476  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
477  proc_exit(1);
478  }
479 }
void InitAuxiliaryProcess(void)
Definition: proc.c:516
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
void WalWriterMain(void)
Definition: walwriter.c:98
char * pstrdup(const char *in)
Definition: mcxt.c:1161
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4274
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:318
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10278
void StartupProcessMain(void)
Definition: startup.c:173
static struct @144 value
#define write_stderr(str)
Definition: parallel.c:182
void proc_exit(int code)
Definition: ipc.c:104
int errcode(int sqlerrcode)
Definition: elog.c:570
#define SetProcessingMode(mode)
Definition: miscadmin.h:380
void BootStrapXLOG(void)
Definition: xlog.c:5087
void BaseInit(void)
Definition: postinit.c:550
bool IgnoreSystemIndexes
Definition: miscinit.c:77
void checkDataDir(void)
Definition: miscinit.c:99
static void bootstrap_signals(void)
Definition: bootstrap.c:557
const char * progname
Definition: pg_standby.c:37
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:501
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:71
void WalReceiverMain(void)
Definition: walreceiver.c:167
void pfree(void *pointer)
Definition: mcxt.c:1031
int optind
Definition: getopt.c:50
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1177
void InitXLOGAccess(void)
Definition: xlog.c:8145
#define MAXPGPATH
int MaxBackends
Definition: globals.c:135
char OutputFileName[MAXPGPATH]
Definition: globals.c:70
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7487
bool IsUnderPostmaster
Definition: globals.c:109
char * flag(int b)
Definition: test-ctype.c:33
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
void ChangeToDataDir(void)
Definition: miscinit.c:213
void pgstat_initialize(void)
Definition: pgstat.c:2815
#define ereport(elevel, rest)
Definition: elog.h:141
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:580
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:5339
AuxProcType MyAuxProcType
Definition: bootstrap.c:72
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
void CreateAuxProcessResourceOwner(void)
Definition: resowner.c:834
void InitializeMaxBackends(void)
Definition: postinit.c:528
const char * name
Definition: encode.c:521
void BackgroundWriterMain(void)
Definition: bgwriter.c:110
int WalSegSz
Definition: pg_standby.c:39
static const char * userDoption
Definition: postgres.c:161
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:105
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:200
int errmsg(const char *fmt,...)
Definition: elog.c:784
void pgstat_bestart(void)
Definition: pgstat.c:2857
char * optarg
Definition: getopt.c:52
#define elog(elevel,...)
Definition: elog.h:226
static void CheckerModeMain(void)
Definition: bootstrap.c:488
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2469
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:53
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:249
void InitializeGUCOptions(void)
Definition: guc.c:5117

◆ boot_get_type_io_data()

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 985 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, typinfo::oid, OidIsValid, typinfo::outproc, and Typ.

Referenced by get_type_io_data(), and InsertOneValue().

993 {
994  if (Typ != NULL)
995  {
996  /* We have the boot-time contents of pg_type, so use it */
997  struct typmap **app;
998  struct typmap *ap;
999 
1000  app = Typ;
1001  while (*app && (*app)->am_oid != typid)
1002  ++app;
1003  ap = *app;
1004  if (ap == NULL)
1005  elog(ERROR, "type OID %u not found in Typ list", typid);
1006 
1007  *typlen = ap->am_typ.typlen;
1008  *typbyval = ap->am_typ.typbyval;
1009  *typalign = ap->am_typ.typalign;
1010  *typdelim = ap->am_typ.typdelim;
1011 
1012  /* XXX this logic must match getTypeIOParam() */
1013  if (OidIsValid(ap->am_typ.typelem))
1014  *typioparam = ap->am_typ.typelem;
1015  else
1016  *typioparam = typid;
1017 
1018  *typinput = ap->am_typ.typinput;
1019  *typoutput = ap->am_typ.typoutput;
1020  }
1021  else
1022  {
1023  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
1024  int typeindex;
1025 
1026  for (typeindex = 0; typeindex < n_types; typeindex++)
1027  {
1028  if (TypInfo[typeindex].oid == typid)
1029  break;
1030  }
1031  if (typeindex >= n_types)
1032  elog(ERROR, "type OID %u not found in TypInfo", typid);
1033 
1034  *typlen = TypInfo[typeindex].len;
1035  *typbyval = TypInfo[typeindex].byval;
1036  *typalign = TypInfo[typeindex].align;
1037  /* We assume typdelim is ',' for all boot-time types */
1038  *typdelim = ',';
1039 
1040  /* XXX this logic must match getTypeIOParam() */
1041  if (OidIsValid(TypInfo[typeindex].elem))
1042  *typioparam = TypInfo[typeindex].elem;
1043  else
1044  *typioparam = typid;
1045 
1046  *typinput = TypInfo[typeindex].inproc;
1047  *typoutput = TypInfo[typeindex].outproc;
1048  }
1049 }
int16 len
Definition: bootstrap.c:94
char align
Definition: bootstrap.c:96
Oid inproc
Definition: bootstrap.c:99
#define OidIsValid(objectId)
Definition: c.h:638
char typalign
Definition: pg_type.h:170
#define ERROR
Definition: elog.h:43
Oid elem
Definition: bootstrap.c:93
static struct typmap ** Typ
Definition: bootstrap.c:164
FormData_pg_type am_typ
Definition: bootstrap.c:161
static const int n_types
Definition: bootstrap.c:156
static const struct typinfo TypInfo[]
Definition: bootstrap.c:103
bool byval
Definition: bootstrap.c:95
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:226
Oid outproc
Definition: bootstrap.c:100

◆ boot_openrel()

void boot_openrel ( char *  name)

Definition at line 597 of file bootstrap.c.

References ALLOC, AllocateAttribute(), typmap::am_oid, ATTRIBUTE_FIXED_PART_SIZE, attrtypes, closerel(), DEBUG4, elog, ForwardScanDirection, GETSTRUCT, heap_getnext(), i, makeRangeVar(), memmove, NAMEDATALEN, NameStr, NoLock, numattr, typinfo::oid, RelationData::rd_att, RelationGetNumberOfAttributes, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), table_openrv(), TupleDescAttr, and Typ.

598 {
599  int i;
600  struct typmap **app;
601  Relation rel;
602  TableScanDesc scan;
603  HeapTuple tup;
604 
605  if (strlen(relname) >= NAMEDATALEN)
606  relname[NAMEDATALEN - 1] = '\0';
607 
608  if (Typ == NULL)
609  {
610  /* We can now load the pg_type data */
611  rel = table_open(TypeRelationId, NoLock);
612  scan = table_beginscan_catalog(rel, 0, NULL);
613  i = 0;
614  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
615  ++i;
616  table_endscan(scan);
617  app = Typ = ALLOC(struct typmap *, i + 1);
618  while (i-- > 0)
619  *app++ = ALLOC(struct typmap, 1);
620  *app = NULL;
621  scan = table_beginscan_catalog(rel, 0, NULL);
622  app = Typ;
623  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
624  {
625  (*app)->am_oid = ((Form_pg_type) GETSTRUCT(tup))->oid;
626  memcpy((char *) &(*app)->am_typ,
627  (char *) GETSTRUCT(tup),
628  sizeof((*app)->am_typ));
629  app++;
630  }
631  table_endscan(scan);
632  table_close(rel, NoLock);
633  }
634 
635  if (boot_reldesc != NULL)
636  closerel(NULL);
637 
638  elog(DEBUG4, "open relation %s, attrsize %d",
640 
643  for (i = 0; i < numattr; i++)
644  {
645  if (attrtypes[i] == NULL)
647  memmove((char *) attrtypes[i],
648  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
650 
651  {
653 
654  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
655  i, NameStr(at->attname), at->attlen, at->attnum,
656  at->atttypid);
657  }
658  }
659 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:98
int numattr
Definition: bootstrap.c:77
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:422
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
NameData relname
Definition: pg_class.h:35
void closerel(char *name)
Definition: bootstrap.c:666
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1290
#define memmove(d, s, c)
Definition: c.h:1238
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:192
static struct typmap ** Typ
Definition: bootstrap.c:164
TupleDesc rd_att
Definition: rel.h:84
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:68
#define ALLOC(t, c)
Definition: bootstrap.c:56
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1059
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:226
int i
#define NameStr(name)
Definition: c.h:609
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:420
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:76

◆ boot_yyerror()

void boot_yyerror ( const char *  str)

◆ boot_yylex()

int boot_yylex ( void  )

◆ boot_yyparse()

int boot_yyparse ( void  )

Referenced by BootstrapModeMain().

◆ build_indices()

void build_indices ( void  )

Definition at line 1127 of file bootstrap.c.

References _IndexList::il_heap, _IndexList::il_ind, _IndexList::il_info, _IndexList::il_next, index_build(), index_close(), index_open(), NoLock, table_close(), and table_open().

1128 {
1129  for (; ILHead != NULL; ILHead = ILHead->il_next)
1130  {
1131  Relation heap;
1132  Relation ind;
1133 
1134  /* need not bother with locks during bootstrap */
1135  heap = table_open(ILHead->il_heap, NoLock);
1136  ind = index_open(ILHead->il_ind, NoLock);
1137 
1138  index_build(heap, ind, ILHead->il_info, false, false);
1139 
1140  index_close(ind, NoLock);
1141  table_close(heap, NoLock);
1142  }
1143 }
struct _IndexList * il_next
Definition: bootstrap.c:183
Oid il_ind
Definition: bootstrap.c:181
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
static IndexList * ILHead
Definition: bootstrap.c:186
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:182
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2689
Oid il_heap
Definition: bootstrap.c:180
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:152
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:126

◆ closerel()

void closerel ( char *  name)

Definition at line 666 of file bootstrap.c.

References DEBUG4, elog, ERROR, NoLock, RelationGetRelationName, and table_close().

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

667 {
668  if (name)
669  {
670  if (boot_reldesc)
671  {
672  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
673  elog(ERROR, "close of %s when %s was expected",
675  }
676  else
677  elog(ERROR, "close of %s before any relation was opened",
678  name);
679  }
680 
681  if (boot_reldesc == NULL)
682  elog(ERROR, "no open relation to close");
683  else
684  {
685  elog(DEBUG4, "close relation %s",
688  boot_reldesc = NULL;
689  }
690 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
Relation boot_reldesc
Definition: bootstrap.c:74
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define RelationGetRelationName(relation)
Definition: rel.h:450
const char * name
Definition: encode.c:521
#define elog(elevel,...)
Definition: elog.h:226

◆ DefineAttr()

void DefineAttr ( char *  name,
char *  type,
int  attnum,
int  nullness 
)

Definition at line 703 of file bootstrap.c.

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

704 {
705  Oid typeoid;
706 
707  if (boot_reldesc != NULL)
708  {
709  elog(WARNING, "no open relations allowed with CREATE command");
710  closerel(NULL);
711  }
712 
713  if (attrtypes[attnum] == NULL)
716 
718  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
719  attrtypes[attnum]->attnum = attnum + 1;
720 
721  typeoid = gettype(type);
722 
723  if (Typ != NULL)
724  {
725  attrtypes[attnum]->atttypid = Ap->am_oid;
726  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
727  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
728  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
729  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
730  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
731  /* if an array type, assume 1-dimensional attribute */
732  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
733  attrtypes[attnum]->attndims = 1;
734  else
735  attrtypes[attnum]->attndims = 0;
736  }
737  else
738  {
739  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
740  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
741  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
742  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
743  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
744  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
745  /* if an array type, assume 1-dimensional attribute */
746  if (TypInfo[typeoid].elem != InvalidOid &&
747  attrtypes[attnum]->attlen < 0)
748  attrtypes[attnum]->attndims = 1;
749  else
750  attrtypes[attnum]->attndims = 0;
751  }
752 
753  /*
754  * If a system catalog column is collation-aware, force it to use C
755  * collation, so that its behavior is independent of the database's
756  * collation. This is essential to allow template0 to be cloned with a
757  * different database collation.
758  */
760  attrtypes[attnum]->attcollation = C_COLLATION_OID;
761 
762  attrtypes[attnum]->attstattarget = -1;
763  attrtypes[attnum]->attcacheoff = -1;
764  attrtypes[attnum]->atttypmod = -1;
765  attrtypes[attnum]->attislocal = true;
766 
767  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
768  {
769  attrtypes[attnum]->attnotnull = true;
770  }
771  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
772  {
773  attrtypes[attnum]->attnotnull = false;
774  }
775  else
776  {
777  Assert(nullness == BOOTCOL_NULL_AUTO);
778 
779  /*
780  * Mark as "not null" if type is fixed-width and prior columns are
781  * too. This corresponds to case where column can be accessed
782  * directly via C struct declaration.
783  *
784  * oidvector and int2vector are also treated as not-nullable, even
785  * though they are no longer fixed-width.
786  */
787 #define MARKNOTNULL(att) \
788  ((att)->attlen > 0 || \
789  (att)->atttypid == OIDVECTOROID || \
790  (att)->atttypid == INT2VECTOROID)
791 
793  {
794  int i;
795 
796  /* check earlier attributes */
797  for (i = 0; i < attnum; i++)
798  {
799  if (!attrtypes[i]->attnotnull)
800  break;
801  }
802  if (i == attnum)
803  attrtypes[attnum]->attnotnull = true;
804  }
805  }
806 }
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
int16 len
Definition: bootstrap.c:94
bool attnotnull
Definition: pg_attribute.h:132
char align
Definition: bootstrap.c:96
Relation boot_reldesc
Definition: bootstrap.c:74
#define BOOTCOL_NULL_AUTO
Definition: bootstrap.h:26
#define MARKNOTNULL(att)
#define MemSet(start, val, len)
Definition: c.h:955
unsigned int Oid
Definition: postgres_ext.h:31
void closerel(char *name)
Definition: bootstrap.c:666
static struct typmap * Ap
Definition: bootstrap.c:165
int namestrcpy(Name name, const char *str)
Definition: name.c:250
#define DEBUG4
Definition: elog.h:22
#define OidIsValid(objectId)
Definition: c.h:638
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition: bootstrap.h:28
NameData attname
Definition: pg_attribute.h:40
Oid attcollation
Definition: pg_attribute.h:164
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:192
int16 attlen
Definition: pg_attribute.h:64
#define WARNING
Definition: elog.h:40
Oid collation
Definition: bootstrap.c:98
static struct typmap ** Typ
Definition: bootstrap.c:164
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:732
char storage
Definition: bootstrap.c:97
FormData_pg_type am_typ
Definition: bootstrap.c:161
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1059
static const struct typinfo TypInfo[]
Definition: bootstrap.c:103
const char * name
Definition: encode.c:521
bool byval
Definition: bootstrap.c:95
static Oid gettype(char *type)
Definition: bootstrap.c:919
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:226
int i
#define NameStr(name)
Definition: c.h:609
Oid oid
Definition: bootstrap.c:92
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:76

◆ index_register()

void index_register ( Oid  heap,
Oid  ind,
IndexInfo indexInfo 
)

Definition at line 1077 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, and palloc().

Referenced by index_create().

1080 {
1081  IndexList *newind;
1082  MemoryContext oldcxt;
1083 
1084  /*
1085  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1086  * bootstrap time. we'll declare the indexes now, but want to create them
1087  * later.
1088  */
1089 
1090  if (nogc == NULL)
1091  nogc = AllocSetContextCreate(NULL,
1092  "BootstrapNoGC",
1094 
1095  oldcxt = MemoryContextSwitchTo(nogc);
1096 
1097  newind = (IndexList *) palloc(sizeof(IndexList));
1098  newind->il_heap = heap;
1099  newind->il_ind = ind;
1100  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1101 
1102  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1103  /* expressions will likely be null, but may as well copy it */
1104  newind->il_info->ii_Expressions =
1105  copyObject(indexInfo->ii_Expressions);
1106  newind->il_info->ii_ExpressionsState = NIL;
1107  /* predicate will likely be null, but may as well copy it */
1108  newind->il_info->ii_Predicate =
1109  copyObject(indexInfo->ii_Predicate);
1110  newind->il_info->ii_PredicateState = NULL;
1111  /* no exclusion constraints at bootstrap time, so no need to copy */
1112  Assert(indexInfo->ii_ExclusionOps == NULL);
1113  Assert(indexInfo->ii_ExclusionProcs == NULL);
1114  Assert(indexInfo->ii_ExclusionStrats == NULL);
1115 
1116  newind->il_next = ILHead;
1117  ILHead = newind;
1118 
1119  MemoryContextSwitchTo(oldcxt);
1120 }
struct _IndexList * il_next
Definition: bootstrap.c:183
#define NIL
Definition: pg_list.h:65
#define AllocSetContextCreate
Definition: memutils.h:169
Oid il_ind
Definition: bootstrap.c:181
List * ii_Predicate
Definition: execnodes.h:162
ExprState * ii_PredicateState
Definition: execnodes.h:163
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static IndexList * ILHead
Definition: bootstrap.c:186
Oid * ii_ExclusionProcs
Definition: execnodes.h:165
static MemoryContext nogc
Definition: bootstrap.c:170
List * ii_ExpressionsState
Definition: execnodes.h:161
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:191
IndexInfo * il_info
Definition: bootstrap.c:182
List * ii_Expressions
Definition: execnodes.h:160
#define Assert(condition)
Definition: c.h:732
Oid il_heap
Definition: bootstrap.c:180
Oid * ii_ExclusionOps
Definition: execnodes.h:164
void * palloc(Size size)
Definition: mcxt.c:924
#define copyObject(obj)
Definition: nodes.h:640
uint16 * ii_ExclusionStrats
Definition: execnodes.h:166

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 883 of file bootstrap.c.

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

884 {
885  elog(DEBUG4, "inserting column %d NULL", i);
886  Assert(i >= 0 && i < MAXATTR);
887  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
888  elog(ERROR,
889  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
892  values[i] = PointerGetDatum(NULL);
893  Nulls[i] = true;
894 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:450
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:84
#define Assert(condition)
Definition: c.h:732
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:226
int i
#define NameStr(name)
Definition: c.h:609
static bool Nulls[MAXATTR]
Definition: bootstrap.c:168

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 817 of file bootstrap.c.

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

818 {
819  HeapTuple tuple;
820  TupleDesc tupDesc;
821  int i;
822 
823  elog(DEBUG4, "inserting row with %d columns", numattr);
824 
825  tupDesc = CreateTupleDesc(numattr, attrtypes);
826  tuple = heap_form_tuple(tupDesc, values, Nulls);
827  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
828 
830  heap_freetuple(tuple);
831  elog(DEBUG4, "row inserted");
832 
833  /*
834  * Reset null markers for next tuple
835  */
836  for (i = 0; i < numattr; i++)
837  Nulls[i] = false;
838 }
int numattr
Definition: bootstrap.c:77
Relation boot_reldesc
Definition: bootstrap.c:74
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define DEBUG4
Definition: elog.h:22
void pfree(void *pointer)
Definition: mcxt.c:1031
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2384
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:226
int i
TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs)
Definition: tupdesc.c:89
static bool Nulls[MAXATTR]
Definition: bootstrap.c:168
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:76

◆ InsertOneValue()

void InsertOneValue ( char *  value,
int  i 
)

Definition at line 845 of file bootstrap.c.

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

846 {
847  Oid typoid;
848  int16 typlen;
849  bool typbyval;
850  char typalign;
851  char typdelim;
852  Oid typioparam;
853  Oid typinput;
854  Oid typoutput;
855 
856  AssertArg(i >= 0 && i < MAXATTR);
857 
858  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
859 
860  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
861 
862  boot_get_type_io_data(typoid,
863  &typlen, &typbyval, &typalign,
864  &typdelim, &typioparam,
865  &typinput, &typoutput);
866 
867  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
868 
869  /*
870  * We use ereport not elog here so that parameters aren't evaluated unless
871  * the message is going to be printed, which generally it isn't
872  */
873  ereport(DEBUG4,
874  (errmsg_internal("inserted -> %s",
875  OidOutputFunctionCall(typoutput, values[i]))));
876 }
signed short int16
Definition: c.h:345
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
static struct @144 value
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
char typalign
Definition: pg_type.h:170
#define MAXATTR
Definition: bootstrap.h:24
#define ereport(elevel, rest)
Definition: elog.h:141
#define AssertArg(condition)
Definition: c.h:734
TupleDesc rd_att
Definition: rel.h:84
int errmsg_internal(const char *fmt,...)
Definition: elog.c:814
static Datum values[MAXATTR]
Definition: bootstrap.c:167
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1655
#define elog(elevel,...)
Definition: elog.h:226
int i
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1646
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:985

Variable Documentation

◆ attrtypes

Definition at line 76 of file bootstrap.c.

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

◆ boot_reldesc

Relation boot_reldesc

Definition at line 74 of file bootstrap.c.

◆ numattr

int numattr

Definition at line 77 of file bootstrap.c.

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