PostgreSQL Source Code  git master
bootstrap.c File Reference
#include "postgres.h"
#include <unistd.h>
#include <signal.h>
#include "access/htup_details.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 "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 "utils/tqual.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 (Oid objectid)
 
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 53 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

Function Documentation

◆ AllocateAttribute()

static Form_pg_attribute AllocateAttribute ( void  )
static

Definition at line 1033 of file bootstrap.c.

References ATTRIBUTE_FIXED_PART_SIZE, MemoryContextAllocZero(), and TopMemoryContext.

Referenced by boot_openrel(), and DefineAttr().

1034 {
1035  return (Form_pg_attribute)
1037 }
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:197
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:189
MemoryContext TopMemoryContext
Definition: mcxt.c:44
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:814

◆ AuxiliaryProcessMain()

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

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

196 {
197  char *progname = argv[0];
198  int flag;
199  char *userDoption = NULL;
200 
201  /*
202  * Initialize process environment (already done if under postmaster, but
203  * not if standalone).
204  */
205  if (!IsUnderPostmaster)
206  InitStandaloneProcess(argv[0]);
207 
208  /*
209  * process command arguments
210  */
211 
212  /* Set defaults, to be overridden by explicit options below */
213  if (!IsUnderPostmaster)
215 
216  /* Ignore the initial --boot argument, if present */
217  if (argc > 1 && strcmp(argv[1], "--boot") == 0)
218  {
219  argv++;
220  argc--;
221  }
222 
223  /* If no -x argument, we are a CheckerProcess */
225 
226  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:x:X:-:")) != -1)
227  {
228  switch (flag)
229  {
230  case 'B':
231  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
232  break;
233  case 'D':
234  userDoption = pstrdup(optarg);
235  break;
236  case 'd':
237  {
238  /* Turn on debugging for the bootstrap process. */
239  char *debugstr;
240 
241  debugstr = psprintf("debug%s", optarg);
242  SetConfigOption("log_min_messages", debugstr,
244  SetConfigOption("client_min_messages", debugstr,
246  pfree(debugstr);
247  }
248  break;
249  case 'F':
250  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
251  break;
252  case 'k':
254  break;
255  case 'r':
257  break;
258  case 'x':
259  MyAuxProcType = atoi(optarg);
260  break;
261  case 'X':
262  {
263  int WalSegSz = strtoul(optarg, NULL, 0);
264 
265  if (!IsValidWalSegSize(WalSegSz))
266  ereport(ERROR,
267  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
268  errmsg("-X requires a power of two value between 1 MB and 1 GB")));
269  SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL,
271  }
272  break;
273  case 'c':
274  case '-':
275  {
276  char *name,
277  *value;
278 
279  ParseLongOption(optarg, &name, &value);
280  if (!value)
281  {
282  if (flag == '-')
283  ereport(ERROR,
284  (errcode(ERRCODE_SYNTAX_ERROR),
285  errmsg("--%s requires a value",
286  optarg)));
287  else
288  ereport(ERROR,
289  (errcode(ERRCODE_SYNTAX_ERROR),
290  errmsg("-c %s requires a value",
291  optarg)));
292  }
293 
295  free(name);
296  if (value)
297  free(value);
298  break;
299  }
300  default:
301  write_stderr("Try \"%s --help\" for more information.\n",
302  progname);
303  proc_exit(1);
304  break;
305  }
306  }
307 
308  if (argc != optind)
309  {
310  write_stderr("%s: invalid command-line arguments\n", progname);
311  proc_exit(1);
312  }
313 
314  /*
315  * Identify myself via ps
316  */
317  if (IsUnderPostmaster)
318  {
319  const char *statmsg;
320 
321  switch (MyAuxProcType)
322  {
323  case StartupProcess:
325  break;
326  case BgWriterProcess:
328  break;
329  case CheckpointerProcess:
331  break;
332  case WalWriterProcess:
334  break;
335  case WalReceiverProcess:
337  break;
338  default:
339  statmsg = "??? process";
340  break;
341  }
342  init_ps_display(statmsg, "", "", "");
343  }
344 
345  /* Acquire configuration parameters, unless inherited from postmaster */
346  if (!IsUnderPostmaster)
347  {
348  if (!SelectConfigFiles(userDoption, progname))
349  proc_exit(1);
350  }
351 
352  /*
353  * Validate we have been given a reasonable-looking DataDir and change
354  * into it (if under postmaster, should be done already).
355  */
356  if (!IsUnderPostmaster)
357  {
358  checkDataDir();
359  ChangeToDataDir();
360  }
361 
362  /* If standalone, create lockfile for data directory */
363  if (!IsUnderPostmaster)
364  CreateDataDirLockFile(false);
365 
367  IgnoreSystemIndexes = true;
368 
369  /* Initialize MaxBackends (if under postmaster, was done already) */
370  if (!IsUnderPostmaster)
372 
373  BaseInit();
374 
375  /*
376  * When we are an auxiliary process, we aren't going to do the full
377  * InitPostgres pushups, but there are a couple of things that need to get
378  * lit up even in an auxiliary process.
379  */
380  if (IsUnderPostmaster)
381  {
382  /*
383  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
384  * this was already done by SubPostmasterMain().
385  */
386 #ifndef EXEC_BACKEND
388 #endif
389 
390  /*
391  * Assign the ProcSignalSlot for an auxiliary process. Since it
392  * doesn't have a BackendId, the slot is statically allocated based on
393  * the auxiliary process type (MyAuxProcType). Backends use slots
394  * indexed in the range from 1 to MaxBackends (inclusive), so we use
395  * MaxBackends + AuxProcType + 1 as the index of the slot for an
396  * auxiliary process.
397  *
398  * This will need rethinking if we ever want more than one of a
399  * particular auxiliary process type.
400  */
402 
403  /* finish setting up bufmgr.c */
405 
406  /* Initialize backend status information */
408  pgstat_bestart();
409 
410  /* register a before-shutdown callback for LWLock cleanup */
412  }
413 
414  /*
415  * XLOG operations
416  */
418 
419  switch (MyAuxProcType)
420  {
421  case CheckerProcess:
422  /* don't set signals, they're useless here */
423  CheckerModeMain();
424  proc_exit(1); /* should never return */
425 
426  case BootstrapProcess:
427 
428  /*
429  * There was a brief instant during which mode was Normal; this is
430  * okay. We need to be in bootstrap mode during BootStrapXLOG for
431  * the sake of multixact initialization.
432  */
435  BootStrapXLOG();
437  proc_exit(1); /* should never return */
438 
439  case StartupProcess:
440  /* don't set signals, startup process has its own agenda */
442  proc_exit(1); /* should never return */
443 
444  case BgWriterProcess:
445  /* don't set signals, bgwriter has its own agenda */
447  proc_exit(1); /* should never return */
448 
449  case CheckpointerProcess:
450  /* don't set signals, checkpointer has its own agenda */
452  proc_exit(1); /* should never return */
453 
454  case WalWriterProcess:
455  /* don't set signals, walwriter has its own agenda */
456  InitXLOGAccess();
457  WalWriterMain();
458  proc_exit(1); /* should never return */
459 
460  case WalReceiverProcess:
461  /* don't set signals, walreceiver has its own agenda */
462  WalReceiverMain();
463  proc_exit(1); /* should never return */
464 
465  default:
466  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
467  proc_exit(1);
468  }
469 }
void InitAuxiliaryProcess(void)
Definition: proc.c:491
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
void WalWriterMain(void)
Definition: walwriter.c:98
char * pstrdup(const char *in)
Definition: mcxt.c:1161
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4099
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:315
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9649
void StartupProcessMain(void)
Definition: startup.c:179
#define write_stderr(str)
Definition: parallel.c:182
void proc_exit(int code)
Definition: ipc.c:104
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SetProcessingMode(mode)
Definition: miscadmin.h:378
void BootStrapXLOG(void)
Definition: xlog.c:5026
void BaseInit(void)
Definition: postinit.c:524
bool IgnoreSystemIndexes
Definition: miscinit.c:75
void checkDataDir(void)
Definition: miscinit.c:97
static void bootstrap_signals(void)
Definition: bootstrap.c:540
const char * progname
Definition: pg_standby.c:37
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:491
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
void WalReceiverMain(void)
Definition: walreceiver.c:189
void pfree(void *pointer)
Definition: mcxt.c:1031
int optind
Definition: getopt.c:51
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1173
void InitXLOGAccess(void)
Definition: xlog.c:8196
#define MAXPGPATH
int MaxBackends
Definition: globals.c:134
char OutputFileName[MAXPGPATH]
Definition: globals.c:69
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6917
bool IsUnderPostmaster
Definition: globals.c:108
char * flag(int b)
Definition: test-ctype.c:33
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:331
void ChangeToDataDir(void)
Definition: miscinit.c:211
void pgstat_initialize(void)
Definition: pgstat.c:2745
#define ereport(elevel, rest)
Definition: elog.h:122
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: bootstrap.c:559
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:4932
AuxProcType MyAuxProcType
Definition: bootstrap.c:69
static struct @131 value
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 InitializeMaxBackends(void)
Definition: postinit.c:502
const char * name
Definition: encode.c:521
void BackgroundWriterMain(void)
Definition: bgwriter.c:110
int WalSegSz
Definition: pg_standby.c:39
static const char * userDoption
Definition: postgres.c:161
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:105
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:196
int errmsg(const char *fmt,...)
Definition: elog.c:797
void pgstat_bestart(void)
Definition: pgstat.c:2785
char * optarg
Definition: getopt.c:53
static void CheckerModeMain(void)
Definition: bootstrap.c:478
void InitBufferPoolBackend(void)
Definition: bufmgr.c:2461
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:50
#define elog
Definition: elog.h:219
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:244
void InitializeGUCOptions(void)
Definition: guc.c:4710

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

967 {
968  if (Typ != NULL)
969  {
970  /* We have the boot-time contents of pg_type, so use it */
971  struct typmap **app;
972  struct typmap *ap;
973 
974  app = Typ;
975  while (*app && (*app)->am_oid != typid)
976  ++app;
977  ap = *app;
978  if (ap == NULL)
979  elog(ERROR, "type OID %u not found in Typ list", typid);
980 
981  *typlen = ap->am_typ.typlen;
982  *typbyval = ap->am_typ.typbyval;
983  *typalign = ap->am_typ.typalign;
984  *typdelim = ap->am_typ.typdelim;
985 
986  /* XXX this logic must match getTypeIOParam() */
987  if (OidIsValid(ap->am_typ.typelem))
988  *typioparam = ap->am_typ.typelem;
989  else
990  *typioparam = typid;
991 
992  *typinput = ap->am_typ.typinput;
993  *typoutput = ap->am_typ.typoutput;
994  }
995  else
996  {
997  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
998  int typeindex;
999 
1000  for (typeindex = 0; typeindex < n_types; typeindex++)
1001  {
1002  if (TypInfo[typeindex].oid == typid)
1003  break;
1004  }
1005  if (typeindex >= n_types)
1006  elog(ERROR, "type OID %u not found in TypInfo", typid);
1007 
1008  *typlen = TypInfo[typeindex].len;
1009  *typbyval = TypInfo[typeindex].byval;
1010  *typalign = TypInfo[typeindex].align;
1011  /* We assume typdelim is ',' for all boot-time types */
1012  *typdelim = ',';
1013 
1014  /* XXX this logic must match getTypeIOParam() */
1015  if (OidIsValid(TypInfo[typeindex].elem))
1016  *typioparam = TypInfo[typeindex].elem;
1017  else
1018  *typioparam = typid;
1019 
1020  *typinput = TypInfo[typeindex].inproc;
1021  *typoutput = TypInfo[typeindex].outproc;
1022  }
1023 }
int16 len
Definition: bootstrap.c:91
int16 typlen
Definition: pg_type.h:55
char align
Definition: bootstrap.c:93
Oid inproc
Definition: bootstrap.c:96
#define OidIsValid(objectId)
Definition: c.h:605
char typalign
Definition: pg_type.h:167
#define ERROR
Definition: elog.h:43
Oid elem
Definition: bootstrap.c:90
static struct typmap ** Typ
Definition: bootstrap.c:161
FormData_pg_type am_typ
Definition: bootstrap.c:158
static const int n_types
Definition: bootstrap.c:153
static const struct typinfo TypInfo[]
Definition: bootstrap.c:100
bool byval
Definition: bootstrap.c:92
Oid am_oid
Definition: bootstrap.c:157
Oid outproc
Definition: bootstrap.c:97
#define elog
Definition: elog.h:219
bool typbyval
Definition: pg_type.h:65

◆ boot_openrel()

void boot_openrel ( char *  relname)

Definition at line 576 of file bootstrap.c.

References ALLOC, AllocateAttribute(), typmap::am_oid, ATTRIBUTE_FIXED_PART_SIZE, attrtypes, closerel(), DEBUG4, elog, ForwardScanDirection, GETSTRUCT, heap_beginscan_catalog(), heap_close, heap_endscan(), heap_getnext(), heap_open(), heap_openrv(), HeapTupleGetOid, i, makeRangeVar(), memmove, NAMEDATALEN, NameStr, NoLock, numattr, RelationData::rd_att, RelationGetNumberOfAttributes, TupleDescAttr, and Typ.

577 {
578  int i;
579  struct typmap **app;
580  Relation rel;
581  HeapScanDesc scan;
582  HeapTuple tup;
583 
584  if (strlen(relname) >= NAMEDATALEN)
585  relname[NAMEDATALEN - 1] = '\0';
586 
587  if (Typ == NULL)
588  {
589  /* We can now load the pg_type data */
590  rel = heap_open(TypeRelationId, NoLock);
591  scan = heap_beginscan_catalog(rel, 0, NULL);
592  i = 0;
593  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
594  ++i;
595  heap_endscan(scan);
596  app = Typ = ALLOC(struct typmap *, i + 1);
597  while (i-- > 0)
598  *app++ = ALLOC(struct typmap, 1);
599  *app = NULL;
600  scan = heap_beginscan_catalog(rel, 0, NULL);
601  app = Typ;
602  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
603  {
604  (*app)->am_oid = HeapTupleGetOid(tup);
605  memcpy((char *) &(*app)->am_typ,
606  (char *) GETSTRUCT(tup),
607  sizeof((*app)->am_typ));
608  app++;
609  }
610  heap_endscan(scan);
611  heap_close(rel, NoLock);
612  }
613 
614  if (boot_reldesc != NULL)
615  closerel(NULL);
616 
617  elog(DEBUG4, "open relation %s, attrsize %d",
618  relname, (int) ATTRIBUTE_FIXED_PART_SIZE);
619 
620  boot_reldesc = heap_openrv(makeRangeVar(NULL, relname, -1), NoLock);
622  for (i = 0; i < numattr; i++)
623  {
624  if (attrtypes[i] == NULL)
626  memmove((char *) attrtypes[i],
627  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
629 
630  {
632 
633  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
634  i, NameStr(at->attname), at->attlen, at->attnum,
635  at->atttypid);
636  }
637  }
638 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1572
int numattr
Definition: bootstrap.c:74
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:413
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
Relation boot_reldesc
Definition: bootstrap.c:71
#define heap_close(r, l)
Definition: heapam.h:97
void closerel(char *name)
Definition: bootstrap.c:645
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
#define memmove(d, s, c)
Definition: c.h:1135
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:197
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1412
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:189
static struct typmap ** Typ
Definition: bootstrap.c:161
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1835
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
TupleDesc rd_att
Definition: rel.h:85
Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1323
#define ALLOC(t, c)
Definition: bootstrap.c:53
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1033
Oid am_oid
Definition: bootstrap.c:157
int i
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:421
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:73

◆ bootstrap_signals()

static void bootstrap_signals ( void  )
static

Definition at line 540 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

541 {
543 
544  /* Set up appropriately for interactive use */
545  pqsignal(SIGHUP, die);
546  pqsignal(SIGINT, die);
547  pqsignal(SIGTERM, die);
548  pqsignal(SIGQUIT, die);
549 }
#define SIGQUIT
Definition: win32_port.h:164
bool IsUnderPostmaster
Definition: globals.c:108
#define SIGHUP
Definition: win32_port.h:163
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
#define Assert(condition)
Definition: c.h:699
void die(SIGNAL_ARGS)
Definition: postgres.c:2658

◆ BootstrapModeMain()

static void BootstrapModeMain ( void  )
static

Definition at line 491 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

492 {
493  int i;
494 
497 
498  /*
499  * Do backend-like initialization for bootstrap mode
500  */
501  InitProcess();
502 
503  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
504 
505  /* Initialize stuff for bootstrap-file processing */
506  for (i = 0; i < MAXATTR; i++)
507  {
508  attrtypes[i] = NULL;
509  Nulls[i] = false;
510  }
511 
512  /*
513  * Process bootstrap input.
514  */
516  boot_yyparse();
518 
519  /*
520  * We should now know about all mapped relations, so it's okay to write
521  * out the initial relation mapping files.
522  */
524 
525  /* Clean up and exit */
526  cleanup();
527  proc_exit(0);
528 }
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:538
void CommitTransactionCommand(void)
Definition: xact.c:2744
int boot_yyparse(void)
void proc_exit(int code)
Definition: ipc.c:104
void InitProcess(void)
Definition: proc.c:288
bool IsUnderPostmaster
Definition: globals.c:108
#define MAXATTR
Definition: bootstrap.h:24
static void cleanup(void)
Definition: bootstrap.c:875
#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:565
#define Assert(condition)
Definition: c.h:699
void StartTransactionCommand(void)
Definition: xact.c:2673
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:372
int i
static bool Nulls[MAXATTR]
Definition: bootstrap.c:165
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:73

◆ build_indices()

void build_indices ( void  )

Definition at line 1101 of file bootstrap.c.

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

1102 {
1103  for (; ILHead != NULL; ILHead = ILHead->il_next)
1104  {
1105  Relation heap;
1106  Relation ind;
1107 
1108  /* need not bother with locks during bootstrap */
1109  heap = heap_open(ILHead->il_heap, NoLock);
1110  ind = index_open(ILHead->il_ind, NoLock);
1111 
1112  index_build(heap, ind, ILHead->il_info, false, false, false);
1113 
1114  index_close(ind, NoLock);
1115  heap_close(heap, NoLock);
1116  }
1117 }
struct _IndexList * il_next
Definition: bootstrap.c:180
Oid il_ind
Definition: bootstrap.c:178
static IndexList * ILHead
Definition: bootstrap.c:183
#define heap_close(r, l)
Definition: heapam.h:97
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isprimary, bool isreindex, bool parallel)
Definition: index.c:2229
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:179
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
Oid il_heap
Definition: bootstrap.c:177
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:150

◆ CheckerModeMain()

static void CheckerModeMain ( void  )
static

Definition at line 478 of file bootstrap.c.

References proc_exit().

Referenced by AuxiliaryProcessMain().

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

◆ cleanup()

static void cleanup ( void  )
static

Definition at line 875 of file bootstrap.c.

References closerel().

Referenced by BootstrapModeMain(), conninfo_uri_parse_options(), ExecQueryUsingCursor(), pg_regexec(), print_aligned_text(), RecordTransactionCommit(), ReorderBufferRestoreChanges(), set_pglocale_pgservice(), and SetWALFileNameForCleanup().

876 {
877  if (boot_reldesc != NULL)
878  closerel(NULL);
879 }
Relation boot_reldesc
Definition: bootstrap.c:71
void closerel(char *name)
Definition: bootstrap.c:645

◆ closerel()

void closerel ( char *  name)

Definition at line 645 of file bootstrap.c.

References DEBUG4, elog, ERROR, heap_close, NoLock, and RelationGetRelationName.

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

646 {
647  if (name)
648  {
649  if (boot_reldesc)
650  {
651  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
652  elog(ERROR, "close of %s when %s was expected",
654  }
655  else
656  elog(ERROR, "close of %s before any relation was opened",
657  name);
658  }
659 
660  if (boot_reldesc == NULL)
661  elog(ERROR, "no open relation to close");
662  else
663  {
664  elog(DEBUG4, "close relation %s",
667  boot_reldesc = NULL;
668  }
669 }
Relation boot_reldesc
Definition: bootstrap.c:71
#define heap_close(r, l)
Definition: heapam.h:97
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define RelationGetRelationName(relation)
Definition: rel.h:441
const char * name
Definition: encode.c:521
#define elog
Definition: elog.h:219

◆ DefineAttr()

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

Definition at line 682 of file bootstrap.c.

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

683 {
684  Oid typeoid;
685 
686  if (boot_reldesc != NULL)
687  {
688  elog(WARNING, "no open relations allowed with CREATE command");
689  closerel(NULL);
690  }
691 
692  if (attrtypes[attnum] == NULL)
695 
697  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
698  attrtypes[attnum]->attnum = attnum + 1; /* fillatt */
699 
700  typeoid = gettype(type);
701 
702  if (Typ != NULL)
703  {
704  attrtypes[attnum]->atttypid = Ap->am_oid;
705  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
706  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
707  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
708  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
709  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
710  /* if an array type, assume 1-dimensional attribute */
711  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
712  attrtypes[attnum]->attndims = 1;
713  else
714  attrtypes[attnum]->attndims = 0;
715  }
716  else
717  {
718  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
719  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
720  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
721  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
722  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
723  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
724  /* if an array type, assume 1-dimensional attribute */
725  if (TypInfo[typeoid].elem != InvalidOid &&
726  attrtypes[attnum]->attlen < 0)
727  attrtypes[attnum]->attndims = 1;
728  else
729  attrtypes[attnum]->attndims = 0;
730  }
731 
732  attrtypes[attnum]->attstattarget = -1;
733  attrtypes[attnum]->attcacheoff = -1;
734  attrtypes[attnum]->atttypmod = -1;
735  attrtypes[attnum]->attislocal = true;
736 
737  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
738  {
739  attrtypes[attnum]->attnotnull = true;
740  }
741  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
742  {
743  attrtypes[attnum]->attnotnull = false;
744  }
745  else
746  {
747  Assert(nullness == BOOTCOL_NULL_AUTO);
748 
749  /*
750  * Mark as "not null" if type is fixed-width and prior columns are
751  * too. This corresponds to case where column can be accessed
752  * directly via C struct declaration.
753  *
754  * oidvector and int2vector are also treated as not-nullable, even
755  * though they are no longer fixed-width.
756  */
757 #define MARKNOTNULL(att) \
758  ((att)->attlen > 0 || \
759  (att)->atttypid == OIDVECTOROID || \
760  (att)->atttypid == INT2VECTOROID)
761 
763  {
764  int i;
765 
766  /* check earlier attributes */
767  for (i = 0; i < attnum; i++)
768  {
769  if (!attrtypes[i]->attnotnull)
770  break;
771  }
772  if (i == attnum)
773  attrtypes[attnum]->attnotnull = true;
774  }
775  }
776 }
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:27
int16 len
Definition: bootstrap.c:91
bool attnotnull
Definition: pg_attribute.h:132
char align
Definition: bootstrap.c:93
Relation boot_reldesc
Definition: bootstrap.c:71
#define BOOTCOL_NULL_AUTO
Definition: bootstrap.h:26
#define MARKNOTNULL(att)
#define MemSet(start, val, len)
Definition: c.h:908
unsigned int Oid
Definition: postgres_ext.h:31
void closerel(char *name)
Definition: bootstrap.c:645
static struct typmap * Ap
Definition: bootstrap.c:162
int namestrcpy(Name name, const char *str)
Definition: name.c:216
#define DEBUG4
Definition: elog.h:22
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition: bootstrap.h:28
NameData attname
Definition: pg_attribute.h:40
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:189
int16 attlen
Definition: pg_attribute.h:64
#define WARNING
Definition: elog.h:40
Oid collation
Definition: bootstrap.c:95
static struct typmap ** Typ
Definition: bootstrap.c:161
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define Assert(condition)
Definition: c.h:699
char storage
Definition: bootstrap.c:94
FormData_pg_type am_typ
Definition: bootstrap.c:158
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1033
static const struct typinfo TypInfo[]
Definition: bootstrap.c:100
const char * name
Definition: encode.c:521
bool byval
Definition: bootstrap.c:92
static Oid gettype(char *type)
Definition: bootstrap.c:893
Oid am_oid
Definition: bootstrap.c:157
int i
#define NameStr(name)
Definition: c.h:576
Oid oid
Definition: bootstrap.c:89
#define elog
Definition: elog.h:219
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:73

◆ gettype()

static Oid gettype ( char *  type)
static

Definition at line 893 of file bootstrap.c.

References ALLOC, typmap::am_oid, typmap::am_typ, DEBUG4, elog, ERROR, ForwardScanDirection, GETSTRUCT, heap_beginscan_catalog(), heap_close, heap_endscan(), heap_getnext(), heap_open(), HeapTupleGetOid, i, memmove, n_types, typinfo::name, NAMEDATALEN, NameStr, NoLock, and Typ.

Referenced by DefineAttr().

894 {
895  int i;
896  Relation rel;
897  HeapScanDesc scan;
898  HeapTuple tup;
899  struct typmap **app;
900 
901  if (Typ != NULL)
902  {
903  for (app = Typ; *app != NULL; app++)
904  {
905  if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
906  {
907  Ap = *app;
908  return (*app)->am_oid;
909  }
910  }
911  }
912  else
913  {
914  for (i = 0; i < n_types; i++)
915  {
916  if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
917  return i;
918  }
919  elog(DEBUG4, "external type: %s", type);
920  rel = heap_open(TypeRelationId, NoLock);
921  scan = heap_beginscan_catalog(rel, 0, NULL);
922  i = 0;
923  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
924  ++i;
925  heap_endscan(scan);
926  app = Typ = ALLOC(struct typmap *, i + 1);
927  while (i-- > 0)
928  *app++ = ALLOC(struct typmap, 1);
929  *app = NULL;
930  scan = heap_beginscan_catalog(rel, 0, NULL);
931  app = Typ;
932  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
933  {
934  (*app)->am_oid = HeapTupleGetOid(tup);
935  memmove((char *) &(*app++)->am_typ,
936  (char *) GETSTRUCT(tup),
937  sizeof((*app)->am_typ));
938  }
939  heap_endscan(scan);
940  heap_close(rel, NoLock);
941  return gettype(type);
942  }
943  elog(ERROR, "unrecognized type \"%s\"", type);
944  /* not reached, here to make compiler happy */
945  return 0;
946 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1572
#define heap_close(r, l)
Definition: heapam.h:97
static struct typmap * Ap
Definition: bootstrap.c:162
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define memmove(d, s, c)
Definition: c.h:1135
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1412
static struct typmap ** Typ
Definition: bootstrap.c:161
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1835
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
#define ALLOC(t, c)
Definition: bootstrap.c:53
FormData_pg_type am_typ
Definition: bootstrap.c:158
static const int n_types
Definition: bootstrap.c:153
static const struct typinfo TypInfo[]
Definition: bootstrap.c:100
const char * name
Definition: encode.c:521
static Oid gettype(char *type)
Definition: bootstrap.c:893
Oid am_oid
Definition: bootstrap.c:157
int i
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707

◆ index_register()

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

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

1054 {
1055  IndexList *newind;
1056  MemoryContext oldcxt;
1057 
1058  /*
1059  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1060  * bootstrap time. we'll declare the indexes now, but want to create them
1061  * later.
1062  */
1063 
1064  if (nogc == NULL)
1065  nogc = AllocSetContextCreate(NULL,
1066  "BootstrapNoGC",
1068 
1069  oldcxt = MemoryContextSwitchTo(nogc);
1070 
1071  newind = (IndexList *) palloc(sizeof(IndexList));
1072  newind->il_heap = heap;
1073  newind->il_ind = ind;
1074  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1075 
1076  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1077  /* expressions will likely be null, but may as well copy it */
1078  newind->il_info->ii_Expressions =
1079  copyObject(indexInfo->ii_Expressions);
1080  newind->il_info->ii_ExpressionsState = NIL;
1081  /* predicate will likely be null, but may as well copy it */
1082  newind->il_info->ii_Predicate =
1083  copyObject(indexInfo->ii_Predicate);
1084  newind->il_info->ii_PredicateState = NULL;
1085  /* no exclusion constraints at bootstrap time, so no need to copy */
1086  Assert(indexInfo->ii_ExclusionOps == NULL);
1087  Assert(indexInfo->ii_ExclusionProcs == NULL);
1088  Assert(indexInfo->ii_ExclusionStrats == NULL);
1089 
1090  newind->il_next = ILHead;
1091  ILHead = newind;
1092 
1093  MemoryContextSwitchTo(oldcxt);
1094 }
struct _IndexList * il_next
Definition: bootstrap.c:180
#define NIL
Definition: pg_list.h:69
Oid il_ind
Definition: bootstrap.c:178
List * ii_Predicate
Definition: execnodes.h:156
ExprState * ii_PredicateState
Definition: execnodes.h:157
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static IndexList * ILHead
Definition: bootstrap.c:183
Oid * ii_ExclusionProcs
Definition: execnodes.h:159
static MemoryContext nogc
Definition: bootstrap.c:167
List * ii_ExpressionsState
Definition: execnodes.h:155
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
IndexInfo * il_info
Definition: bootstrap.c:179
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
List * ii_Expressions
Definition: execnodes.h:154
#define Assert(condition)
Definition: c.h:699
Oid il_heap
Definition: bootstrap.c:177
Oid * ii_ExclusionOps
Definition: execnodes.h:158
void * palloc(Size size)
Definition: mcxt.c:924
#define copyObject(obj)
Definition: nodes.h:630
uint16 * ii_ExclusionStrats
Definition: execnodes.h:160

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 857 of file bootstrap.c.

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

858 {
859  elog(DEBUG4, "inserting column %d NULL", i);
860  Assert(i >= 0 && i < MAXATTR);
861  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
862  elog(ERROR,
863  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
866  values[i] = PointerGetDatum(NULL);
867  Nulls[i] = true;
868 }
#define PointerGetDatum(X)
Definition: postgres.h:541
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
Relation boot_reldesc
Definition: bootstrap.c:71
#define DEBUG4
Definition: elog.h:22
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:441
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:85
#define Assert(condition)
Definition: c.h:699
static Datum values[MAXATTR]
Definition: bootstrap.c:164
int i
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219
static bool Nulls[MAXATTR]
Definition: bootstrap.c:165

◆ InsertOneTuple()

void InsertOneTuple ( Oid  objectid)

Definition at line 787 of file bootstrap.c.

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

788 {
789  HeapTuple tuple;
790  TupleDesc tupDesc;
791  int i;
792 
793  elog(DEBUG4, "inserting row oid %u, %d columns", objectid, numattr);
794 
795  tupDesc = CreateTupleDesc(numattr,
797  attrtypes);
798  tuple = heap_form_tuple(tupDesc, values, Nulls);
799  if (objectid != (Oid) 0)
800  HeapTupleSetOid(tuple, objectid);
801  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
802 
804  heap_freetuple(tuple);
805  elog(DEBUG4, "row inserted");
806 
807  /*
808  * Reset null markers for next tuple
809  */
810  for (i = 0; i < numattr; i++)
811  Nulls[i] = false;
812 }
bool relhasoids
Definition: pg_class.h:60
int numattr
Definition: bootstrap.c:74
#define RelationGetForm(relation)
Definition: rel.h:401
Relation boot_reldesc
Definition: bootstrap.c:71
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1074
TupleDesc CreateTupleDesc(int natts, bool hasoid, Form_pg_attribute *attrs)
Definition: tupdesc.c:91
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1773
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
#define HeapTupleSetOid(tuple, oid)
Definition: htup_details.h:710
void pfree(void *pointer)
Definition: mcxt.c:1031
Oid simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2986
static Datum values[MAXATTR]
Definition: bootstrap.c:164
int i
#define elog
Definition: elog.h:219
static bool Nulls[MAXATTR]
Definition: bootstrap.c:165
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:73

◆ InsertOneValue()

void InsertOneValue ( char *  value,
int  i 
)

Definition at line 819 of file bootstrap.c.

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

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

◆ ShutdownAuxiliaryProcess()

static void ShutdownAuxiliaryProcess ( int  code,
Datum  arg 
)
static

Definition at line 559 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

560 {
564 }
void ConditionVariableCancelSleep(void)
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1260
void LWLockReleaseAll(void)
Definition: lwlock.c:1824

Variable Documentation

◆ Ap

struct typmap* Ap = NULL
static

Definition at line 162 of file bootstrap.c.

◆ attrtypes

Definition at line 73 of file bootstrap.c.

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

◆ boot_reldesc

Relation boot_reldesc

Definition at line 71 of file bootstrap.c.

◆ bootstrap_data_checksum_version

uint32 bootstrap_data_checksum_version = 0

Definition at line 50 of file bootstrap.c.

Referenced by AuxiliaryProcessMain(), and BootStrapXLOG().

◆ ILHead

IndexList* ILHead = NULL
static

Definition at line 183 of file bootstrap.c.

Referenced by index_register().

◆ MyAuxProcType

AuxProcType MyAuxProcType = NotAnAuxProcess

Definition at line 69 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 153 of file bootstrap.c.

Referenced by boot_get_type_io_data(), and gettype().

◆ nogc

MemoryContext nogc = NULL
static

Definition at line 167 of file bootstrap.c.

◆ Nulls

bool Nulls[MAXATTR]
static

Definition at line 165 of file bootstrap.c.

◆ numattr

int numattr

Definition at line 74 of file bootstrap.c.

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

◆ Typ

struct typmap** Typ = NULL
static

Definition at line 161 of file bootstrap.c.

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

◆ TypInfo

const struct typinfo TypInfo[]
static

Definition at line 100 of file bootstrap.c.

◆ values

Datum values[MAXATTR]
static

Definition at line 164 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(), ATRewriteTable(), 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_tuplestore_recursively(), CatalogIndexInsert(), CollationCreate(), collectTSQueryValues(), comparetup_index_btree(), compute_index_stats(), compute_scalar_stats(), connect_pg_server(), connectDatabase(), ConnectDatabase(), ConversionCreate(), copy_heap_data(), CopyFrom(), copyTemplateDependencies(), CopyTo(), 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_notify(), dblink_get_pkey(), DefineOpClass(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), deflist_to_tuplestore(), dependency_degree(), 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(), ExecBuildAggTrans(), ExecCheckIndexConstraints(), 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_range(), 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(), hstore_from_record(), hstore_populate_record(), IdentifySystem(), index_truncate_tuple(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), IndexSetParentIndex(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertPgAttributeTuple(), InsertPgClassTuple(), InsertRule(), inv_truncate(), inv_write(), LargeObjectCreate(), LogicalOutputWrite(), logicalrep_write_tuple(), main(), make_tuple_from_result_row(), make_tuple_indirect(), MakeConfigurationMapping(), materializeQueryResult(), 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_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_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_tuple(), sql_conn(), ssl_extension_info(), StartReplication(), statext_store(), StoreAttrDefault(), StoreIndexTuple(), storeOperators(), StorePartitionKey(), storeProcedures(), StoreSingleInheritance(), test_predtest(), tfuncLoadRows(), ts_process_call(), tsvector_unnest(), tt_process_call(), tuple_equals_slot(), TypeCreate(), TypeShellMake(), unique_key_recheck(), update_attstats(), UpdateIndexRelation(), UpdateSubscriptionRelState(), vacuumlo(), validate_index_heapscan(), ValuesNext(), and xpath_table().