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/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
 

Macros

#define ALLOC(t, c)   ((t *) MemoryContextAllocZero(TopMemoryContext, (unsigned)(c) * sizeof(t)))
 
#define MARKNOTNULL(att)
 

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 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 struct typmap ** Typ = NULL
 
static struct typmapAp = NULL
 
static Datum values [MAXATTR]
 
static bool Nulls [MAXATTR]
 
static MemoryContext nogc = NULL
 
static IndexListILHead = NULL
 

Macro Definition Documentation

◆ ALLOC

#define ALLOC (   t,
  c 
)    ((t *) MemoryContextAllocZero(TopMemoryContext, (unsigned)(c) * sizeof(t)))

Definition at line 56 of file bootstrap.c.

Referenced by boot_openrel(), and gettype().

◆ MARKNOTNULL

#define MARKNOTNULL (   att)
Value:
((att)->attlen > 0 || \
(att)->atttypid == OIDVECTOROID || \
(att)->atttypid == INT2VECTOROID)
Oid atttypid
Definition: pg_attribute.h:49
int16 attlen
Definition: pg_attribute.h:64

Referenced by DefineAttr().

Typedef Documentation

◆ IndexList

typedef struct _IndexList IndexList

Function Documentation

◆ AllocateAttribute()

static Form_pg_attribute AllocateAttribute ( void  )
static

Definition at line 1051 of file bootstrap.c.

References ATTRIBUTE_FIXED_PART_SIZE, MemoryContextAllocZero(), and TopMemoryContext.

Referenced by boot_openrel(), and DefineAttr().

1052 {
1053  return (Form_pg_attribute)
1055 }
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:185
MemoryContext TopMemoryContext
Definition: mcxt.c:44
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:839

◆ AuxiliaryProcessMain()

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

Definition at line 198 of file bootstrap.c.

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

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

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

◆ boot_get_type_io_data()

void boot_get_type_io_data ( Oid  typid,
int16 typlen,
bool typbyval,
char *  typalign,
char *  typdelim,
Oid typioparam,
Oid typinput,
Oid typoutput 
)

Definition at line 977 of file bootstrap.c.

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

Referenced by get_type_io_data(), and InsertOneValue().

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

◆ boot_openrel()

void boot_openrel ( char *  relname)

Definition at line 589 of file bootstrap.c.

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

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

◆ bootstrap_signals()

static void bootstrap_signals ( void  )
static

Definition at line 549 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

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

◆ BootstrapModeMain()

static void BootstrapModeMain ( void  )
static

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

494 {
495  int i;
496 
499 
500  /*
501  * To ensure that src/common/link-canary.c is linked into the backend, we
502  * must call it from somewhere. Here is as good as anywhere.
503  */
505  elog(ERROR, "backend is incorrectly linked to frontend functions");
506 
507  /*
508  * Do backend-like initialization for bootstrap mode
509  */
510  InitProcess();
511 
512  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
513 
514  /* Initialize stuff for bootstrap-file processing */
515  for (i = 0; i < MAXATTR; i++)
516  {
517  attrtypes[i] = NULL;
518  Nulls[i] = false;
519  }
520 
521  /*
522  * Process bootstrap input.
523  */
525  boot_yyparse();
527 
528  /*
529  * We should now know about all mapped relations, so it's okay to write
530  * out the initial relation mapping files.
531  */
533 
534  /* Clean up and exit */
535  cleanup();
536  proc_exit(0);
537 }
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:560
void CommitTransactionCommand(void)
Definition: xact.c:2898
int boot_yyparse(void)
void proc_exit(int code)
Definition: ipc.c:104
#define ERROR
Definition: elog.h:43
void InitProcess(void)
Definition: proc.c:304
bool IsUnderPostmaster
Definition: globals.c:109
#define MAXATTR
Definition: bootstrap.h:24
static void cleanup(void)
Definition: bootstrap.c:893
#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:590
#define Assert(condition)
Definition: c.h:738
void StartTransactionCommand(void)
Definition: xact.c:2797
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:392
#define elog(elevel,...)
Definition: elog.h:214
int i
static bool Nulls[MAXATTR]
Definition: bootstrap.c:168
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:76

◆ build_indices()

void build_indices ( void  )

Definition at line 1119 of file bootstrap.c.

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

1120 {
1121  for (; ILHead != NULL; ILHead = ILHead->il_next)
1122  {
1123  Relation heap;
1124  Relation ind;
1125 
1126  /* need not bother with locks during bootstrap */
1127  heap = table_open(ILHead->il_heap, NoLock);
1128  ind = index_open(ILHead->il_ind, NoLock);
1129 
1130  index_build(heap, ind, ILHead->il_info, false, false);
1131 
1132  index_close(ind, NoLock);
1133  table_close(heap, NoLock);
1134  }
1135 }
struct _IndexList * il_next
Definition: bootstrap.c:183
Oid il_ind
Definition: bootstrap.c:181
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
static IndexList * ILHead
Definition: bootstrap.c:186
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:182
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2823
Oid il_heap
Definition: bootstrap.c:180
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132

◆ CheckerModeMain()

static void CheckerModeMain ( void  )
static

Definition at line 480 of file bootstrap.c.

References proc_exit().

Referenced by AuxiliaryProcessMain().

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

◆ cleanup()

static void cleanup ( void  )
static

◆ closerel()

void closerel ( char *  name)

Definition at line 658 of file bootstrap.c.

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

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

659 {
660  if (name)
661  {
662  if (boot_reldesc)
663  {
664  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
665  elog(ERROR, "close of %s when %s was expected",
667  }
668  else
669  elog(ERROR, "close of %s before any relation was opened",
670  name);
671  }
672 
673  if (boot_reldesc == NULL)
674  elog(ERROR, "no open relation to close");
675  else
676  {
677  elog(DEBUG4, "close relation %s",
680  boot_reldesc = NULL;
681  }
682 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
Relation boot_reldesc
Definition: bootstrap.c:74
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define RelationGetRelationName(relation)
Definition: rel.h:470
const char * name
Definition: encode.c:521
#define elog(elevel,...)
Definition: elog.h:214

◆ DefineAttr()

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

Definition at line 695 of file bootstrap.c.

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

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

◆ gettype()

static Oid gettype ( char *  type)
static

Definition at line 911 of file bootstrap.c.

References ALLOC, typmap::am_oid, typmap::am_typ, DEBUG4, elog, ERROR, ForwardScanDirection, GETSTRUCT, heap_getnext(), i, n_types, typinfo::name, NAMEDATALEN, NameStr, NoLock, typinfo::oid, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), and Typ.

Referenced by DefineAttr().

912 {
913  int i;
914  Relation rel;
915  TableScanDesc scan;
916  HeapTuple tup;
917  struct typmap **app;
918 
919  if (Typ != NULL)
920  {
921  for (app = Typ; *app != NULL; app++)
922  {
923  if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
924  {
925  Ap = *app;
926  return (*app)->am_oid;
927  }
928  }
929  }
930  else
931  {
932  for (i = 0; i < n_types; i++)
933  {
934  if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
935  return i;
936  }
937  elog(DEBUG4, "external type: %s", type);
938  rel = table_open(TypeRelationId, NoLock);
939  scan = table_beginscan_catalog(rel, 0, NULL);
940  i = 0;
941  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
942  ++i;
943  table_endscan(scan);
944  app = Typ = ALLOC(struct typmap *, i + 1);
945  while (i-- > 0)
946  *app++ = ALLOC(struct typmap, 1);
947  *app = NULL;
948  scan = table_beginscan_catalog(rel, 0, NULL);
949  app = Typ;
950  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
951  {
952  (*app)->am_oid = ((Form_pg_type) GETSTRUCT(tup))->oid;
953  memmove((char *) &(*app++)->am_typ,
954  (char *) GETSTRUCT(tup),
955  sizeof((*app)->am_typ));
956  }
957  table_endscan(scan);
958  table_close(rel, NoLock);
959  return gettype(type);
960  }
961  elog(ERROR, "unrecognized type \"%s\"", type);
962  /* not reached, here to make compiler happy */
963  return 0;
964 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:98
static struct typmap * Ap
Definition: bootstrap.c:165
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1291
static struct typmap ** Typ
Definition: bootstrap.c:164
#define ALLOC(t, c)
Definition: bootstrap.c:56
FormData_pg_type am_typ
Definition: bootstrap.c:161
static const int n_types
Definition: bootstrap.c:156
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
static const struct typinfo TypInfo[]
Definition: bootstrap.c:103
const char * name
Definition: encode.c:521
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:863
static Oid gettype(char *type)
Definition: bootstrap.c:911
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:214
int i
#define NameStr(name)
Definition: c.h:615
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ index_register()

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

Definition at line 1069 of file bootstrap.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, copyObject, IndexInfo::ii_ExclusionOps, IndexInfo::ii_ExclusionProcs, IndexInfo::ii_ExclusionStrats, IndexInfo::ii_Expressions, IndexInfo::ii_ExpressionsState, IndexInfo::ii_Predicate, IndexInfo::ii_PredicateState, _IndexList::il_heap, _IndexList::il_ind, _IndexList::il_info, _IndexList::il_next, ILHead, MemoryContextSwitchTo(), NIL, and palloc().

Referenced by index_create().

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

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 875 of file bootstrap.c.

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

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

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 809 of file bootstrap.c.

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

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

◆ InsertOneValue()

void InsertOneValue ( char *  value,
int  i 
)

Definition at line 837 of file bootstrap.c.

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

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

◆ ShutdownAuxiliaryProcess()

static void ShutdownAuxiliaryProcess ( int  code,
Datum  arg 
)
static

Definition at line 572 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

573 {
577 }
void ConditionVariableCancelSleep(void)
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1330
void LWLockReleaseAll(void)
Definition: lwlock.c:1826

Variable Documentation

◆ Ap

struct typmap* Ap = NULL
static

Definition at line 165 of file bootstrap.c.

◆ attrtypes

Definition at line 76 of file bootstrap.c.

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

◆ boot_reldesc

Relation boot_reldesc

Definition at line 74 of file bootstrap.c.

◆ bootstrap_data_checksum_version

uint32 bootstrap_data_checksum_version = 0

Definition at line 53 of file bootstrap.c.

Referenced by AuxiliaryProcessMain(), and InitControlFile().

◆ ILHead

IndexList* ILHead = NULL
static

Definition at line 186 of file bootstrap.c.

Referenced by index_register().

◆ MyAuxProcType

AuxProcType MyAuxProcType = NotAnAuxProcess

Definition at line 72 of file bootstrap.c.

Referenced by AuxiliaryProcessMain(), and pgstat_initialize().

◆ n_types

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

Definition at line 156 of file bootstrap.c.

Referenced by boot_get_type_io_data(), and gettype().

◆ nogc

MemoryContext nogc = NULL
static

Definition at line 170 of file bootstrap.c.

◆ Nulls

bool Nulls[MAXATTR]
static

Definition at line 168 of file bootstrap.c.

◆ numattr

int numattr

Definition at line 77 of file bootstrap.c.

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

◆ Typ

struct typmap** Typ = NULL
static

Definition at line 164 of file bootstrap.c.

Referenced by boot_get_type_io_data(), boot_openrel(), and gettype().

◆ TypInfo

const struct typinfo TypInfo[]
static

Definition at line 103 of file bootstrap.c.

◆ values

Datum values[MAXATTR]
static

Definition at line 167 of file bootstrap.c.

Referenced by _bt_check_unique(), _connectDB(), 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(), 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(), copyTemplateDependencies(), create_cursor(), CreateAccessMethod(), CreateComments(), CreateConstraintEntry(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreatePolicy(), CreateProceduralLanguage(), CreatePublication(), CreateReplicationSlot(), CreateSharedComments(), CreateStatistics(), CreateSubscription(), CreateTableSpace(), CreateTransform(), CreateTrigger(), 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(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), 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(), IndexSetParentIndex(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertPgAttributeTuple(), 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(), 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_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_subscription(), pg_stat_get_wal_receiver(), pg_stat_get_wal_senders(), 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(), 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(), pqPacketSend(), ProcedureCreate(), prs_process_call(), publication_add_relation(), RangeCreate(), record_in(), record_out(), record_recv(), record_send(), recordExtensionInitPrivWorker(), recordMultipleDependencies(), RemoveRoleFromObjectPolicy(), replorigin_create(), SetDefaultACL(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepAddDependency(), shdepChangeDep(), show_all_file_settings(), show_all_settings(), ShowAllGUCConfig(), slot_deform_heap_tuple(), sql_conn(), ssl_extension_info(), StartReplication(), statext_mcv_serialize(), statext_store(), StoreAttrDefault(), storeOperators(), StorePartitionKey(), storeProcedures(), StoreSingleInheritance(), test_huge_distances(), test_predtest(), tfuncLoadRows(), ts_process_call(), tsvector_unnest(), tt_process_call(), TypeCreate(), TypeShellMake(), unique_key_recheck(), update_attstats(), UpdateIndexRelation(), UpdateStatisticsForTypeChange(), UpdateSubscriptionRelState(), vacuumlo(), ValuesNext(), WaitForLockersMultiple(), and xpath_table().