PostgreSQL Source Code  git master
bootstrap.c File Reference
#include "postgres.h"
#include <unistd.h>
#include <signal.h>
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "access/toast_compression.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "bootstrap/bootstrap.h"
#include "catalog/index.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
#include "common/link-canary.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "pg_getopt.h"
#include "pgstat.h"
#include "postmaster/bgwriter.h"
#include "postmaster/startup.h"
#include "postmaster/walwriter.h"
#include "replication/walreceiver.h"
#include "storage/bufmgr.h"
#include "storage/bufpage.h"
#include "storage/condition_variable.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/rel.h"
#include "utils/relmapper.h"
Include dependency graph for bootstrap.c:

Go to the source code of this file.

Data Structures

struct  typinfo
 
struct  typmap
 
struct  _IndexList
 

Typedefs

typedef struct _IndexList IndexList
 

Functions

static void CheckerModeMain (void)
 
static void BootstrapModeMain (void)
 
static void bootstrap_signals (void)
 
static void ShutdownAuxiliaryProcess (int code, Datum arg)
 
static Form_pg_attribute AllocateAttribute (void)
 
static void populate_typ_list (void)
 
static Oid gettype (char *type)
 
static void cleanup (void)
 
void AuxiliaryProcessMain (int argc, char *argv[])
 
void boot_openrel (char *relname)
 
void closerel (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 boot_get_type_io_data (Oid typid, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *typinput, Oid *typoutput)
 
void index_register (Oid heap, Oid ind, IndexInfo *indexInfo)
 
void build_indices (void)
 

Variables

uint32 bootstrap_data_checksum_version = 0
 
AuxProcType MyAuxProcType = NotAnAuxProcess
 
Relation boot_reldesc
 
Form_pg_attribute attrtypes [MAXATTR]
 
int numattr
 
static const struct typinfo TypInfo []
 
static const int n_types = sizeof(TypInfo) / sizeof(struct typinfo)
 
static ListTyp = NIL
 
static struct typmapAp = NULL
 
static Datum values [MAXATTR]
 
static bool Nulls [MAXATTR]
 
static MemoryContext nogc = NULL
 
static IndexListILHead = NULL
 

Typedef Documentation

◆ IndexList

typedef struct _IndexList IndexList

Function Documentation

◆ AllocateAttribute()

static Form_pg_attribute AllocateAttribute ( void  )
static

Definition at line 1068 of file bootstrap.c.

References ATTRIBUTE_FIXED_PART_SIZE, MemoryContextAllocZero(), and TopMemoryContext.

Referenced by boot_openrel(), and DefineAttr().

1069 {
1070  return (Form_pg_attribute)
1072 }
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:199
MemoryContext TopMemoryContext
Definition: mcxt.c:48
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906

◆ 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 
422 
423  switch (MyAuxProcType)
424  {
425  case CheckerProcess:
426  /* don't set signals, they're useless here */
427  CheckerModeMain();
428  proc_exit(1); /* should never return */
429 
430  case BootstrapProcess:
431 
432  /*
433  * There was a brief instant during which mode was Normal; this is
434  * okay. We need to be in bootstrap mode during BootStrapXLOG for
435  * the sake of multixact initialization.
436  */
439  BootStrapXLOG();
441  proc_exit(1); /* should never return */
442 
443  case StartupProcess:
445  proc_exit(1);
446 
447  case ArchiverProcess:
448  PgArchiverMain();
449  proc_exit(1);
450 
451  case BgWriterProcess:
453  proc_exit(1);
454 
455  case CheckpointerProcess:
457  proc_exit(1);
458 
459  case WalWriterProcess:
460  InitXLOGAccess();
461  WalWriterMain();
462  proc_exit(1);
463 
464  case WalReceiverProcess:
465  WalReceiverMain();
466  proc_exit(1);
467 
468  default:
469  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
470  proc_exit(1);
471  }
472 }
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
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:10979
void StartupProcessMain(void)
Definition: startup.c:208
#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:5243
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:550
#define PANIC
Definition: elog.h:50
static void BootstrapModeMain(void)
Definition: bootstrap.c:494
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:8477
#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:8086
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:2928
void PgArchiverMain(void)
Definition: pgarch.c:168
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:573
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:5825
AuxProcType MyAuxProcType
Definition: bootstrap.c:71
void CheckpointerMain(void)
Definition: checkpointer.c:180
static struct @143 value
#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:91
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:481
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2615
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:5602

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

999 {
1000  if (Typ != NIL)
1001  {
1002  /* We have the boot-time contents of pg_type, so use it */
1003  struct typmap *ap = NULL;
1004  ListCell *lc;
1005 
1006  foreach(lc, Typ)
1007  {
1008  ap = lfirst(lc);
1009  if (ap->am_oid == typid)
1010  break;
1011  }
1012 
1013  if (!ap || ap->am_oid != typid)
1014  elog(ERROR, "type OID %u not found in Typ list", typid);
1015 
1016  *typlen = ap->am_typ.typlen;
1017  *typbyval = ap->am_typ.typbyval;
1018  *typalign = ap->am_typ.typalign;
1019  *typdelim = ap->am_typ.typdelim;
1020 
1021  /* XXX this logic must match getTypeIOParam() */
1022  if (OidIsValid(ap->am_typ.typelem))
1023  *typioparam = ap->am_typ.typelem;
1024  else
1025  *typioparam = typid;
1026 
1027  *typinput = ap->am_typ.typinput;
1028  *typoutput = ap->am_typ.typoutput;
1029  }
1030  else
1031  {
1032  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
1033  int typeindex;
1034 
1035  for (typeindex = 0; typeindex < n_types; typeindex++)
1036  {
1037  if (TypInfo[typeindex].oid == typid)
1038  break;
1039  }
1040  if (typeindex >= n_types)
1041  elog(ERROR, "type OID %u not found in TypInfo", typid);
1042 
1043  *typlen = TypInfo[typeindex].len;
1044  *typbyval = TypInfo[typeindex].byval;
1045  *typalign = TypInfo[typeindex].align;
1046  /* We assume typdelim is ',' for all boot-time types */
1047  *typdelim = ',';
1048 
1049  /* XXX this logic must match getTypeIOParam() */
1050  if (OidIsValid(TypInfo[typeindex].elem))
1051  *typioparam = TypInfo[typeindex].elem;
1052  else
1053  *typioparam = typid;
1054 
1055  *typinput = TypInfo[typeindex].inproc;
1056  *typoutput = TypInfo[typeindex].outproc;
1057  }
1058 }
#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 *  relname)

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

593 {
594  int i;
595 
596  if (strlen(relname) >= NAMEDATALEN)
597  relname[NAMEDATALEN - 1] = '\0';
598 
599  /*
600  * pg_type must be filled before any OPEN command is executed, hence we
601  * can now populate Typ if we haven't yet.
602  */
603  if (Typ == NIL)
605 
606  if (boot_reldesc != NULL)
607  closerel(NULL);
608 
609  elog(DEBUG4, "open relation %s, attrsize %d",
611 
614  for (i = 0; i < numattr; i++)
615  {
616  if (attrtypes[i] == NULL)
618  memmove((char *) attrtypes[i],
619  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
621 
622  {
624 
625  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
626  i, NameStr(at->attname), at->attlen, at->attnum,
627  at->atttypid);
628  }
629  }
630 }
#define NIL
Definition: pg_list.h:65
static void populate_typ_list(void)
Definition: bootstrap.c:880
int numattr
Definition: bootstrap.c:76
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:483
#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:637
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:199
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:1068
#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

◆ bootstrap_signals()

static void bootstrap_signals ( void  )
static

Definition at line 550 of file bootstrap.c.

References Assert, IsUnderPostmaster, pqsignal(), SIG_DFL, SIGHUP, and SIGQUIT.

Referenced by AuxiliaryProcessMain().

551 {
553 
554  /*
555  * We don't actually need any non-default signal handling in bootstrap
556  * mode; "curl up and die" is a sufficient response for all these cases.
557  * Let's set that handling explicitly, as documentation if nothing else.
558  */
560  pqsignal(SIGINT, SIG_DFL);
561  pqsignal(SIGTERM, SIG_DFL);
563 }
#define SIGQUIT
Definition: win32_port.h:160
bool IsUnderPostmaster
Definition: globals.c:112
#define SIGHUP
Definition: win32_port.h:159
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
#define SIG_DFL
Definition: win32_port.h:154
#define Assert(condition)
Definition: c.h:804

◆ BootstrapModeMain()

static void BootstrapModeMain ( void  )
static

Definition at line 494 of file bootstrap.c.

References Assert, attrtypes, boot_yyparse(), cleanup(), CommitTransactionCommand(), elog, ERROR, i, InitPostgres(), InitProcess(), InvalidOid, IsBootstrapProcessingMode, IsUnderPostmaster, MAXATTR, pg_link_canary_is_frontend(), proc_exit(), RelationMapFinishBootstrap(), and StartTransactionCommand().

Referenced by AuxiliaryProcessMain().

495 {
496  int i;
497 
500 
501  /*
502  * To ensure that src/common/link-canary.c is linked into the backend, we
503  * must call it from somewhere. Here is as good as anywhere.
504  */
506  elog(ERROR, "backend is incorrectly linked to frontend functions");
507 
508  /*
509  * Do backend-like initialization for bootstrap mode
510  */
511  InitProcess();
512 
513  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
514 
515  /* Initialize stuff for bootstrap-file processing */
516  for (i = 0; i < MAXATTR; i++)
517  {
518  attrtypes[i] = NULL;
519  Nulls[i] = false;
520  }
521 
522  /*
523  * Process bootstrap input.
524  */
526  boot_yyparse();
528 
529  /*
530  * We should now know about all mapped relations, so it's okay to write
531  * out the initial relation mapping files.
532  */
534 
535  /* Clean up and exit */
536  cleanup();
537  proc_exit(0);
538 }
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:560
void CommitTransactionCommand(void)
Definition: xact.c:2939
int boot_yyparse(void)
void proc_exit(int code)
Definition: ipc.c:104
#define ERROR
Definition: elog.h:46
void InitProcess(void)
Definition: proc.c:303
bool IsUnderPostmaster
Definition: globals.c:112
#define MAXATTR
Definition: bootstrap.h:24
static void cleanup(void)
Definition: bootstrap.c:867
#define InvalidOid
Definition: postgres_ext.h:36
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname, bool override_allow_connections)
Definition: postinit.c:579
#define Assert(condition)
Definition: c.h:804
void StartTransactionCommand(void)
Definition: xact.c:2838
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
#define elog(elevel,...)
Definition: elog.h:232
int i
static bool Nulls[MAXATTR]
Definition: bootstrap.c:167
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:75

◆ build_indices()

void build_indices ( void  )

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

1137 {
1138  for (; ILHead != NULL; ILHead = ILHead->il_next)
1139  {
1140  Relation heap;
1141  Relation ind;
1142 
1143  /* need not bother with locks during bootstrap */
1144  heap = table_open(ILHead->il_heap, NoLock);
1145  ind = index_open(ILHead->il_ind, NoLock);
1146 
1147  index_build(heap, ind, ILHead->il_info, false, false);
1148 
1149  index_close(ind, NoLock);
1150  table_close(heap, NoLock);
1151  }
1152 }
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:2898
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

◆ CheckerModeMain()

static void CheckerModeMain ( void  )
static

Definition at line 481 of file bootstrap.c.

References proc_exit().

Referenced by AuxiliaryProcessMain().

482 {
483  proc_exit(0);
484 }
void proc_exit(int code)
Definition: ipc.c:104

◆ cleanup()

◆ closerel()

void closerel ( char *  name)

Definition at line 637 of file bootstrap.c.

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

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

638 {
639  if (name)
640  {
641  if (boot_reldesc)
642  {
643  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
644  elog(ERROR, "close of %s when %s was expected",
646  }
647  else
648  elog(ERROR, "close of %s before any relation was opened",
649  name);
650  }
651 
652  if (boot_reldesc == NULL)
653  elog(ERROR, "no open relation to close");
654  else
655  {
656  elog(DEBUG4, "close relation %s",
659  boot_reldesc = NULL;
660  }
661 }
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:511
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 674 of file bootstrap.c.

References typinfo::align, AllocateAttribute(), typmap::am_oid, typmap::am_typ, Assert, 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, InvalidCompressionMethod, InvalidOid, typinfo::len, MemSet, NameStr, namestrcpy(), NIL, typinfo::oid, OidIsValid, typinfo::storage, and WARNING.

675 {
676  Oid typeoid;
677 
678  if (boot_reldesc != NULL)
679  {
680  elog(WARNING, "no open relations allowed with CREATE command");
681  closerel(NULL);
682  }
683 
684  if (attrtypes[attnum] == NULL)
687 
689  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
690  attrtypes[attnum]->attnum = attnum + 1;
691 
692  typeoid = gettype(type);
693 
694  if (Typ != NIL)
695  {
696  attrtypes[attnum]->atttypid = Ap->am_oid;
697  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
698  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
699  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
700  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
701  attrtypes[attnum]->attcompression = InvalidCompressionMethod;
702  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
703  /* if an array type, assume 1-dimensional attribute */
704  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
705  attrtypes[attnum]->attndims = 1;
706  else
707  attrtypes[attnum]->attndims = 0;
708  }
709  else
710  {
711  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
712  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
713  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
714  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
715  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
716  attrtypes[attnum]->attcompression = InvalidCompressionMethod;
717  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
718  /* if an array type, assume 1-dimensional attribute */
719  if (TypInfo[typeoid].elem != InvalidOid &&
720  attrtypes[attnum]->attlen < 0)
721  attrtypes[attnum]->attndims = 1;
722  else
723  attrtypes[attnum]->attndims = 0;
724  }
725 
726  /*
727  * If a system catalog column is collation-aware, force it to use C
728  * collation, so that its behavior is independent of the database's
729  * collation. This is essential to allow template0 to be cloned with a
730  * different database collation.
731  */
732  if (OidIsValid(attrtypes[attnum]->attcollation))
733  attrtypes[attnum]->attcollation = C_COLLATION_OID;
734 
735  attrtypes[attnum]->attstattarget = -1;
736  attrtypes[attnum]->attcacheoff = -1;
737  attrtypes[attnum]->atttypmod = -1;
738  attrtypes[attnum]->attislocal = true;
739 
740  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
741  {
742  attrtypes[attnum]->attnotnull = true;
743  }
744  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
745  {
746  attrtypes[attnum]->attnotnull = false;
747  }
748  else
749  {
750  Assert(nullness == BOOTCOL_NULL_AUTO);
751 
752  /*
753  * Mark as "not null" if type is fixed-width and prior columns are
754  * likewise fixed-width and not-null. This corresponds to case where
755  * column can be accessed directly via C struct declaration.
756  */
757  if (attrtypes[attnum]->attlen > 0)
758  {
759  int i;
760 
761  /* check earlier attributes */
762  for (i = 0; i < attnum; i++)
763  {
764  if (attrtypes[i]->attlen <= 0 ||
765  !attrtypes[i]->attnotnull)
766  break;
767  }
768  if (i == attnum)
769  attrtypes[attnum]->attnotnull = true;
770  }
771  }
772 }
#define NIL
Definition: pg_list.h:65
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
int16 len
Definition: bootstrap.c:93
bool attnotnull
Definition: pg_attribute.h:139
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:637
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
NameData attname
Definition: pg_attribute.h:41
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:199
int16 attlen
Definition: pg_attribute.h:68
#define WARNING
Definition: elog.h:40
Oid collation
Definition: bootstrap.c:97
#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:1068
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:920
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

◆ gettype()

static Oid gettype ( char *  type)
static

Definition at line 920 of file bootstrap.c.

References typmap::am_oid, typmap::am_typ, DEBUG4, elog, ERROR, i, lfirst, list_free_deep(), n_types, typinfo::name, NAMEDATALEN, NameStr, NIL, and populate_typ_list().

Referenced by DefineAttr().

921 {
922  if (Typ != NIL)
923  {
924  ListCell *lc;
925 
926  foreach(lc, Typ)
927  {
928  struct typmap *app = lfirst(lc);
929 
930  if (strncmp(NameStr(app->am_typ.typname), type, NAMEDATALEN) == 0)
931  {
932  Ap = app;
933  return app->am_oid;
934  }
935  }
936 
937  /*
938  * The type wasn't known; reload the pg_type contents and check again
939  * to handle composite types, added since last populating the list.
940  */
941 
943  Typ = NIL;
945 
946  /*
947  * Calling gettype would result in infinite recursion for types
948  * missing in pg_type, so just repeat the lookup.
949  */
950  foreach(lc, Typ)
951  {
952  struct typmap *app = lfirst(lc);
953 
954  if (strncmp(NameStr(app->am_typ.typname), type, NAMEDATALEN) == 0)
955  {
956  Ap = app;
957  return app->am_oid;
958  }
959  }
960  }
961  else
962  {
963  int i;
964 
965  for (i = 0; i < n_types; i++)
966  {
967  if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
968  return i;
969  }
970  /* Not in TypInfo, so we'd better be able to read pg_type now */
971  elog(DEBUG4, "external type: %s", type);
973  return gettype(type);
974  }
975  elog(ERROR, "unrecognized type \"%s\"", type);
976  /* not reached, here to make compiler happy */
977  return 0;
978 }
#define NIL
Definition: pg_list.h:65
static void populate_typ_list(void)
Definition: bootstrap.c:880
static List * Typ
Definition: bootstrap.c:163
static struct typmap * Ap
Definition: bootstrap.c:164
#define DEBUG4
Definition: elog.h:22
void list_free_deep(List *list)
Definition: list.c:1405
#define NAMEDATALEN
#define ERROR
Definition: elog.h:46
#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
const char * name
Definition: encode.c:515
static Oid gettype(char *type)
Definition: bootstrap.c:920
Oid am_oid
Definition: bootstrap.c:159
#define elog(elevel,...)
Definition: elog.h:232
int i
#define NameStr(name)
Definition: c.h:681

◆ index_register()

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

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

1089 {
1090  IndexList *newind;
1091  MemoryContext oldcxt;
1092 
1093  /*
1094  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1095  * bootstrap time. we'll declare the indexes now, but want to create them
1096  * later.
1097  */
1098 
1099  if (nogc == NULL)
1100  nogc = AllocSetContextCreate(NULL,
1101  "BootstrapNoGC",
1103 
1104  oldcxt = MemoryContextSwitchTo(nogc);
1105 
1106  newind = (IndexList *) palloc(sizeof(IndexList));
1107  newind->il_heap = heap;
1108  newind->il_ind = ind;
1109  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1110 
1111  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1112  /* expressions will likely be null, but may as well copy it */
1113  newind->il_info->ii_Expressions =
1114  copyObject(indexInfo->ii_Expressions);
1115  newind->il_info->ii_ExpressionsState = NIL;
1116  /* predicate will likely be null, but may as well copy it */
1117  newind->il_info->ii_Predicate =
1118  copyObject(indexInfo->ii_Predicate);
1119  newind->il_info->ii_PredicateState = NULL;
1120  /* no exclusion constraints at bootstrap time, so no need to copy */
1121  Assert(indexInfo->ii_ExclusionOps == NULL);
1122  Assert(indexInfo->ii_ExclusionProcs == NULL);
1123  Assert(indexInfo->ii_ExclusionStrats == NULL);
1124 
1125  newind->il_next = ILHead;
1126  ILHead = newind;
1127 
1128  MemoryContextSwitchTo(oldcxt);
1129 }
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 849 of file bootstrap.c.

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

850 {
851  elog(DEBUG4, "inserting column %d NULL", i);
852  Assert(i >= 0 && i < MAXATTR);
853  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
854  elog(ERROR,
855  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
858  values[i] = PointerGetDatum(NULL);
859  Nulls[i] = true;
860 }
#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:511
#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 783 of file bootstrap.c.

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

784 {
785  HeapTuple tuple;
786  TupleDesc tupDesc;
787  int i;
788 
789  elog(DEBUG4, "inserting row with %d columns", numattr);
790 
791  tupDesc = CreateTupleDesc(numattr, attrtypes);
792  tuple = heap_form_tuple(tupDesc, values, Nulls);
793  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
794 
796  heap_freetuple(tuple);
797  elog(DEBUG4, "row inserted");
798 
799  /*
800  * Reset null markers for next tuple
801  */
802  for (i = 0; i < numattr; i++)
803  Nulls[i] = false;
804 }
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:2642
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 811 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.

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

◆ populate_typ_list()

static void populate_typ_list ( void  )
static

Definition at line 880 of file bootstrap.c.

References typmap::am_oid, typmap::am_typ, Assert, ForwardScanDirection, GETSTRUCT, heap_getnext(), lappend(), MemoryContextSwitchTo(), NIL, NoLock, palloc(), table_beginscan_catalog(), table_close(), table_endscan(), table_open(), and TopMemoryContext.

Referenced by boot_openrel(), and gettype().

881 {
882  Relation rel;
883  TableScanDesc scan;
884  HeapTuple tup;
885  MemoryContext old;
886 
887  Assert(Typ == NIL);
888 
889  rel = table_open(TypeRelationId, NoLock);
890  scan = table_beginscan_catalog(rel, 0, NULL);
892  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
893  {
894  Form_pg_type typForm = (Form_pg_type) GETSTRUCT(tup);
895  struct typmap *newtyp;
896 
897  newtyp = (struct typmap *) palloc(sizeof(struct typmap));
898  Typ = lappend(Typ, newtyp);
899 
900  newtyp->am_oid = typForm->oid;
901  memcpy(&newtyp->am_typ, typForm, sizeof(newtyp->am_typ));
902  }
904  table_endscan(scan);
905  table_close(rel, NoLock);
906 }
#define NIL
Definition: pg_list.h:65
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:112
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static List * Typ
Definition: bootstrap.c:163
#define NoLock
Definition: lockdefs.h:34
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1340
MemoryContext TopMemoryContext
Definition: mcxt.c:48
List * lappend(List *list, void *datum)
Definition: list.c:336
#define Assert(condition)
Definition: c.h:804
FormData_pg_type am_typ
Definition: bootstrap.c:160
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:991
Oid am_oid
Definition: bootstrap.c:159
void * palloc(Size size)
Definition: mcxt.c:1062
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ ShutdownAuxiliaryProcess()

static void ShutdownAuxiliaryProcess ( int  code,
Datum  arg 
)
static

Definition at line 573 of file bootstrap.c.

References ConditionVariableCancelSleep(), LWLockReleaseAll(), and pgstat_report_wait_end().

Referenced by AuxiliaryProcessMain().

574 {
578 }
static void pgstat_report_wait_end(void)
Definition: wait_event.h:278
void ConditionVariableCancelSleep(void)
void LWLockReleaseAll(void)
Definition: lwlock.c:1902

Variable Documentation

◆ Ap

struct typmap* Ap = NULL
static

Definition at line 164 of file bootstrap.c.

◆ 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.

◆ bootstrap_data_checksum_version

uint32 bootstrap_data_checksum_version = 0

Definition at line 54 of file bootstrap.c.

Referenced by AuxiliaryProcessMain(), and InitControlFile().

◆ ILHead

IndexList* ILHead = NULL
static

Definition at line 185 of file bootstrap.c.

Referenced by index_register().

◆ MyAuxProcType

AuxProcType MyAuxProcType = NotAnAuxProcess

Definition at line 71 of file bootstrap.c.

Referenced by AuxiliaryProcessMain(), and pgstat_beinit().

◆ n_types

const int n_types = sizeof(TypInfo) / sizeof(struct typinfo)
static

Definition at line 155 of file bootstrap.c.

Referenced by boot_get_type_io_data(), and gettype().

◆ nogc

MemoryContext nogc = NULL
static

Definition at line 169 of file bootstrap.c.

◆ Nulls

bool Nulls[MAXATTR]
static

Definition at line 167 of file bootstrap.c.

◆ numattr

int numattr

Definition at line 76 of file bootstrap.c.

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

◆ Typ

List* Typ = NIL
static

Definition at line 163 of file bootstrap.c.

◆ TypInfo

const struct typinfo TypInfo[]
static

Definition at line 102 of file bootstrap.c.

◆ values

Datum values[MAXATTR]
static

Definition at line 166 of file bootstrap.c.

Referenced by _bt_check_unique(), aclexplode(), AddEnumLabel(), AddSubscriptionRelState(), AggregateCreate(), AlterCollation(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterOperator(), AlterPolicy(), AlterPublicationOptions(), AlterSetting(), AlterSubscription(), AlterTypeRecurse(), apply_returning_filter(), ApplyExtensionUpdates(), array_iterate(), array_map(), array_out(), array_replace_internal(), brin_deform_tuple(), brin_form_tuple(), brin_metapage_info(), brin_page_items(), bt_metap(), bt_page_print_tuples(), bt_page_stats_internal(), build_pgstattuple_type(), build_sorted_items(), build_tuplestore_recursively(), CastCreate(), CatalogIndexInsert(), CollationCreate(), collectTSQueryValues(), comparetup_index_btree(), compute_index_stats(), compute_scalar_stats(), connect_pg_server(), connectDatabase(), ConnectDatabase(), ConversionCreate(), copy_replication_slot(), create_cursor(), CreateAccessMethod(), CreateComments(), CreateConstraintEntry(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreatePolicy(), CreateProceduralLanguage(), CreatePublication(), CreateReplicationSlot(), CreateSharedComments(), CreateStatistics(), CreateSubscription(), CreateTableSpace(), CreateTransform(), CreateTriggerFiringOn(), CreateUserMapping(), crosstab(), dblink_get_pkey(), DefineOpClass(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), deflist_to_tuplestore(), DiscreteKnapsack(), do_connect(), do_text_output_multiline(), doConnect(), each_object_field_end(), each_worker_jsonb(), elements_array_element_end(), elements_worker_jsonb(), EnumValuesCreate(), exec_move_row(), exec_rt_fetch(), ExecBuildAggTrans(), ExecCheckIndexConstraints(), ExecComputeStoredGenerated(), ExecEvalMinMax(), ExecEvalXmlExpr(), ExecFilterJunk(), ExecFindPartition(), ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), ExecInitExprRec(), ExecInsertIndexTuples(), execute_dml_stmt(), ExtractReplicaIdentity(), file_acquire_sample_rows(), fill_hba_line(), fillRelOptions(), get_actual_variable_endpoint(), get_available_versions_for_extension(), get_crosstab_tuplestore(), get_text_array_contents(), GetConnection(), gin_leafpage_items(), gin_metapage_info(), gin_page_opaque_info(), gist_page_items(), gist_page_items_bytea(), gist_page_opaque_info(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), hash_record(), hash_record_extended(), heap_deform_tuple(), heap_modify_tuple(), heap_modify_tuple_by_cols(), heap_page_items(), heap_tuple_infomask_flags(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_relation_copy_for_cluster(), hstore_from_record(), hstore_populate_record(), IdentifySystem(), index_concurrently_swap(), index_truncate_tuple(), IndexCheckExclusion(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertPgClassTuple(), InsertRule(), intset_flush_buffered_values(), inv_truncate(), inv_write(), LargeObjectCreate(), LogicalOutputWrite(), logicalrep_write_tuple(), main(), make_tuple_from_result_row(), make_tuple_indirect(), MakeConfigurationMapping(), MakeOldSnapshotTimeMappingTuple(), materializeResult(), NamespaceCreate(), ndistinct_for_combination(), oid_array_to_list(), OperatorCreate(), OperatorShellMake(), page_header(), parse_key_value_arrays(), parseLocalRelOptions(), perform_pruning_base_step(), pg_armor(), pg_available_extensions(), pg_buffercache_pages(), pg_config(), pg_control_checkpoint(), pg_control_init(), pg_control_recovery(), pg_control_system(), pg_create_logical_replication_slot(), pg_create_physical_replication_slot(), pg_cursor(), pg_event_trigger_ddl_commands(), pg_event_trigger_dropped_objects(), pg_extension_update_paths(), pg_get_catalog_foreign_keys(), pg_get_keywords(), pg_get_multixact_members(), pg_get_object_address(), pg_get_replication_slots(), pg_get_shmem_allocations(), pg_identify_object(), pg_identify_object_as_address(), pg_last_committed_xact(), pg_lock_status(), pg_logdir_ls_internal(), pg_ls_dir(), pg_ls_dir_files(), pg_partition_tree(), pg_prepared_statement(), pg_prepared_xact(), pg_replication_slot_advance(), pg_sequence_parameters(), pg_show_replication_origin_status(), pg_stat_file(), pg_stat_get_activity(), pg_stat_get_archiver(), pg_stat_get_progress_info(), pg_stat_get_replication_slot(), pg_stat_get_slru(), pg_stat_get_subscription(), pg_stat_get_wal(), pg_stat_get_wal_receiver(), pg_stat_get_wal_senders(), pg_stat_statements_info(), pg_stat_statements_internal(), pg_stats_ext_mcvlist_items(), pg_stop_backup_v2(), pg_tablespace_databases(), pg_timezone_abbrevs(), pg_timezone_names(), pg_visibility(), pg_visibility_map(), pg_visibility_map_rel(), pg_visibility_map_summary(), pg_visibility_rel(), pg_walfile_name_offset(), pg_xact_commit_timestamp_origin(), pgp_armor_headers(), pgrowlocks(), pgstatginindex_internal(), pgstathashindex(), pgstatindex_impl(), pgstattuple_approx_internal(), plperl_build_tuple_result(), pltcl_build_tuple_result(), PLyGenericObject_ToComposite(), PLyMapping_ToComposite(), PLySequence_ToComposite(), populate_record(), postgres_fdw_get_connections(), pqPacketSend(), ProcedureCreate(), prs_process_call(), publication_add_relation(), PutMemoryContextsStatsTupleStore(), RangeCreate(), record_in(), record_out(), record_recv(), record_send(), recordExtensionInitPrivWorker(), reduce_expanded_ranges(), RemoveRoleFromObjectPolicy(), replorigin_create(), report_corruption_internal(), serialize_expr_stats(), SetDefaultACL(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepAddDependency(), shdepChangeDep(), show_all_file_settings(), show_all_settings(), ShowAllGUCConfig(), slot_deform_heap_tuple(), split_text_accum_result(), sql_conn(), ssl_extension_info(), StartReplication(), statext_mcv_serialize(), statext_store(), StoreAttrDefault(), storeOperators(), StorePartitionKey(), storeProcedures(), StoreSingleInheritance(), test_enc_conversion(), test_huge_distances(), test_predtest(), tfuncLoadRows(), ts_process_call(), tsvector_unnest(), tt_process_call(), TypeCreate(), TypeShellMake(), unique_key_recheck(), update_attstats(), UpdateIndexRelation(), UpdateSubscriptionRelState(), UpdateTwoPhaseState(), vacuumlo(), ValuesNext(), WaitForLockersMultiple(), and xpath_table().