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

References ATTRIBUTE_FIXED_PART_SIZE, MemoryContextAllocZero(), and TopMemoryContext.

Referenced by boot_openrel(), and DefineAttr().

1060 {
1061  return (Form_pg_attribute)
1063 }
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:192
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_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, 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_get_backend_desc(), 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  /*
318  * Identify myself via ps
319  */
320  if (IsUnderPostmaster)
321  {
322  const char *statmsg;
323 
324  switch (MyAuxProcType)
325  {
326  case StartupProcess:
328  break;
329  case BgWriterProcess:
331  break;
332  case CheckpointerProcess:
334  break;
335  case WalWriterProcess:
337  break;
338  case WalReceiverProcess:
340  break;
341  default:
342  statmsg = "??? process";
343  break;
344  }
345  init_ps_display(statmsg, "", "", "");
346  }
347 
348  /* Acquire configuration parameters, unless inherited from postmaster */
349  if (!IsUnderPostmaster)
350  {
351  if (!SelectConfigFiles(userDoption, progname))
352  proc_exit(1);
353  }
354 
355  /*
356  * Validate we have been given a reasonable-looking DataDir and change
357  * into it (if under postmaster, should be done already).
358  */
359  if (!IsUnderPostmaster)
360  {
361  checkDataDir();
362  ChangeToDataDir();
363  }
364 
365  /* If standalone, create lockfile for data directory */
366  if (!IsUnderPostmaster)
367  CreateDataDirLockFile(false);
368 
370  IgnoreSystemIndexes = true;
371 
372  /* Initialize MaxBackends (if under postmaster, was done already) */
373  if (!IsUnderPostmaster)
375 
376  BaseInit();
377 
378  /*
379  * When we are an auxiliary process, we aren't going to do the full
380  * InitPostgres pushups, but there are a couple of things that need to get
381  * lit up even in an auxiliary process.
382  */
383  if (IsUnderPostmaster)
384  {
385  /*
386  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
387  * this was already done by SubPostmasterMain().
388  */
389 #ifndef EXEC_BACKEND
391 #endif
392 
393  /*
394  * Assign the ProcSignalSlot for an auxiliary process. Since it
395  * doesn't have a BackendId, the slot is statically allocated based on
396  * the auxiliary process type (MyAuxProcType). Backends use slots
397  * indexed in the range from 1 to MaxBackends (inclusive), so we use
398  * MaxBackends + AuxProcType + 1 as the index of the slot for an
399  * auxiliary process.
400  *
401  * This will need rethinking if we ever want more than one of a
402  * particular auxiliary process type.
403  */
405 
406  /* finish setting up bufmgr.c */
408 
409  /*
410  * Auxiliary processes don't run transactions, but they may need a
411  * resource owner anyway to manage buffer pins acquired outside
412  * transactions (and, perhaps, other things in future).
413  */
415 
416  /* Initialize backend status information */
418  pgstat_bestart();
419 
420  /* register a before-shutdown callback for LWLock cleanup */
422  }
423 
424  /*
425  * XLOG operations
426  */
428 
429  switch (MyAuxProcType)
430  {
431  case CheckerProcess:
432  /* don't set signals, they're useless here */
433  CheckerModeMain();
434  proc_exit(1); /* should never return */
435 
436  case BootstrapProcess:
437 
438  /*
439  * There was a brief instant during which mode was Normal; this is
440  * okay. We need to be in bootstrap mode during BootStrapXLOG for
441  * the sake of multixact initialization.
442  */
445  BootStrapXLOG();
447  proc_exit(1); /* should never return */
448 
449  case StartupProcess:
450  /* don't set signals, startup process has its own agenda */
452  proc_exit(1); /* should never return */
453 
454  case BgWriterProcess:
455  /* don't set signals, bgwriter has its own agenda */
457  proc_exit(1); /* should never return */
458 
459  case CheckpointerProcess:
460  /* don't set signals, checkpointer has its own agenda */
462  proc_exit(1); /* should never return */
463 
464  case WalWriterProcess:
465  /* don't set signals, walwriter has its own agenda */
466  InitXLOGAccess();
467  WalWriterMain();
468  proc_exit(1); /* should never return */
469 
470  case WalReceiverProcess:
471  /* don't set signals, walreceiver has its own agenda */
472  WalReceiverMain();
473  proc_exit(1); /* should never return */
474 
475  default:
476  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
477  proc_exit(1);
478  }
479 }
void InitAuxiliaryProcess(void)
Definition: proc.c:515
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
void WalWriterMain(void)
Definition: walwriter.c:98
char * pstrdup(const char *in)
Definition: mcxt.c:1186
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4272
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:318
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:10360
void StartupProcessMain(void)
Definition: startup.c:162
#define write_stderr(str)
Definition: parallel.c:181
static struct @145 value
void proc_exit(int code)
Definition: ipc.c:104
int errcode(int sqlerrcode)
Definition: elog.c:608
#define SetProcessingMode(mode)
Definition: miscadmin.h:380
void BootStrapXLOG(void)
Definition: xlog.c:5084
void BaseInit(void)
Definition: postinit.c:547
bool IgnoreSystemIndexes
Definition: miscinit.c:77
void checkDataDir(void)
Definition: miscinit.c:99
static void bootstrap_signals(void)
Definition: bootstrap.c:557
const char * progname
Definition: pg_standby.c:36
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:501
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:1056
int optind
Definition: getopt.c:50
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1177
void InitXLOGAccess(void)
Definition: xlog.c:8182
#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:7540
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:213
void pgstat_initialize(void)
Definition: pgstat.c:2813
#define ereport(elevel, rest)
Definition: elog.h:141
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:580
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:5392
AuxProcType MyAuxProcType
Definition: bootstrap.c:72
void CheckpointerMain(void)
Definition: checkpointer.c:193
#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:834
void InitializeMaxBackends(void)
Definition: postinit.c:525
const char * name
Definition: encode.c:521
void BackgroundWriterMain(void)
Definition: bgwriter.c:109
int WalSegSz
Definition: pg_standby.c:38
static const char * userDoption
Definition: postgres.c:155
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:104
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:200
int errmsg(const char *fmt,...)
Definition: elog.c:822
void pgstat_bestart(void)
Definition: pgstat.c:2855
char * optarg
Definition: getopt.c:52
#define elog(elevel,...)
Definition: elog.h:228
static void CheckerModeMain(void)
Definition: bootstrap.c:488
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2469
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:53
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:249
void InitializeGUCOptions(void)
Definition: guc.c:5170

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

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

◆ boot_openrel()

void boot_openrel ( char *  relname)

Definition at line 597 of file bootstrap.c.

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

598 {
599  int i;
600  struct typmap **app;
601  Relation rel;
602  TableScanDesc scan;
603  HeapTuple tup;
604 
605  if (strlen(relname) >= NAMEDATALEN)
606  relname[NAMEDATALEN - 1] = '\0';
607 
608  if (Typ == NULL)
609  {
610  /* We can now load the pg_type data */
611  rel = table_open(TypeRelationId, NoLock);
612  scan = table_beginscan_catalog(rel, 0, NULL);
613  i = 0;
614  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
615  ++i;
616  table_endscan(scan);
617  app = Typ = ALLOC(struct typmap *, i + 1);
618  while (i-- > 0)
619  *app++ = ALLOC(struct typmap, 1);
620  *app = NULL;
621  scan = table_beginscan_catalog(rel, 0, NULL);
622  app = Typ;
623  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
624  {
625  (*app)->am_oid = ((Form_pg_type) GETSTRUCT(tup))->oid;
626  memcpy((char *) &(*app)->am_typ,
627  (char *) GETSTRUCT(tup),
628  sizeof((*app)->am_typ));
629  app++;
630  }
631  table_endscan(scan);
632  table_close(rel, NoLock);
633  }
634 
635  if (boot_reldesc != NULL)
636  closerel(NULL);
637 
638  elog(DEBUG4, "open relation %s, attrsize %d",
640 
643  for (i = 0; i < numattr; i++)
644  {
645  if (attrtypes[i] == NULL)
647  memmove((char *) attrtypes[i],
648  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
650 
651  {
653 
654  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
655  i, NameStr(at->attname), at->attlen, at->attnum,
656  at->atttypid);
657  }
658  }
659 }
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:428
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
NameData relname
Definition: pg_class.h:35
void closerel(char *name)
Definition: bootstrap.c:666
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1290
#define memmove(d, s, c)
Definition: c.h:1267
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:192
static struct typmap ** Typ
Definition: bootstrap.c:164
TupleDesc rd_att
Definition: rel.h:84
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:1059
FormData_pg_type * Form_pg_type
Definition: pg_type.h:250
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:228
int i
#define NameStr(name)
Definition: c.h:616
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 557 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

558 {
560 
561  /*
562  * We don't actually need any non-default signal handling in bootstrap
563  * mode; "curl up and die" is a sufficient response for all these cases.
564  * Let's set that handling explicitly, as documentation if nothing else.
565  */
567  pqsignal(SIGINT, SIG_DFL);
568  pqsignal(SIGTERM, SIG_DFL);
570 }
#define SIGQUIT
Definition: win32_port.h:155
bool IsUnderPostmaster
Definition: globals.c:109
#define SIGHUP
Definition: win32_port.h:154
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
#define SIG_DFL
Definition: win32_port.h:149
#define Assert(condition)
Definition: c.h:739

◆ BootstrapModeMain()

static void BootstrapModeMain ( void  )
static

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

502 {
503  int i;
504 
507 
508  /*
509  * To ensure that src/common/link-canary.c is linked into the backend, we
510  * must call it from somewhere. Here is as good as anywhere.
511  */
513  elog(ERROR, "backend is incorrectly linked to frontend functions");
514 
515  /*
516  * Do backend-like initialization for bootstrap mode
517  */
518  InitProcess();
519 
520  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
521 
522  /* Initialize stuff for bootstrap-file processing */
523  for (i = 0; i < MAXATTR; i++)
524  {
525  attrtypes[i] = NULL;
526  Nulls[i] = false;
527  }
528 
529  /*
530  * Process bootstrap input.
531  */
533  boot_yyparse();
535 
536  /*
537  * We should now know about all mapped relations, so it's okay to write
538  * out the initial relation mapping files.
539  */
541 
542  /* Clean up and exit */
543  cleanup();
544  proc_exit(0);
545 }
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:901
#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:589
#define Assert(condition)
Definition: c.h:739
void StartTransactionCommand(void)
Definition: xact.c:2797
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:374
#define elog(elevel,...)
Definition: elog.h:228
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 1127 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().

1128 {
1129  for (; ILHead != NULL; ILHead = ILHead->il_next)
1130  {
1131  Relation heap;
1132  Relation ind;
1133 
1134  /* need not bother with locks during bootstrap */
1135  heap = table_open(ILHead->il_heap, NoLock);
1136  ind = index_open(ILHead->il_ind, NoLock);
1137 
1138  index_build(heap, ind, ILHead->il_info, false, false);
1139 
1140  index_close(ind, NoLock);
1141  table_close(heap, NoLock);
1142  }
1143 }
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:2794
Oid il_heap
Definition: bootstrap.c:180
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:152
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:126

◆ CheckerModeMain()

static void CheckerModeMain ( void  )
static

Definition at line 488 of file bootstrap.c.

References proc_exit().

Referenced by AuxiliaryProcessMain().

489 {
490  proc_exit(0);
491 }
void proc_exit(int code)
Definition: ipc.c:104

◆ cleanup()

static void cleanup ( void  )
static

◆ closerel()

void closerel ( char *  name)

Definition at line 666 of file bootstrap.c.

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

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

667 {
668  if (name)
669  {
670  if (boot_reldesc)
671  {
672  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
673  elog(ERROR, "close of %s when %s was expected",
675  }
676  else
677  elog(ERROR, "close of %s before any relation was opened",
678  name);
679  }
680 
681  if (boot_reldesc == NULL)
682  elog(ERROR, "no open relation to close");
683  else
684  {
685  elog(DEBUG4, "close relation %s",
688  boot_reldesc = NULL;
689  }
690 }
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:456
const char * name
Definition: encode.c:521
#define elog(elevel,...)
Definition: elog.h:228

◆ DefineAttr()

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

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

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

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

Referenced by DefineAttr().

920 {
921  int i;
922  Relation rel;
923  TableScanDesc scan;
924  HeapTuple tup;
925  struct typmap **app;
926 
927  if (Typ != NULL)
928  {
929  for (app = Typ; *app != NULL; app++)
930  {
931  if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
932  {
933  Ap = *app;
934  return (*app)->am_oid;
935  }
936  }
937  }
938  else
939  {
940  for (i = 0; i < n_types; i++)
941  {
942  if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
943  return i;
944  }
945  elog(DEBUG4, "external type: %s", type);
946  rel = table_open(TypeRelationId, NoLock);
947  scan = table_beginscan_catalog(rel, 0, NULL);
948  i = 0;
949  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
950  ++i;
951  table_endscan(scan);
952  app = Typ = ALLOC(struct typmap *, i + 1);
953  while (i-- > 0)
954  *app++ = ALLOC(struct typmap, 1);
955  *app = NULL;
956  scan = table_beginscan_catalog(rel, 0, NULL);
957  app = Typ;
958  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
959  {
960  (*app)->am_oid = ((Form_pg_type) GETSTRUCT(tup))->oid;
961  memmove((char *) &(*app++)->am_typ,
962  (char *) GETSTRUCT(tup),
963  sizeof((*app)->am_typ));
964  }
965  table_endscan(scan);
966  table_close(rel, NoLock);
967  return gettype(type);
968  }
969  elog(ERROR, "unrecognized type \"%s\"", type);
970  /* not reached, here to make compiler happy */
971  return 0;
972 }
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:1290
#define memmove(d, s, c)
Definition: c.h:1267
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:250
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:831
static Oid gettype(char *type)
Definition: bootstrap.c:919
Oid am_oid
Definition: bootstrap.c:160
#define elog(elevel,...)
Definition: elog.h:228
int i
#define NameStr(name)
Definition: c.h:616
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 1077 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().

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

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 883 of file bootstrap.c.

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

884 {
885  elog(DEBUG4, "inserting column %d NULL", i);
886  Assert(i >= 0 && i < MAXATTR);
887  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
888  elog(ERROR,
889  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
892  values[i] = PointerGetDatum(NULL);
893  Nulls[i] = true;
894 }
#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:456
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:84
#define Assert(condition)
Definition: c.h:739
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:228
int i
#define NameStr(name)
Definition: c.h:616
static bool Nulls[MAXATTR]
Definition: bootstrap.c:168

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 817 of file bootstrap.c.

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

818 {
819  HeapTuple tuple;
820  TupleDesc tupDesc;
821  int i;
822 
823  elog(DEBUG4, "inserting row with %d columns", numattr);
824 
825  tupDesc = CreateTupleDesc(numattr, attrtypes);
826  tuple = heap_form_tuple(tupDesc, values, Nulls);
827  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
828 
830  heap_freetuple(tuple);
831  elog(DEBUG4, "row inserted");
832 
833  /*
834  * Reset null markers for next tuple
835  */
836  for (i = 0; i < numattr; i++)
837  Nulls[i] = false;
838 }
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:2384
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define elog(elevel,...)
Definition: elog.h:228
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 845 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.

846 {
847  Oid typoid;
848  int16 typlen;
849  bool typbyval;
850  char typalign;
851  char typdelim;
852  Oid typioparam;
853  Oid typinput;
854  Oid typoutput;
855 
856  AssertArg(i >= 0 && i < MAXATTR);
857 
858  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
859 
860  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
861 
862  boot_get_type_io_data(typoid,
863  &typlen, &typbyval, &typalign,
864  &typdelim, &typioparam,
865  &typinput, &typoutput);
866 
867  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
868 
869  /*
870  * We use ereport not elog here so that parameters aren't evaluated unless
871  * the message is going to be printed, which generally it isn't
872  */
873  ereport(DEBUG4,
874  (errmsg_internal("inserted -> %s",
875  OidOutputFunctionCall(typoutput, values[i]))));
876 }
signed short int16
Definition: c.h:346
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Relation boot_reldesc
Definition: bootstrap.c:74
static struct @145 value
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
char typalign
Definition: pg_type.h:169
#define MAXATTR
Definition: bootstrap.h:24
#define ereport(elevel, rest)
Definition: elog.h:141
#define AssertArg(condition)
Definition: c.h:741
TupleDesc rd_att
Definition: rel.h:84
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
static Datum values[MAXATTR]
Definition: bootstrap.c:167
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1655
#define elog(elevel,...)
Definition: elog.h:228
int i
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1646
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:985

◆ ShutdownAuxiliaryProcess()

static void ShutdownAuxiliaryProcess ( int  code,
Datum  arg 
)
static

Definition at line 580 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

581 {
585 }
void ConditionVariableCancelSleep(void)
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1342
void LWLockReleaseAll(void)
Definition: lwlock.c:1825

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

◆ 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(), pgstat_bestart(), 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(), 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(), CatalogIndexInsert(), CollationCreate(), collectTSQueryValues(), comparetup_index_btree(), compute_index_stats(), compute_scalar_stats(), connect_pg_server(), connectDatabase(), ConnectDatabase(), ConversionCreate(), copy_replication_slot(), copyTemplateDependencies(), create_cursor(), create_proc_lang(), CreateAccessMethod(), CreateCast(), CreateComments(), CreateConstraintEntry(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreatePolicy(), 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(), 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_identify_object(), pg_identify_object_as_address(), pg_last_committed_xact(), pg_lock_status(), pg_logdir_ls_internal(), 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_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().