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 197 of file bootstrap.c.

References ArchiverProcess, B_ARCHIVER, 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, PgArchiverMain(), PGC_INTERNAL, PGC_POSTMASTER, PGC_S_ARGV, PGC_S_OVERRIDE, pgstat_beinit(), 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().

198 {
199  char *progname = argv[0];
200  int flag;
201  char *userDoption = NULL;
202 
203  /*
204  * Initialize process environment (already done if under postmaster, but
205  * not if standalone).
206  */
207  if (!IsUnderPostmaster)
208  InitStandaloneProcess(argv[0]);
209 
210  /*
211  * process command arguments
212  */
213 
214  /* Set defaults, to be overridden by explicit options below */
215  if (!IsUnderPostmaster)
217 
218  /* Ignore the initial --boot argument, if present */
219  if (argc > 1 && strcmp(argv[1], "--boot") == 0)
220  {
221  argv++;
222  argc--;
223  }
224 
225  /* If no -x argument, we are a CheckerProcess */
227 
228  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:x:X:-:")) != -1)
229  {
230  switch (flag)
231  {
232  case 'B':
233  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
234  break;
235  case 'D':
236  userDoption = pstrdup(optarg);
237  break;
238  case 'd':
239  {
240  /* Turn on debugging for the bootstrap process. */
241  char *debugstr;
242 
243  debugstr = psprintf("debug%s", optarg);
244  SetConfigOption("log_min_messages", debugstr,
246  SetConfigOption("client_min_messages", debugstr,
248  pfree(debugstr);
249  }
250  break;
251  case 'F':
252  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
253  break;
254  case 'k':
256  break;
257  case 'r':
259  break;
260  case 'x':
261  MyAuxProcType = atoi(optarg);
262  break;
263  case 'X':
264  {
265  int WalSegSz = strtoul(optarg, NULL, 0);
266 
267  if (!IsValidWalSegSize(WalSegSz))
268  ereport(ERROR,
269  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
270  errmsg("-X requires a power of two value between 1 MB and 1 GB")));
271  SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL,
273  }
274  break;
275  case 'c':
276  case '-':
277  {
278  char *name,
279  *value;
280 
281  ParseLongOption(optarg, &name, &value);
282  if (!value)
283  {
284  if (flag == '-')
285  ereport(ERROR,
286  (errcode(ERRCODE_SYNTAX_ERROR),
287  errmsg("--%s requires a value",
288  optarg)));
289  else
290  ereport(ERROR,
291  (errcode(ERRCODE_SYNTAX_ERROR),
292  errmsg("-c %s requires a value",
293  optarg)));
294  }
295 
297  free(name);
298  if (value)
299  free(value);
300  break;
301  }
302  default:
303  write_stderr("Try \"%s --help\" for more information.\n",
304  progname);
305  proc_exit(1);
306  break;
307  }
308  }
309 
310  if (argc != optind)
311  {
312  write_stderr("%s: invalid command-line arguments\n", progname);
313  proc_exit(1);
314  }
315 
316  switch (MyAuxProcType)
317  {
318  case StartupProcess:
320  break;
321  case ArchiverProcess:
323  break;
324  case BgWriterProcess:
326  break;
327  case CheckpointerProcess:
329  break;
330  case WalWriterProcess:
332  break;
333  case WalReceiverProcess:
335  break;
336  default:
338  }
339  if (IsUnderPostmaster)
340  init_ps_display(NULL);
341 
342  /* Acquire configuration parameters, unless inherited from postmaster */
343  if (!IsUnderPostmaster)
344  {
345  if (!SelectConfigFiles(userDoption, progname))
346  proc_exit(1);
347  }
348 
349  /*
350  * Validate we have been given a reasonable-looking DataDir and change
351  * into it (if under postmaster, should be done already).
352  */
353  if (!IsUnderPostmaster)
354  {
355  checkDataDir();
356  ChangeToDataDir();
357  }
358 
359  /* If standalone, create lockfile for data directory */
360  if (!IsUnderPostmaster)
361  CreateDataDirLockFile(false);
362 
364  IgnoreSystemIndexes = true;
365 
366  /* Initialize MaxBackends (if under postmaster, was done already) */
367  if (!IsUnderPostmaster)
369 
370  BaseInit();
371 
372  /*
373  * When we are an auxiliary process, we aren't going to do the full
374  * InitPostgres pushups, but there are a couple of things that need to get
375  * lit up even in an auxiliary process.
376  */
377  if (IsUnderPostmaster)
378  {
379  /*
380  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
381  * this was already done by SubPostmasterMain().
382  */
383 #ifndef EXEC_BACKEND
385 #endif
386 
387  /*
388  * Assign the ProcSignalSlot for an auxiliary process. Since it
389  * doesn't have a BackendId, the slot is statically allocated based on
390  * the auxiliary process type (MyAuxProcType). Backends use slots
391  * indexed in the range from 1 to MaxBackends (inclusive), so we use
392  * MaxBackends + AuxProcType + 1 as the index of the slot for an
393  * auxiliary process.
394  *
395  * This will need rethinking if we ever want more than one of a
396  * particular auxiliary process type.
397  */
399 
400  /* finish setting up bufmgr.c */
402 
403  /*
404  * Auxiliary processes don't run transactions, but they may need a
405  * resource owner anyway to manage buffer pins acquired outside
406  * transactions (and, perhaps, other things in future).
407  */
409 
410  /* Initialize statistics reporting */
412 
413  /* Initialize backend status information */
414  pgstat_beinit();
415  pgstat_bestart();
416 
417  /* register a before-shutdown callback for LWLock cleanup */
419  }
420 
421  /*
422  * XLOG operations
423  */
425 
426  switch (MyAuxProcType)
427  {
428  case CheckerProcess:
429  /* don't set signals, they're useless here */
430  CheckerModeMain();
431  proc_exit(1); /* should never return */
432 
433  case BootstrapProcess:
434 
435  /*
436  * There was a brief instant during which mode was Normal; this is
437  * okay. We need to be in bootstrap mode during BootStrapXLOG for
438  * the sake of multixact initialization.
439  */
442  BootStrapXLOG();
444  proc_exit(1); /* should never return */
445 
446  case StartupProcess:
448  proc_exit(1);
449 
450  case ArchiverProcess:
451  PgArchiverMain();
452  proc_exit(1);
453 
454  case BgWriterProcess:
456  proc_exit(1);
457 
458  case CheckpointerProcess:
460  proc_exit(1);
461 
462  case WalWriterProcess:
463  InitXLOGAccess();
464  WalWriterMain();
465  proc_exit(1);
466 
467  case WalReceiverProcess:
468  WalReceiverMain();
469  proc_exit(1);
470 
471  default:
472  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
473  proc_exit(1);
474  }
475 }
void InitAuxiliaryProcess(void)
Definition: proc.c:517
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:94
const char * progname
Definition: main.c:46
void WalWriterMain(void)
Definition: walwriter.c:91
static struct @142 value
BackendType MyBackendType
Definition: miscinit.c:62
char * pstrdup(const char *in)
Definition: mcxt.c:1299
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:10943
void StartupProcessMain(void)
Definition: startup.c:207
#define write_stderr(str)
Definition: parallel.c:186
void proc_exit(int code)
Definition: ipc.c:104
int errcode(int sqlerrcode)
Definition: elog.c:698
#define SetProcessingMode(mode)
Definition: miscadmin.h:412
void BootStrapXLOG(void)
Definition: xlog.c:5240
void BaseInit(void)
Definition: postinit.c:537
bool IgnoreSystemIndexes
Definition: miscinit.c:79
void checkDataDir(void)
Definition: miscinit.c:304
void pgstat_bestart(void)
static void bootstrap_signals(void)
Definition: bootstrap.c:553
#define PANIC
Definition: elog.h:50
static void BootstrapModeMain(void)
Definition: bootstrap.c:497
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:1169
int optind
Definition: getopt.c:50
#define ERROR
Definition: elog.h:46
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1275
void InitXLOGAccess(void)
Definition: xlog.c:8478
#define MAXPGPATH
int MaxBackends
Definition: globals.c:139
char OutputFileName[MAXPGPATH]
Definition: globals.c:73
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8050
bool IsUnderPostmaster
Definition: globals.c:112
char * flag(int b)
Definition: test-ctype.c:33
void pgstat_beinit(void)
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
void ChangeToDataDir(void)
Definition: miscinit.c:418
void pgstat_initialize(void)
Definition: pgstat.c:2918
void PgArchiverMain(void)
Definition: pgarch.c:167
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:576
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:5789
AuxProcType MyAuxProcType
Definition: bootstrap.c:71
void CheckpointerMain(void)
Definition: checkpointer.c:183
#define ereport(elevel,...)
Definition: elog.h:157
#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:887
void InitializeMaxBackends(void)
Definition: postinit.c:515
const char * name
Definition: encode.c:515
void BackgroundWriterMain(void)
Definition: bgwriter.c:94
uint32 WalSegSz
Definition: streamutil.c:34
static const char * userDoption
Definition: postgres.c:172
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:161
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:200
int errmsg(const char *fmt,...)
Definition: elog.c:909
char * optarg
Definition: getopt.c:52
#define elog(elevel,...)
Definition: elog.h:232
static void CheckerModeMain(void)
Definition: bootstrap.c:484
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2621
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:54
void init_ps_display(const char *fixed_part)
Definition: ps_status.c:258
void InitializeGUCOptions(void)
Definition: guc.c:5566

◆ 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 996 of file bootstrap.c.

References typinfo::align, typmap::am_oid, typmap::am_typ, typinfo::byval, typinfo::elem, elog, ERROR, typinfo::inproc, typinfo::len, lfirst, n_types, NIL, typinfo::oid, OidIsValid, and typinfo::outproc.

Referenced by get_type_io_data(), and InsertOneValue().

1004 {
1005  if (Typ != NIL)
1006  {
1007  /* We have the boot-time contents of pg_type, so use it */
1008  struct typmap *ap = NULL;
1009  ListCell *lc;
1010 
1011  foreach(lc, Typ)
1012  {
1013  ap = lfirst(lc);
1014  if (ap->am_oid == typid)
1015  break;
1016  }
1017 
1018  if (!ap || ap->am_oid != typid)
1019  elog(ERROR, "type OID %u not found in Typ list", typid);
1020 
1021  *typlen = ap->am_typ.typlen;
1022  *typbyval = ap->am_typ.typbyval;
1023  *typalign = ap->am_typ.typalign;
1024  *typdelim = ap->am_typ.typdelim;
1025 
1026  /* XXX this logic must match getTypeIOParam() */
1027  if (OidIsValid(ap->am_typ.typelem))
1028  *typioparam = ap->am_typ.typelem;
1029  else
1030  *typioparam = typid;
1031 
1032  *typinput = ap->am_typ.typinput;
1033  *typoutput = ap->am_typ.typoutput;
1034  }
1035  else
1036  {
1037  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
1038  int typeindex;
1039 
1040  for (typeindex = 0; typeindex < n_types; typeindex++)
1041  {
1042  if (TypInfo[typeindex].oid == typid)
1043  break;
1044  }
1045  if (typeindex >= n_types)
1046  elog(ERROR, "type OID %u not found in TypInfo", typid);
1047 
1048  *typlen = TypInfo[typeindex].len;
1049  *typbyval = TypInfo[typeindex].byval;
1050  *typalign = TypInfo[typeindex].align;
1051  /* We assume typdelim is ',' for all boot-time types */
1052  *typdelim = ',';
1053 
1054  /* XXX this logic must match getTypeIOParam() */
1055  if (OidIsValid(TypInfo[typeindex].elem))
1056  *typioparam = TypInfo[typeindex].elem;
1057  else
1058  *typioparam = typid;
1059 
1060  *typinput = TypInfo[typeindex].inproc;
1061  *typoutput = TypInfo[typeindex].outproc;
1062  }
1063 }
#define NIL
Definition: pg_list.h:65
int16 len
Definition: bootstrap.c:93
char align
Definition: bootstrap.c:95
static List * Typ
Definition: bootstrap.c:163
Oid inproc
Definition: bootstrap.c:98
#define OidIsValid(objectId)
Definition: c.h:710
char typalign
Definition: pg_type.h:176
#define ERROR
Definition: elog.h:46
Oid elem
Definition: bootstrap.c:92
#define lfirst(lc)
Definition: pg_list.h:169
FormData_pg_type am_typ
Definition: bootstrap.c:160
static const int n_types
Definition: bootstrap.c:155
static const struct typinfo TypInfo[]
Definition: bootstrap.c:102
bool byval
Definition: bootstrap.c:94
Oid am_oid
Definition: bootstrap.c:159
#define elog(elevel,...)
Definition: elog.h:232
Oid outproc
Definition: bootstrap.c:99

◆ boot_openrel()

void boot_openrel ( char *  name)

Definition at line 595 of file bootstrap.c.

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

596 {
597  int i;
598 
599  if (strlen(relname) >= NAMEDATALEN)
600  relname[NAMEDATALEN - 1] = '\0';
601 
602  /*
603  * pg_type must be filled before any OPEN command is executed, hence we
604  * can now populate Typ if we haven't yet.
605  */
606  if (Typ == NIL)
608 
609  if (boot_reldesc != NULL)
610  closerel(NULL);
611 
612  elog(DEBUG4, "open relation %s, attrsize %d",
614 
617  for (i = 0; i < numattr; i++)
618  {
619  if (attrtypes[i] == NULL)
621  memmove((char *) attrtypes[i],
622  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
624 
625  {
627 
628  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
629  i, NameStr(at->attname), at->attlen, at->attnum,
630  at->atttypid);
631  }
632  }
633 }
#define NIL
Definition: pg_list.h:65
static void populate_typ_list(void)
Definition: bootstrap.c:885
int numattr
Definition: bootstrap.c:76
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:475
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:73
static List * Typ
Definition: bootstrap.c:163
NameData relname
Definition: pg_class.h:38
void closerel(char *name)
Definition: bootstrap.c:640
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:203
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:195
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:1073
#define elog(elevel,...)
Definition: elog.h:232
int i
#define NameStr(name)
Definition: c.h:681
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:422
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:75

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

1142 {
1143  for (; ILHead != NULL; ILHead = ILHead->il_next)
1144  {
1145  Relation heap;
1146  Relation ind;
1147 
1148  /* need not bother with locks during bootstrap */
1149  heap = table_open(ILHead->il_heap, NoLock);
1150  ind = index_open(ILHead->il_ind, NoLock);
1151 
1152  index_build(heap, ind, ILHead->il_info, false, false);
1153 
1154  index_close(ind, NoLock);
1155  table_close(heap, NoLock);
1156  }
1157 }
struct _IndexList * il_next
Definition: bootstrap.c:182
Oid il_ind
Definition: bootstrap.c:180
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
static IndexList * ILHead
Definition: bootstrap.c:185
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:181
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2896
Oid il_heap
Definition: bootstrap.c:179
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 640 of file bootstrap.c.

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

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

641 {
642  if (name)
643  {
644  if (boot_reldesc)
645  {
646  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
647  elog(ERROR, "close of %s when %s was expected",
649  }
650  else
651  elog(ERROR, "close of %s before any relation was opened",
652  name);
653  }
654 
655  if (boot_reldesc == NULL)
656  elog(ERROR, "no open relation to close");
657  else
658  {
659  elog(DEBUG4, "close relation %s",
662  boot_reldesc = NULL;
663  }
664 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation boot_reldesc
Definition: bootstrap.c:73
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:46
#define NoLock
Definition: lockdefs.h:34
#define RelationGetRelationName(relation)
Definition: rel.h:503
const char * name
Definition: encode.c:515
#define elog(elevel,...)
Definition: elog.h:232

◆ DefineAttr()

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

Definition at line 677 of file bootstrap.c.

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

678 {
679  Oid typeoid;
680 
681  if (boot_reldesc != NULL)
682  {
683  elog(WARNING, "no open relations allowed with CREATE command");
684  closerel(NULL);
685  }
686 
687  if (attrtypes[attnum] == NULL)
690 
692  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
693  attrtypes[attnum]->attnum = attnum + 1;
694 
695  typeoid = gettype(type);
696 
697  if (Typ != NIL)
698  {
699  attrtypes[attnum]->atttypid = Ap->am_oid;
700  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
701  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
702  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
703  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
704  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
705  /* if an array type, assume 1-dimensional attribute */
706  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
707  attrtypes[attnum]->attndims = 1;
708  else
709  attrtypes[attnum]->attndims = 0;
710  }
711  else
712  {
713  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
714  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
715  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
716  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
717  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
718  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
719  /* if an array type, assume 1-dimensional attribute */
720  if (TypInfo[typeoid].elem != InvalidOid &&
721  attrtypes[attnum]->attlen < 0)
722  attrtypes[attnum]->attndims = 1;
723  else
724  attrtypes[attnum]->attndims = 0;
725  }
726 
727  /*
728  * If a system catalog column is collation-aware, force it to use C
729  * collation, so that its behavior is independent of the database's
730  * collation. This is essential to allow template0 to be cloned with a
731  * different database collation.
732  */
733  if (OidIsValid(attrtypes[attnum]->attcollation))
734  attrtypes[attnum]->attcollation = C_COLLATION_OID;
735 
736  attrtypes[attnum]->attstattarget = -1;
737  attrtypes[attnum]->attcacheoff = -1;
738  attrtypes[attnum]->atttypmod = -1;
739  attrtypes[attnum]->attislocal = true;
741  attrtypes[attnum]->attcompression = GetDefaultToastCompression();
742  else
743  attrtypes[attnum]->attcompression = InvalidCompressionMethod;
744 
745  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
746  {
747  attrtypes[attnum]->attnotnull = true;
748  }
749  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
750  {
751  attrtypes[attnum]->attnotnull = false;
752  }
753  else
754  {
755  Assert(nullness == BOOTCOL_NULL_AUTO);
756 
757  /*
758  * Mark as "not null" if type is fixed-width and prior columns are
759  * likewise fixed-width and not-null. This corresponds to case where
760  * column can be accessed directly via C struct declaration.
761  */
762  if (attrtypes[attnum]->attlen > 0)
763  {
764  int i;
765 
766  /* check earlier attributes */
767  for (i = 0; i < attnum; i++)
768  {
769  if (attrtypes[i]->attlen <= 0 ||
770  !attrtypes[i]->attnotnull)
771  break;
772  }
773  if (i == attnum)
774  attrtypes[attnum]->attnotnull = true;
775  }
776  }
777 }
#define NIL
Definition: pg_list.h:65
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
char attstorage
Definition: pg_attribute.h:120
int16 len
Definition: bootstrap.c:93
bool attnotnull
Definition: pg_attribute.h:129
char align
Definition: bootstrap.c:95
void namestrcpy(Name name, const char *str)
Definition: name.c:233
Relation boot_reldesc
Definition: bootstrap.c:73
#define BOOTCOL_NULL_AUTO
Definition: bootstrap.h:26
#define MemSet(start, val, len)
Definition: c.h:1008
static List * Typ
Definition: bootstrap.c:163
unsigned int Oid
Definition: postgres_ext.h:31
void closerel(char *name)
Definition: bootstrap.c:640
static struct typmap * Ap
Definition: bootstrap.c:164
#define DEBUG4
Definition: elog.h:22
#define OidIsValid(objectId)
Definition: c.h:710
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition: bootstrap.h:28
static char GetDefaultToastCompression(void)
NameData attname
Definition: pg_attribute.h:41
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:195
int16 attlen
Definition: pg_attribute.h:68
#define WARNING
Definition: elog.h:40
Oid collation
Definition: bootstrap.c:97
#define IsStorageCompressible(storage)
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:83
#define Assert(condition)
Definition: c.h:804
char storage
Definition: bootstrap.c:96
FormData_pg_type am_typ
Definition: bootstrap.c:160
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1073
static const struct typinfo TypInfo[]
Definition: bootstrap.c:102
const char * name
Definition: encode.c:515
bool byval
Definition: bootstrap.c:94
#define InvalidCompressionMethod
static Oid gettype(char *type)
Definition: bootstrap.c:925
Oid am_oid
Definition: bootstrap.c:159
#define elog(elevel,...)
Definition: elog.h:232
int i
#define NameStr(name)
Definition: c.h:681
Oid oid
Definition: bootstrap.c:91
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:75

◆ index_register()

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

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

1094 {
1095  IndexList *newind;
1096  MemoryContext oldcxt;
1097 
1098  /*
1099  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1100  * bootstrap time. we'll declare the indexes now, but want to create them
1101  * later.
1102  */
1103 
1104  if (nogc == NULL)
1105  nogc = AllocSetContextCreate(NULL,
1106  "BootstrapNoGC",
1108 
1109  oldcxt = MemoryContextSwitchTo(nogc);
1110 
1111  newind = (IndexList *) palloc(sizeof(IndexList));
1112  newind->il_heap = heap;
1113  newind->il_ind = ind;
1114  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1115 
1116  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1117  /* expressions will likely be null, but may as well copy it */
1118  newind->il_info->ii_Expressions =
1119  copyObject(indexInfo->ii_Expressions);
1120  newind->il_info->ii_ExpressionsState = NIL;
1121  /* predicate will likely be null, but may as well copy it */
1122  newind->il_info->ii_Predicate =
1123  copyObject(indexInfo->ii_Predicate);
1124  newind->il_info->ii_PredicateState = NULL;
1125  /* no exclusion constraints at bootstrap time, so no need to copy */
1126  Assert(indexInfo->ii_ExclusionOps == NULL);
1127  Assert(indexInfo->ii_ExclusionProcs == NULL);
1128  Assert(indexInfo->ii_ExclusionStrats == NULL);
1129 
1130  newind->il_next = ILHead;
1131  ILHead = newind;
1132 
1133  MemoryContextSwitchTo(oldcxt);
1134 }
struct _IndexList * il_next
Definition: bootstrap.c:182
#define NIL
Definition: pg_list.h:65
#define AllocSetContextCreate
Definition: memutils.h:173
Oid il_ind
Definition: bootstrap.c:180
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:185
Oid * ii_ExclusionProcs
Definition: execnodes.h:166
static MemoryContext nogc
Definition: bootstrap.c:169
List * ii_ExpressionsState
Definition: execnodes.h:162
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
IndexInfo * il_info
Definition: bootstrap.c:181
List * ii_Expressions
Definition: execnodes.h:161
#define Assert(condition)
Definition: c.h:804
Oid il_heap
Definition: bootstrap.c:179
Oid * ii_ExclusionOps
Definition: execnodes.h:165
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:655
uint16 * ii_ExclusionStrats
Definition: execnodes.h:167

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 854 of file bootstrap.c.

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

855 {
856  elog(DEBUG4, "inserting column %d NULL", i);
857  Assert(i >= 0 && i < MAXATTR);
858  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
859  elog(ERROR,
860  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
863  values[i] = PointerGetDatum(NULL);
864  Nulls[i] = true;
865 }
#define PointerGetDatum(X)
Definition: postgres.h:600
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:73
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:46
#define RelationGetRelationName(relation)
Definition: rel.h:503
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:110
#define Assert(condition)
Definition: c.h:804
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define elog(elevel,...)
Definition: elog.h:232
int i
#define NameStr(name)
Definition: c.h:681
static bool Nulls[MAXATTR]
Definition: bootstrap.c:167

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 788 of file bootstrap.c.

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

789 {
790  HeapTuple tuple;
791  TupleDesc tupDesc;
792  int i;
793 
794  elog(DEBUG4, "inserting row with %d columns", numattr);
795 
796  tupDesc = CreateTupleDesc(numattr, attrtypes);
797  tuple = heap_form_tuple(tupDesc, values, Nulls);
798  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
799 
801  heap_freetuple(tuple);
802  elog(DEBUG4, "row inserted");
803 
804  /*
805  * Reset null markers for next tuple
806  */
807  for (i = 0; i < numattr; i++)
808  Nulls[i] = false;
809 }
int numattr
Definition: bootstrap.c:76
Relation boot_reldesc
Definition: bootstrap.c:73
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:1169
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2710
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define elog(elevel,...)
Definition: elog.h:232
int i
TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs)
Definition: tupdesc.c:90
static bool Nulls[MAXATTR]
Definition: bootstrap.c:167
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:75

◆ InsertOneValue()

void InsertOneValue ( char *  value,
int  i 
)

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

817 {
818  Oid typoid;
819  int16 typlen;
820  bool typbyval;
821  char typalign;
822  char typdelim;
823  Oid typioparam;
824  Oid typinput;
825  Oid typoutput;
826 
827  AssertArg(i >= 0 && i < MAXATTR);
828 
829  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
830 
831  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
832 
833  boot_get_type_io_data(typoid,
834  &typlen, &typbyval, &typalign,
835  &typdelim, &typioparam,
836  &typinput, &typoutput);
837 
838  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
839 
840  /*
841  * We use ereport not elog here so that parameters aren't evaluated unless
842  * the message is going to be printed, which generally it isn't
843  */
844  ereport(DEBUG4,
845  (errmsg_internal("inserted -> %s",
846  OidOutputFunctionCall(typoutput, values[i]))));
847 }
signed short int16
Definition: c.h:428
static struct @142 value
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:73
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
char typalign
Definition: pg_type.h:176
#define MAXATTR
Definition: bootstrap.h:24
#define AssertArg(condition)
Definition: c.h:806
TupleDesc rd_att
Definition: rel.h:110
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
static Datum values[MAXATTR]
Definition: bootstrap.c:166
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1653
#define elog(elevel,...)
Definition: elog.h:232
int i
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1644
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:996

Variable Documentation

◆ attrtypes

Definition at line 75 of file bootstrap.c.

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

◆ boot_reldesc

Relation boot_reldesc

Definition at line 73 of file bootstrap.c.

◆ numattr

int numattr

Definition at line 76 of file bootstrap.c.

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