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

197 {
198  char *progname = argv[0];
199  int flag;
200  char *userDoption = NULL;
201 
202  /*
203  * Initialize process environment (already done if under postmaster, but
204  * not if standalone).
205  */
206  if (!IsUnderPostmaster)
207  InitStandaloneProcess(argv[0]);
208 
209  /*
210  * process command arguments
211  */
212 
213  /* Set defaults, to be overridden by explicit options below */
214  if (!IsUnderPostmaster)
216 
217  /* Ignore the initial --boot argument, if present */
218  if (argc > 1 && strcmp(argv[1], "--boot") == 0)
219  {
220  argv++;
221  argc--;
222  }
223 
224  /* If no -x argument, we are a CheckerProcess */
226 
227  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:x:X:-:")) != -1)
228  {
229  switch (flag)
230  {
231  case 'B':
232  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
233  break;
234  case 'D':
235  userDoption = pstrdup(optarg);
236  break;
237  case 'd':
238  {
239  /* Turn on debugging for the bootstrap process. */
240  char *debugstr;
241 
242  debugstr = psprintf("debug%s", optarg);
243  SetConfigOption("log_min_messages", debugstr,
245  SetConfigOption("client_min_messages", debugstr,
247  pfree(debugstr);
248  }
249  break;
250  case 'F':
251  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
252  break;
253  case 'k':
255  break;
256  case 'r':
258  break;
259  case 'x':
260  MyAuxProcType = atoi(optarg);
261  break;
262  case 'X':
263  {
264  int WalSegSz = strtoul(optarg, NULL, 0);
265 
266  if (!IsValidWalSegSize(WalSegSz))
267  ereport(ERROR,
268  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
269  errmsg("-X requires a power of two value between 1 MB and 1 GB")));
270  SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL,
272  }
273  break;
274  case 'c':
275  case '-':
276  {
277  char *name,
278  *value;
279 
280  ParseLongOption(optarg, &name, &value);
281  if (!value)
282  {
283  if (flag == '-')
284  ereport(ERROR,
285  (errcode(ERRCODE_SYNTAX_ERROR),
286  errmsg("--%s requires a value",
287  optarg)));
288  else
289  ereport(ERROR,
290  (errcode(ERRCODE_SYNTAX_ERROR),
291  errmsg("-c %s requires a value",
292  optarg)));
293  }
294 
296  free(name);
297  if (value)
298  free(value);
299  break;
300  }
301  default:
302  write_stderr("Try \"%s --help\" for more information.\n",
303  progname);
304  proc_exit(1);
305  break;
306  }
307  }
308 
309  if (argc != optind)
310  {
311  write_stderr("%s: invalid command-line arguments\n", progname);
312  proc_exit(1);
313  }
314 
315  switch (MyAuxProcType)
316  {
317  case StartupProcess:
319  break;
320  case BgWriterProcess:
322  break;
323  case CheckpointerProcess:
325  break;
326  case WalWriterProcess:
328  break;
329  case WalReceiverProcess:
331  break;
332  default:
334  }
335  if (IsUnderPostmaster)
336  init_ps_display(NULL);
337 
338  /* Acquire configuration parameters, unless inherited from postmaster */
339  if (!IsUnderPostmaster)
340  {
341  if (!SelectConfigFiles(userDoption, progname))
342  proc_exit(1);
343  }
344 
345  /*
346  * Validate we have been given a reasonable-looking DataDir and change
347  * into it (if under postmaster, should be done already).
348  */
349  if (!IsUnderPostmaster)
350  {
351  checkDataDir();
352  ChangeToDataDir();
353  }
354 
355  /* If standalone, create lockfile for data directory */
356  if (!IsUnderPostmaster)
357  CreateDataDirLockFile(false);
358 
360  IgnoreSystemIndexes = true;
361 
362  /* Initialize MaxBackends (if under postmaster, was done already) */
363  if (!IsUnderPostmaster)
365 
366  BaseInit();
367 
368  /*
369  * When we are an auxiliary process, we aren't going to do the full
370  * InitPostgres pushups, but there are a couple of things that need to get
371  * lit up even in an auxiliary process.
372  */
373  if (IsUnderPostmaster)
374  {
375  /*
376  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
377  * this was already done by SubPostmasterMain().
378  */
379 #ifndef EXEC_BACKEND
381 #endif
382 
383  /*
384  * Assign the ProcSignalSlot for an auxiliary process. Since it
385  * doesn't have a BackendId, the slot is statically allocated based on
386  * the auxiliary process type (MyAuxProcType). Backends use slots
387  * indexed in the range from 1 to MaxBackends (inclusive), so we use
388  * MaxBackends + AuxProcType + 1 as the index of the slot for an
389  * auxiliary process.
390  *
391  * This will need rethinking if we ever want more than one of a
392  * particular auxiliary process type.
393  */
395 
396  /* finish setting up bufmgr.c */
398 
399  /*
400  * Auxiliary processes don't run transactions, but they may need a
401  * resource owner anyway to manage buffer pins acquired outside
402  * transactions (and, perhaps, other things in future).
403  */
405 
406  /* Initialize backend status information */
408  pgstat_bestart();
409 
410  /* register a before-shutdown callback for LWLock cleanup */
412  }
413 
414  /*
415  * XLOG operations
416  */
418 
419  switch (MyAuxProcType)
420  {
421  case CheckerProcess:
422  /* don't set signals, they're useless here */
423  CheckerModeMain();
424  proc_exit(1); /* should never return */
425 
426  case BootstrapProcess:
427 
428  /*
429  * There was a brief instant during which mode was Normal; this is
430  * okay. We need to be in bootstrap mode during BootStrapXLOG for
431  * the sake of multixact initialization.
432  */
435  BootStrapXLOG();
437  proc_exit(1); /* should never return */
438 
439  case StartupProcess:
440  /* don't set signals, startup process has its own agenda */
442  proc_exit(1); /* should never return */
443 
444  case BgWriterProcess:
445  /* don't set signals, bgwriter has its own agenda */
447  proc_exit(1); /* should never return */
448 
449  case CheckpointerProcess:
450  /* don't set signals, checkpointer has its own agenda */
452  proc_exit(1); /* should never return */
453 
454  case WalWriterProcess:
455  /* don't set signals, walwriter has its own agenda */
456  InitXLOGAccess();
457  WalWriterMain();
458  proc_exit(1); /* should never return */
459 
460  case WalReceiverProcess:
461  /* don't set signals, walreceiver has its own agenda */
462  WalReceiverMain();
463  proc_exit(1); /* should never return */
464 
465  default:
466  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
467  proc_exit(1);
468  }
469 }
void InitAuxiliaryProcess(void)
Definition: proc.c:511
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:94
void WalWriterMain(void)
Definition: walwriter.c:88
BackendType MyBackendType
Definition: miscinit.c:62
char * pstrdup(const char *in)
Definition: mcxt.c:1187
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:165
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10557
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:399
void BootStrapXLOG(void)
Definition: xlog.c:5196
void BaseInit(void)
Definition: postinit.c:548
bool IgnoreSystemIndexes
Definition: miscinit.c:79
void checkDataDir(void)
Definition: miscinit.c:302
static void bootstrap_signals(void)
Definition: bootstrap.c:547
const char * progname
Definition: pg_standby.c:36
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:491
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:1057
int optind
Definition: getopt.c:50
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1273
void InitXLOGAccess(void)
Definition: xlog.c:8342
#define MAXPGPATH
int MaxBackends
Definition: globals.c:136
char OutputFileName[MAXPGPATH]
Definition: globals.c:70
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:7742
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:416
void pgstat_initialize(void)
Definition: pgstat.c:3024
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:570
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:5566
AuxProcType MyAuxProcType
Definition: bootstrap.c:70
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:561
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:821
void pgstat_bestart(void)
Definition: pgstat.c:3066
char * optarg
Definition: getopt.c:52
#define elog(elevel,...)
Definition: elog.h:214
static void CheckerModeMain(void)
Definition: bootstrap.c:478
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2524
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:5344

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

979 {
980  if (Typ != NULL)
981  {
982  /* We have the boot-time contents of pg_type, so use it */
983  struct typmap **app;
984  struct typmap *ap;
985 
986  app = Typ;
987  while (*app && (*app)->am_oid != typid)
988  ++app;
989  ap = *app;
990  if (ap == NULL)
991  elog(ERROR, "type OID %u not found in Typ list", typid);
992 
993  *typlen = ap->am_typ.typlen;
994  *typbyval = ap->am_typ.typbyval;
995  *typalign = ap->am_typ.typalign;
996  *typdelim = ap->am_typ.typdelim;
997 
998  /* XXX this logic must match getTypeIOParam() */
999  if (OidIsValid(ap->am_typ.typelem))
1000  *typioparam = ap->am_typ.typelem;
1001  else
1002  *typioparam = typid;
1003 
1004  *typinput = ap->am_typ.typinput;
1005  *typoutput = ap->am_typ.typoutput;
1006  }
1007  else
1008  {
1009  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
1010  int typeindex;
1011 
1012  for (typeindex = 0; typeindex < n_types; typeindex++)
1013  {
1014  if (TypInfo[typeindex].oid == typid)
1015  break;
1016  }
1017  if (typeindex >= n_types)
1018  elog(ERROR, "type OID %u not found in TypInfo", typid);
1019 
1020  *typlen = TypInfo[typeindex].len;
1021  *typbyval = TypInfo[typeindex].byval;
1022  *typalign = TypInfo[typeindex].align;
1023  /* We assume typdelim is ',' for all boot-time types */
1024  *typdelim = ',';
1025 
1026  /* XXX this logic must match getTypeIOParam() */
1027  if (OidIsValid(TypInfo[typeindex].elem))
1028  *typioparam = TypInfo[typeindex].elem;
1029  else
1030  *typioparam = typid;
1031 
1032  *typinput = TypInfo[typeindex].inproc;
1033  *typoutput = TypInfo[typeindex].outproc;
1034  }
1035 }
int16 len
Definition: bootstrap.c:92
char align
Definition: bootstrap.c:94
Oid inproc
Definition: bootstrap.c:97
#define OidIsValid(objectId)
Definition: c.h:652
char typalign
Definition: pg_type.h:170
#define ERROR
Definition: elog.h:43
Oid elem
Definition: bootstrap.c:91
static struct typmap ** Typ
Definition: bootstrap.c:162
FormData_pg_type am_typ
Definition: bootstrap.c:159
static const int n_types
Definition: bootstrap.c:154
static const struct typinfo TypInfo[]
Definition: bootstrap.c:101
bool byval
Definition: bootstrap.c:93
Oid am_oid
Definition: bootstrap.c:158
#define elog(elevel,...)
Definition: elog.h:214
Oid outproc
Definition: bootstrap.c:98

◆ boot_openrel()

void boot_openrel ( char *  name)

Definition at line 589 of file bootstrap.c.

References AllocateAttribute(), ATTRIBUTE_FIXED_PART_SIZE, attrtypes, closerel(), DEBUG4, elog, i, makeRangeVar(), NAMEDATALEN, NameStr, NoLock, numattr, populate_typ_array(), RelationData::rd_att, RelationGetNumberOfAttributes, table_openrv(), and TupleDescAttr.

590 {
591  int i;
592 
593  if (strlen(relname) >= NAMEDATALEN)
594  relname[NAMEDATALEN - 1] = '\0';
595 
596  /*
597  * pg_type must be filled before any OPEN command is executed, hence we
598  * can now populate the Typ array if we haven't yet.
599  */
600  if (Typ == NULL)
602 
603  if (boot_reldesc != NULL)
604  closerel(NULL);
605 
606  elog(DEBUG4, "open relation %s, attrsize %d",
608 
611  for (i = 0; i < numattr; i++)
612  {
613  if (attrtypes[i] == NULL)
615  memmove((char *) attrtypes[i],
616  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
618 
619  {
621 
622  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
623  i, NameStr(at->attname), at->attlen, at->attnum,
624  at->atttypid);
625  }
626  }
627 }
int numattr
Definition: bootstrap.c:75
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:462
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:72
NameData relname
Definition: pg_class.h:38
void closerel(char *name)
Definition: bootstrap.c:634
#define DEBUG4
Definition: elog.h:22
static void populate_typ_array(void)
Definition: bootstrap.c:875
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
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:162
TupleDesc rd_att
Definition: rel.h:110
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:102
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1045
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:623
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:422
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:74

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

1114 {
1115  for (; ILHead != NULL; ILHead = ILHead->il_next)
1116  {
1117  Relation heap;
1118  Relation ind;
1119 
1120  /* need not bother with locks during bootstrap */
1121  heap = table_open(ILHead->il_heap, NoLock);
1122  ind = index_open(ILHead->il_ind, NoLock);
1123 
1124  index_build(heap, ind, ILHead->il_info, false, false);
1125 
1126  index_close(ind, NoLock);
1127  table_close(heap, NoLock);
1128  }
1129 }
struct _IndexList * il_next
Definition: bootstrap.c:181
Oid il_ind
Definition: bootstrap.c:179
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
static IndexList * ILHead
Definition: bootstrap.c:184
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:180
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2821
Oid il_heap
Definition: bootstrap.c:178
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 634 of file bootstrap.c.

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

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

635 {
636  if (name)
637  {
638  if (boot_reldesc)
639  {
640  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
641  elog(ERROR, "close of %s when %s was expected",
643  }
644  else
645  elog(ERROR, "close of %s before any relation was opened",
646  name);
647  }
648 
649  if (boot_reldesc == NULL)
650  elog(ERROR, "no open relation to close");
651  else
652  {
653  elog(DEBUG4, "close relation %s",
656  boot_reldesc = NULL;
657  }
658 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation boot_reldesc
Definition: bootstrap.c:72
#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:561
#define elog(elevel,...)
Definition: elog.h:214

◆ DefineAttr()

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

Definition at line 671 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, MemSet, NameStr, namestrcpy(), typinfo::oid, OidIsValid, typinfo::storage, and WARNING.

672 {
673  Oid typeoid;
674 
675  if (boot_reldesc != NULL)
676  {
677  elog(WARNING, "no open relations allowed with CREATE command");
678  closerel(NULL);
679  }
680 
681  if (attrtypes[attnum] == NULL)
684 
686  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
687  attrtypes[attnum]->attnum = attnum + 1;
688 
689  typeoid = gettype(type);
690 
691  if (Typ != NULL)
692  {
693  attrtypes[attnum]->atttypid = Ap->am_oid;
694  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
695  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
696  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
697  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
698  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
699  /* if an array type, assume 1-dimensional attribute */
700  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
701  attrtypes[attnum]->attndims = 1;
702  else
703  attrtypes[attnum]->attndims = 0;
704  }
705  else
706  {
707  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
708  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
709  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
710  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
711  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
712  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
713  /* if an array type, assume 1-dimensional attribute */
714  if (TypInfo[typeoid].elem != InvalidOid &&
715  attrtypes[attnum]->attlen < 0)
716  attrtypes[attnum]->attndims = 1;
717  else
718  attrtypes[attnum]->attndims = 0;
719  }
720 
721  /*
722  * If a system catalog column is collation-aware, force it to use C
723  * collation, so that its behavior is independent of the database's
724  * collation. This is essential to allow template0 to be cloned with a
725  * different database collation.
726  */
728  attrtypes[attnum]->attcollation = C_COLLATION_OID;
729 
730  attrtypes[attnum]->attstattarget = -1;
731  attrtypes[attnum]->attcacheoff = -1;
732  attrtypes[attnum]->atttypmod = -1;
733  attrtypes[attnum]->attislocal = true;
734 
735  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
736  {
737  attrtypes[attnum]->attnotnull = true;
738  }
739  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
740  {
741  attrtypes[attnum]->attnotnull = false;
742  }
743  else
744  {
745  Assert(nullness == BOOTCOL_NULL_AUTO);
746 
747  /*
748  * Mark as "not null" if type is fixed-width and prior columns are
749  * likewise fixed-width and not-null. This corresponds to case where
750  * column can be accessed directly via C struct declaration.
751  */
752  if (attrtypes[attnum]->attlen > 0)
753  {
754  int i;
755 
756  /* check earlier attributes */
757  for (i = 0; i < attnum; i++)
758  {
759  if (attrtypes[i]->attlen <= 0 ||
760  !attrtypes[i]->attnotnull)
761  break;
762  }
763  if (i == attnum)
764  attrtypes[attnum]->attnotnull = true;
765  }
766  }
767 }
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
int16 len
Definition: bootstrap.c:92
bool attnotnull
Definition: pg_attribute.h:125
char align
Definition: bootstrap.c:94
void namestrcpy(Name name, const char *str)
Definition: name.c:233
Relation boot_reldesc
Definition: bootstrap.c:72
#define BOOTCOL_NULL_AUTO
Definition: bootstrap.h:26
#define MemSet(start, val, len)
Definition: c.h:950
unsigned int Oid
Definition: postgres_ext.h:31
void closerel(char *name)
Definition: bootstrap.c:634
static struct typmap * Ap
Definition: bootstrap.c:163
#define DEBUG4
Definition: elog.h:22
#define OidIsValid(objectId)
Definition: c.h:652
#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:96
static struct typmap ** Typ
Definition: bootstrap.c:162
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:746
char storage
Definition: bootstrap.c:95
FormData_pg_type am_typ
Definition: bootstrap.c:159
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1045
static const struct typinfo TypInfo[]
Definition: bootstrap.c:101
const char * name
Definition: encode.c:561
bool byval
Definition: bootstrap.c:93
static Oid gettype(char *type)
Definition: bootstrap.c:926
Oid am_oid
Definition: bootstrap.c:158
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:623
Oid oid
Definition: bootstrap.c:90
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:74

◆ index_register()

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

Definition at line 1063 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().

1066 {
1067  IndexList *newind;
1068  MemoryContext oldcxt;
1069 
1070  /*
1071  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1072  * bootstrap time. we'll declare the indexes now, but want to create them
1073  * later.
1074  */
1075 
1076  if (nogc == NULL)
1077  nogc = AllocSetContextCreate(NULL,
1078  "BootstrapNoGC",
1080 
1081  oldcxt = MemoryContextSwitchTo(nogc);
1082 
1083  newind = (IndexList *) palloc(sizeof(IndexList));
1084  newind->il_heap = heap;
1085  newind->il_ind = ind;
1086  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1087 
1088  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1089  /* expressions will likely be null, but may as well copy it */
1090  newind->il_info->ii_Expressions =
1091  copyObject(indexInfo->ii_Expressions);
1092  newind->il_info->ii_ExpressionsState = NIL;
1093  /* predicate will likely be null, but may as well copy it */
1094  newind->il_info->ii_Predicate =
1095  copyObject(indexInfo->ii_Predicate);
1096  newind->il_info->ii_PredicateState = NULL;
1097  /* no exclusion constraints at bootstrap time, so no need to copy */
1098  Assert(indexInfo->ii_ExclusionOps == NULL);
1099  Assert(indexInfo->ii_ExclusionProcs == NULL);
1100  Assert(indexInfo->ii_ExclusionStrats == NULL);
1101 
1102  newind->il_next = ILHead;
1103  ILHead = newind;
1104 
1105  MemoryContextSwitchTo(oldcxt);
1106 }
struct _IndexList * il_next
Definition: bootstrap.c:181
#define NIL
Definition: pg_list.h:65
#define AllocSetContextCreate
Definition: memutils.h:170
Oid il_ind
Definition: bootstrap.c:179
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:184
Oid * ii_ExclusionProcs
Definition: execnodes.h:165
static MemoryContext nogc
Definition: bootstrap.c:168
List * ii_ExpressionsState
Definition: execnodes.h:161
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
IndexInfo * il_info
Definition: bootstrap.c:180
List * ii_Expressions
Definition: execnodes.h:160
#define Assert(condition)
Definition: c.h:746
Oid il_heap
Definition: bootstrap.c:178
Oid * ii_ExclusionOps
Definition: execnodes.h:164
void * palloc(Size size)
Definition: mcxt.c:950
#define copyObject(obj)
Definition: nodes.h:644
uint16 * ii_ExclusionStrats
Definition: execnodes.h:166

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 844 of file bootstrap.c.

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

845 {
846  elog(DEBUG4, "inserting column %d NULL", i);
847  Assert(i >= 0 && i < MAXATTR);
848  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
849  elog(ERROR,
850  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
853  values[i] = PointerGetDatum(NULL);
854  Nulls[i] = true;
855 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:72
#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:746
static Datum values[MAXATTR]
Definition: bootstrap.c:165
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:623
static bool Nulls[MAXATTR]
Definition: bootstrap.c:166

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 778 of file bootstrap.c.

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

779 {
780  HeapTuple tuple;
781  TupleDesc tupDesc;
782  int i;
783 
784  elog(DEBUG4, "inserting row with %d columns", numattr);
785 
786  tupDesc = CreateTupleDesc(numattr, attrtypes);
787  tuple = heap_form_tuple(tupDesc, values, Nulls);
788  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
789 
791  heap_freetuple(tuple);
792  elog(DEBUG4, "row inserted");
793 
794  /*
795  * Reset null markers for next tuple
796  */
797  for (i = 0; i < numattr; i++)
798  Nulls[i] = false;
799 }
int numattr
Definition: bootstrap.c:75
Relation boot_reldesc
Definition: bootstrap.c:72
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:1057
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2384
static Datum values[MAXATTR]
Definition: bootstrap.c:165
#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:166
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:74

◆ InsertOneValue()

void InsertOneValue ( char *  value,
int  i 
)

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

807 {
808  Oid typoid;
809  int16 typlen;
810  bool typbyval;
811  char typalign;
812  char typdelim;
813  Oid typioparam;
814  Oid typinput;
815  Oid typoutput;
816 
817  AssertArg(i >= 0 && i < MAXATTR);
818 
819  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
820 
821  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
822 
823  boot_get_type_io_data(typoid,
824  &typlen, &typbyval, &typalign,
825  &typdelim, &typioparam,
826  &typinput, &typoutput);
827 
828  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
829 
830  /*
831  * We use ereport not elog here so that parameters aren't evaluated unless
832  * the message is going to be printed, which generally it isn't
833  */
834  ereport(DEBUG4,
835  (errmsg_internal("inserted -> %s",
836  OidOutputFunctionCall(typoutput, values[i]))));
837 }
signed short int16
Definition: c.h:362
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:72
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:748
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:908
static Datum values[MAXATTR]
Definition: bootstrap.c:165
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:971

Variable Documentation

◆ attrtypes

Definition at line 74 of file bootstrap.c.

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

◆ boot_reldesc

Relation boot_reldesc

Definition at line 72 of file bootstrap.c.

◆ numattr

int numattr

Definition at line 75 of file bootstrap.c.

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