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_INVALID, 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, MyBackendType, 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_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  switch (MyAuxProcType)
318  {
319  case StartupProcess:
321  break;
322  case BgWriterProcess:
324  break;
325  case CheckpointerProcess:
327  break;
328  case WalWriterProcess:
330  break;
331  case WalReceiverProcess:
333  break;
334  default:
336  }
337  if (IsUnderPostmaster)
338  init_ps_display(NULL);
339 
340  /* Acquire configuration parameters, unless inherited from postmaster */
341  if (!IsUnderPostmaster)
342  {
343  if (!SelectConfigFiles(userDoption, progname))
344  proc_exit(1);
345  }
346 
347  /*
348  * Validate we have been given a reasonable-looking DataDir and change
349  * into it (if under postmaster, should be done already).
350  */
351  if (!IsUnderPostmaster)
352  {
353  checkDataDir();
354  ChangeToDataDir();
355  }
356 
357  /* If standalone, create lockfile for data directory */
358  if (!IsUnderPostmaster)
359  CreateDataDirLockFile(false);
360 
362  IgnoreSystemIndexes = true;
363 
364  /* Initialize MaxBackends (if under postmaster, was done already) */
365  if (!IsUnderPostmaster)
367 
368  BaseInit();
369 
370  /*
371  * When we are an auxiliary process, we aren't going to do the full
372  * InitPostgres pushups, but there are a couple of things that need to get
373  * lit up even in an auxiliary process.
374  */
375  if (IsUnderPostmaster)
376  {
377  /*
378  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
379  * this was already done by SubPostmasterMain().
380  */
381 #ifndef EXEC_BACKEND
383 #endif
384 
385  /*
386  * Assign the ProcSignalSlot for an auxiliary process. Since it
387  * doesn't have a BackendId, the slot is statically allocated based on
388  * the auxiliary process type (MyAuxProcType). Backends use slots
389  * indexed in the range from 1 to MaxBackends (inclusive), so we use
390  * MaxBackends + AuxProcType + 1 as the index of the slot for an
391  * auxiliary process.
392  *
393  * This will need rethinking if we ever want more than one of a
394  * particular auxiliary process type.
395  */
397 
398  /* finish setting up bufmgr.c */
400 
401  /*
402  * Auxiliary processes don't run transactions, but they may need a
403  * resource owner anyway to manage buffer pins acquired outside
404  * transactions (and, perhaps, other things in future).
405  */
407 
408  /* Initialize backend status information */
410  pgstat_bestart();
411 
412  /* register a before-shutdown callback for LWLock cleanup */
414  }
415 
416  /*
417  * XLOG operations
418  */
420 
421  switch (MyAuxProcType)
422  {
423  case CheckerProcess:
424  /* don't set signals, they're useless here */
425  CheckerModeMain();
426  proc_exit(1); /* should never return */
427 
428  case BootstrapProcess:
429 
430  /*
431  * There was a brief instant during which mode was Normal; this is
432  * okay. We need to be in bootstrap mode during BootStrapXLOG for
433  * the sake of multixact initialization.
434  */
437  BootStrapXLOG();
439  proc_exit(1); /* should never return */
440 
441  case StartupProcess:
442  /* don't set signals, startup process has its own agenda */
444  proc_exit(1); /* should never return */
445 
446  case BgWriterProcess:
447  /* don't set signals, bgwriter has its own agenda */
449  proc_exit(1); /* should never return */
450 
451  case CheckpointerProcess:
452  /* don't set signals, checkpointer has its own agenda */
454  proc_exit(1); /* should never return */
455 
456  case WalWriterProcess:
457  /* don't set signals, walwriter has its own agenda */
458  InitXLOGAccess();
459  WalWriterMain();
460  proc_exit(1); /* should never return */
461 
462  case WalReceiverProcess:
463  /* don't set signals, walreceiver has its own agenda */
464  WalReceiverMain();
465  proc_exit(1); /* should never return */
466 
467  default:
468  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
469  proc_exit(1);
470  }
471 }
void InitAuxiliaryProcess(void)
Definition: proc.c:515
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
void WalWriterMain(void)
Definition: walwriter.c:88
BackendType MyBackendType
Definition: miscinit.c:60
char * pstrdup(const char *in)
Definition: mcxt.c:1186
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:145
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10521
void StartupProcessMain(void)
Definition: startup.c:170
#define write_stderr(str)
Definition: parallel.c:186
void proc_exit(int code)
Definition: ipc.c:104
int errcode(int sqlerrcode)
Definition: elog.c:610
#define SetProcessingMode(mode)
Definition: miscadmin.h:398
void BootStrapXLOG(void)
Definition: xlog.c:5193
void BaseInit(void)
Definition: postinit.c:548
bool IgnoreSystemIndexes
Definition: miscinit.c:77
void checkDataDir(void)
Definition: miscinit.c:274
static void bootstrap_signals(void)
Definition: bootstrap.c:549
const char * progname
Definition: pg_standby.c:36
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:493
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:71
void WalReceiverMain(void)
Definition: walreceiver.c:178
void pfree(void *pointer)
Definition: mcxt.c:1056
int optind
Definition: getopt.c:50
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1245
void InitXLOGAccess(void)
Definition: xlog.c:8335
#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:7706
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:388
void pgstat_initialize(void)
Definition: pgstat.c:2885
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:572
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:5558
AuxProcType MyAuxProcType
Definition: bootstrap.c:72
void CheckpointerMain(void)
Definition: checkpointer.c:183
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
#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:858
void InitializeMaxBackends(void)
Definition: postinit.c:526
const char * name
Definition: encode.c:555
void BackgroundWriterMain(void)
Definition: bgwriter.c:94
int WalSegSz
Definition: pg_standby.c:38
static const char * userDoption
Definition: postgres.c:157
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:151
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:200
int errmsg(const char *fmt,...)
Definition: elog.c:824
void pgstat_bestart(void)
Definition: pgstat.c:2927
char * optarg
Definition: getopt.c:52
#define elog(elevel,...)
Definition: elog.h:214
static void CheckerModeMain(void)
Definition: bootstrap.c:480
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2489
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:53
void init_ps_display(const char *fixed_part)
Definition: ps_status.c:258
void InitializeGUCOptions(void)
Definition: guc.c:5336

◆ 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 977 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().

985 {
986  if (Typ != NULL)
987  {
988  /* We have the boot-time contents of pg_type, so use it */
989  struct typmap **app;
990  struct typmap *ap;
991 
992  app = Typ;
993  while (*app && (*app)->am_oid != typid)
994  ++app;
995  ap = *app;
996  if (ap == NULL)
997  elog(ERROR, "type OID %u not found in Typ list", typid);
998 
999  *typlen = ap->am_typ.typlen;
1000  *typbyval = ap->am_typ.typbyval;
1001  *typalign = ap->am_typ.typalign;
1002  *typdelim = ap->am_typ.typdelim;
1003 
1004  /* XXX this logic must match getTypeIOParam() */
1005  if (OidIsValid(ap->am_typ.typelem))
1006  *typioparam = ap->am_typ.typelem;
1007  else
1008  *typioparam = typid;
1009 
1010  *typinput = ap->am_typ.typinput;
1011  *typoutput = ap->am_typ.typoutput;
1012  }
1013  else
1014  {
1015  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
1016  int typeindex;
1017 
1018  for (typeindex = 0; typeindex < n_types; typeindex++)
1019  {
1020  if (TypInfo[typeindex].oid == typid)
1021  break;
1022  }
1023  if (typeindex >= n_types)
1024  elog(ERROR, "type OID %u not found in TypInfo", typid);
1025 
1026  *typlen = TypInfo[typeindex].len;
1027  *typbyval = TypInfo[typeindex].byval;
1028  *typalign = TypInfo[typeindex].align;
1029  /* We assume typdelim is ',' for all boot-time types */
1030  *typdelim = ',';
1031 
1032  /* XXX this logic must match getTypeIOParam() */
1033  if (OidIsValid(TypInfo[typeindex].elem))
1034  *typioparam = TypInfo[typeindex].elem;
1035  else
1036  *typioparam = typid;
1037 
1038  *typinput = TypInfo[typeindex].inproc;
1039  *typoutput = TypInfo[typeindex].outproc;
1040  }
1041 }
int16 len
Definition: bootstrap.c:94
char align
Definition: bootstrap.c:96
Oid inproc
Definition: bootstrap.c:99
#define OidIsValid(objectId)
Definition: c.h:644
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:214
Oid outproc
Definition: bootstrap.c:100

◆ boot_openrel()

void boot_openrel ( char *  name)

Definition at line 589 of file bootstrap.c.

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

590 {
591  int i;
592  struct typmap **app;
593  Relation rel;
594  TableScanDesc scan;
595  HeapTuple tup;
596 
597  if (strlen(relname) >= NAMEDATALEN)
598  relname[NAMEDATALEN - 1] = '\0';
599 
600  if (Typ == NULL)
601  {
602  /* We can now load the pg_type data */
603  rel = table_open(TypeRelationId, NoLock);
604  scan = table_beginscan_catalog(rel, 0, NULL);
605  i = 0;
606  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
607  ++i;
608  table_endscan(scan);
609  app = Typ = ALLOC(struct typmap *, i + 1);
610  while (i-- > 0)
611  *app++ = ALLOC(struct typmap, 1);
612  *app = NULL;
613  scan = table_beginscan_catalog(rel, 0, NULL);
614  app = Typ;
615  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
616  {
617  (*app)->am_oid = ((Form_pg_type) GETSTRUCT(tup))->oid;
618  memcpy((char *) &(*app)->am_typ,
619  (char *) GETSTRUCT(tup),
620  sizeof((*app)->am_typ));
621  app++;
622  }
623  table_endscan(scan);
624  table_close(rel, NoLock);
625  }
626 
627  if (boot_reldesc != NULL)
628  closerel(NULL);
629 
630  elog(DEBUG4, "open relation %s, attrsize %d",
632 
635  for (i = 0; i < numattr; i++)
636  {
637  if (attrtypes[i] == NULL)
639  memmove((char *) attrtypes[i],
640  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
642 
643  {
645 
646  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
647  i, NameStr(at->attname), at->attlen, at->attnum,
648  at->atttypid);
649  }
650  }
651 }
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:462
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
NameData relname
Definition: pg_class.h:38
void closerel(char *name)
Definition: bootstrap.c:658
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1275
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:185
static struct typmap ** Typ
Definition: bootstrap.c:164
TupleDesc rd_att
Definition: rel.h:110
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:1051
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:862
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:615
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 1119 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().

1120 {
1121  for (; ILHead != NULL; ILHead = ILHead->il_next)
1122  {
1123  Relation heap;
1124  Relation ind;
1125 
1126  /* need not bother with locks during bootstrap */
1127  heap = table_open(ILHead->il_heap, NoLock);
1128  ind = index_open(ILHead->il_ind, NoLock);
1129 
1130  index_build(heap, ind, ILHead->il_info, false, false);
1131 
1132  index_close(ind, NoLock);
1133  table_close(heap, NoLock);
1134  }
1135 }
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:2826
Oid il_heap
Definition: bootstrap.c:180
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132

◆ closerel()

void closerel ( char *  name)

Definition at line 658 of file bootstrap.c.

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

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

659 {
660  if (name)
661  {
662  if (boot_reldesc)
663  {
664  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
665  elog(ERROR, "close of %s when %s was expected",
667  }
668  else
669  elog(ERROR, "close of %s before any relation was opened",
670  name);
671  }
672 
673  if (boot_reldesc == NULL)
674  elog(ERROR, "no open relation to close");
675  else
676  {
677  elog(DEBUG4, "close relation %s",
680  boot_reldesc = NULL;
681  }
682 }
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:490
const char * name
Definition: encode.c:555
#define elog(elevel,...)
Definition: elog.h:214

◆ DefineAttr()

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

Definition at line 695 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.

696 {
697  Oid typeoid;
698 
699  if (boot_reldesc != NULL)
700  {
701  elog(WARNING, "no open relations allowed with CREATE command");
702  closerel(NULL);
703  }
704 
705  if (attrtypes[attnum] == NULL)
708 
710  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
711  attrtypes[attnum]->attnum = attnum + 1;
712 
713  typeoid = gettype(type);
714 
715  if (Typ != NULL)
716  {
717  attrtypes[attnum]->atttypid = Ap->am_oid;
718  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
719  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
720  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
721  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
722  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
723  /* if an array type, assume 1-dimensional attribute */
724  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
725  attrtypes[attnum]->attndims = 1;
726  else
727  attrtypes[attnum]->attndims = 0;
728  }
729  else
730  {
731  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
732  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
733  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
734  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
735  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
736  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
737  /* if an array type, assume 1-dimensional attribute */
738  if (TypInfo[typeoid].elem != InvalidOid &&
739  attrtypes[attnum]->attlen < 0)
740  attrtypes[attnum]->attndims = 1;
741  else
742  attrtypes[attnum]->attndims = 0;
743  }
744 
745  /*
746  * If a system catalog column is collation-aware, force it to use C
747  * collation, so that its behavior is independent of the database's
748  * collation. This is essential to allow template0 to be cloned with a
749  * different database collation.
750  */
752  attrtypes[attnum]->attcollation = C_COLLATION_OID;
753 
754  attrtypes[attnum]->attstattarget = -1;
755  attrtypes[attnum]->attcacheoff = -1;
756  attrtypes[attnum]->atttypmod = -1;
757  attrtypes[attnum]->attislocal = true;
758 
759  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
760  {
761  attrtypes[attnum]->attnotnull = true;
762  }
763  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
764  {
765  attrtypes[attnum]->attnotnull = false;
766  }
767  else
768  {
769  Assert(nullness == BOOTCOL_NULL_AUTO);
770 
771  /*
772  * Mark as "not null" if type is fixed-width and prior columns are
773  * too. This corresponds to case where column can be accessed
774  * directly via C struct declaration.
775  *
776  * oidvector and int2vector are also treated as not-nullable, even
777  * though they are no longer fixed-width.
778  */
779 #define MARKNOTNULL(att) \
780  ((att)->attlen > 0 || \
781  (att)->atttypid == OIDVECTOROID || \
782  (att)->atttypid == INT2VECTOROID)
783 
785  {
786  int i;
787 
788  /* check earlier attributes */
789  for (i = 0; i < attnum; i++)
790  {
791  if (!attrtypes[i]->attnotnull)
792  break;
793  }
794  if (i == attnum)
795  attrtypes[attnum]->attnotnull = true;
796  }
797  }
798 }
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
int16 len
Definition: bootstrap.c:94
bool attnotnull
Definition: pg_attribute.h:125
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:971
unsigned int Oid
Definition: postgres_ext.h:31
void closerel(char *name)
Definition: bootstrap.c:658
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:644
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition: bootstrap.h:28
NameData attname
Definition: pg_attribute.h:40
Oid attcollation
Definition: pg_attribute.h:157
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:185
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:738
char storage
Definition: bootstrap.c:97
FormData_pg_type am_typ
Definition: bootstrap.c:161
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1051
static const struct typinfo TypInfo[]
Definition: bootstrap.c:103
const char * name
Definition: encode.c:555
bool byval
Definition: bootstrap.c:95
static Oid gettype(char *type)
Definition: bootstrap.c:911
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:615
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 1069 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().

1072 {
1073  IndexList *newind;
1074  MemoryContext oldcxt;
1075 
1076  /*
1077  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1078  * bootstrap time. we'll declare the indexes now, but want to create them
1079  * later.
1080  */
1081 
1082  if (nogc == NULL)
1083  nogc = AllocSetContextCreate(NULL,
1084  "BootstrapNoGC",
1086 
1087  oldcxt = MemoryContextSwitchTo(nogc);
1088 
1089  newind = (IndexList *) palloc(sizeof(IndexList));
1090  newind->il_heap = heap;
1091  newind->il_ind = ind;
1092  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1093 
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 =
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 =
1101  copyObject(indexInfo->ii_Predicate);
1102  newind->il_info->ii_PredicateState = NULL;
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);
1107 
1108  newind->il_next = ILHead;
1109  ILHead = newind;
1110 
1111  MemoryContextSwitchTo(oldcxt);
1112 }
struct _IndexList * il_next
Definition: bootstrap.c:183
#define NIL
Definition: pg_list.h:65
#define AllocSetContextCreate
Definition: memutils.h:170
Oid il_ind
Definition: bootstrap.c:181
List * ii_Predicate
Definition: execnodes.h:163
ExprState * ii_PredicateState
Definition: execnodes.h:164
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static IndexList * ILHead
Definition: bootstrap.c:186
Oid * ii_ExclusionProcs
Definition: execnodes.h:166
static MemoryContext nogc
Definition: bootstrap.c:170
List * ii_ExpressionsState
Definition: execnodes.h:162
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
IndexInfo * il_info
Definition: bootstrap.c:182
List * ii_Expressions
Definition: execnodes.h:161
#define Assert(condition)
Definition: c.h:738
Oid il_heap
Definition: bootstrap.c:180
Oid * ii_ExclusionOps
Definition: execnodes.h:165
void * palloc(Size size)
Definition: mcxt.c:949
#define copyObject(obj)
Definition: nodes.h:645
uint16 * ii_ExclusionStrats
Definition: execnodes.h:167

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 875 of file bootstrap.c.

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

876 {
877  elog(DEBUG4, "inserting column %d NULL", i);
878  Assert(i >= 0 && i < MAXATTR);
879  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
880  elog(ERROR,
881  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
884  values[i] = PointerGetDatum(NULL);
885  Nulls[i] = true;
886 }
#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:490
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:110
#define Assert(condition)
Definition: c.h:738
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:615
static bool Nulls[MAXATTR]
Definition: bootstrap.c:168

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 809 of file bootstrap.c.

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

810 {
811  HeapTuple tuple;
812  TupleDesc tupDesc;
813  int i;
814 
815  elog(DEBUG4, "inserting row with %d columns", numattr);
816 
817  tupDesc = CreateTupleDesc(numattr, attrtypes);
818  tuple = heap_form_tuple(tupDesc, values, Nulls);
819  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
820 
822  heap_freetuple(tuple);
823  elog(DEBUG4, "row inserted");
824 
825  /*
826  * Reset null markers for next tuple
827  */
828  for (i = 0; i < numattr; i++)
829  Nulls[i] = false;
830 }
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:1056
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2355
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:214
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 837 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.

838 {
839  Oid typoid;
840  int16 typlen;
841  bool typbyval;
842  char typalign;
843  char typdelim;
844  Oid typioparam;
845  Oid typinput;
846  Oid typoutput;
847 
848  AssertArg(i >= 0 && i < MAXATTR);
849 
850  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
851 
852  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
853 
854  boot_get_type_io_data(typoid,
855  &typlen, &typbyval, &typalign,
856  &typdelim, &typioparam,
857  &typinput, &typoutput);
858 
859  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
860 
861  /*
862  * We use ereport not elog here so that parameters aren't evaluated unless
863  * the message is going to be printed, which generally it isn't
864  */
865  ereport(DEBUG4,
866  (errmsg_internal("inserted -> %s",
867  OidOutputFunctionCall(typoutput, values[i]))));
868 }
signed short int16
Definition: c.h:354
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
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 AssertArg(condition)
Definition: c.h:740
TupleDesc rd_att
Definition: rel.h:110
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911
static Datum values[MAXATTR]
Definition: bootstrap.c:167
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1657
#define elog(elevel,...)
Definition: elog.h:214
int i
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1648
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:977

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().