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)
 
char * MapArrayTypeName (const char *s)
 
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)
#define INT2VECTOROID
Definition: pg_type.h:312
#define OIDVECTOROID
Definition: pg_type.h:344

Referenced by DefineAttr().

Typedef Documentation

◆ IndexList

Function Documentation

◆ AllocateAttribute()

static Form_pg_attribute AllocateAttribute ( void  )
static

Definition at line 1031 of file bootstrap.c.

References ATTRIBUTE_FIXED_PART_SIZE, MemoryContextAllocZero(), and TopMemoryContext.

Referenced by boot_openrel(), and DefineAttr().

1032 {
1033  return (Form_pg_attribute)
1035 }
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:728

◆ AuxiliaryProcessMain()

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

Definition at line 195 of file bootstrap.c.

References Assert, 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(), CheckerModeMain(), CheckerProcess, CheckpointerMain(), CheckpointerProcess, CreateDataDirLockFile(), DataDir, 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, ValidatePgVersion(), 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 2 value between 1MB and 1GB")));
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  /* Validate we have been given a reasonable-looking DataDir */
353  Assert(DataDir);
355 
356  /* Change into DataDir (if under postmaster, should be done already) */
357  if (!IsUnderPostmaster)
358  ChangeToDataDir();
359 
360  /* If standalone, create lockfile for data directory */
361  if (!IsUnderPostmaster)
362  CreateDataDirLockFile(false);
363 
365  IgnoreSystemIndexes = true;
366 
367  /* Initialize MaxBackends (if under postmaster, was done already) */
368  if (!IsUnderPostmaster)
370 
371  BaseInit();
372 
373  /*
374  * When we are an auxiliary process, we aren't going to do the full
375  * InitPostgres pushups, but there are a couple of things that need to get
376  * lit up even in an auxiliary process.
377  */
378  if (IsUnderPostmaster)
379  {
380  /*
381  * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
382  * this was already done by SubPostmasterMain().
383  */
384 #ifndef EXEC_BACKEND
386 #endif
387 
388  /*
389  * Assign the ProcSignalSlot for an auxiliary process. Since it
390  * doesn't have a BackendId, the slot is statically allocated based on
391  * the auxiliary process type (MyAuxProcType). Backends use slots
392  * indexed in the range from 1 to MaxBackends (inclusive), so we use
393  * MaxBackends + AuxProcType + 1 as the index of the slot for an
394  * auxiliary process.
395  *
396  * This will need rethinking if we ever want more than one of a
397  * particular auxiliary process type.
398  */
400 
401  /* finish setting up bufmgr.c */
403 
404  /* Initialize backend status information */
406  pgstat_bestart();
407 
408  /* register a before-shutdown callback for LWLock cleanup */
410  }
411 
412  /*
413  * XLOG operations
414  */
416 
417  switch (MyAuxProcType)
418  {
419  case CheckerProcess:
420  /* don't set signals, they're useless here */
421  CheckerModeMain();
422  proc_exit(1); /* should never return */
423 
424  case BootstrapProcess:
425 
426  /*
427  * There was a brief instant during which mode was Normal; this is
428  * okay. We need to be in bootstrap mode during BootStrapXLOG for
429  * the sake of multixact initialization.
430  */
433  BootStrapXLOG();
435  proc_exit(1); /* should never return */
436 
437  case StartupProcess:
438  /* don't set signals, startup process has its own agenda */
440  proc_exit(1); /* should never return */
441 
442  case BgWriterProcess:
443  /* don't set signals, bgwriter has its own agenda */
445  proc_exit(1); /* should never return */
446 
447  case CheckpointerProcess:
448  /* don't set signals, checkpointer has its own agenda */
450  proc_exit(1); /* should never return */
451 
452  case WalWriterProcess:
453  /* don't set signals, walwriter has its own agenda */
454  InitXLOGAccess();
455  WalWriterMain();
456  proc_exit(1); /* should never return */
457 
458  case WalReceiverProcess:
459  /* don't set signals, walreceiver has its own agenda */
460  WalReceiverMain();
461  proc_exit(1); /* should never return */
462 
463  default:
464  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
465  proc_exit(1);
466  }
467 }
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:1063
const char * pgstat_get_backend_desc(BackendType backendType)
Definition: pgstat.c:4044
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:220
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:9397
void StartupProcessMain(void)
Definition: startup.c:179
void ValidatePgVersion(const char *path)
Definition: miscinit.c:1358
#define write_stderr(str)
Definition: parallel.c:182
void proc_exit(int code)
Definition: ipc.c:99
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SetProcessingMode(mode)
Definition: miscadmin.h:373
void BootStrapXLOG(void)
Definition: xlog.c:4996
void BaseInit(void)
Definition: postinit.c:518
bool IgnoreSystemIndexes
Definition: miscinit.c:74
static void bootstrap_signals(void)
Definition: bootstrap.c:538
const char * progname
Definition: pg_standby.c:37
#define PANIC
Definition: elog.h:53
static void BootstrapModeMain(void)
Definition: bootstrap.c:489
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
void WalReceiverMain(void)
Definition: walreceiver.c:188
void pfree(void *pointer)
Definition: mcxt.c:936
int optind
Definition: getopt.c:51
#define ERROR
Definition: elog.h:43
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1081
void InitXLOGAccess(void)
Definition: xlog.c:8169
#define MAXPGPATH
static struct @121 value
int MaxBackends
Definition: globals.c:126
char OutputFileName[MAXPGPATH]
Definition: globals.c:62
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:6700
bool IsUnderPostmaster
Definition: globals.c:101
char * flag(int b)
Definition: test-ctype.c:33
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:320
void ChangeToDataDir(void)
Definition: miscinit.c:116
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:557
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:4717
AuxProcType MyAuxProcType
Definition: bootstrap.c:69
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
#define Assert(condition)
Definition: c.h:680
void InitializeMaxBackends(void)
Definition: postinit.c:496
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:159
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:476
char * DataDir
Definition: globals.c:60
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:4495

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

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

◆ boot_openrel()

void boot_openrel ( char *  relname)

Definition at line 574 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, RelationData::rd_rel, TupleDescAttr, Typ, and TypeRelationId.

575 {
576  int i;
577  struct typmap **app;
578  Relation rel;
579  HeapScanDesc scan;
580  HeapTuple tup;
581 
582  if (strlen(relname) >= NAMEDATALEN)
583  relname[NAMEDATALEN - 1] = '\0';
584 
585  if (Typ == NULL)
586  {
587  /* We can now load the pg_type data */
589  scan = heap_beginscan_catalog(rel, 0, NULL);
590  i = 0;
591  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
592  ++i;
593  heap_endscan(scan);
594  app = Typ = ALLOC(struct typmap *, i + 1);
595  while (i-- > 0)
596  *app++ = ALLOC(struct typmap, 1);
597  *app = NULL;
598  scan = heap_beginscan_catalog(rel, 0, NULL);
599  app = Typ;
600  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
601  {
602  (*app)->am_oid = HeapTupleGetOid(tup);
603  memcpy((char *) &(*app)->am_typ,
604  (char *) GETSTRUCT(tup),
605  sizeof((*app)->am_typ));
606  app++;
607  }
608  heap_endscan(scan);
609  heap_close(rel, NoLock);
610  }
611 
612  if (boot_reldesc != NULL)
613  closerel(NULL);
614 
615  elog(DEBUG4, "open relation %s, attrsize %d",
616  relname, (int) ATTRIBUTE_FIXED_PART_SIZE);
617 
618  boot_reldesc = heap_openrv(makeRangeVar(NULL, relname, -1), NoLock);
619  numattr = boot_reldesc->rd_rel->relnatts;
620  for (i = 0; i < numattr; i++)
621  {
622  if (attrtypes[i] == NULL)
624  memmove((char *) attrtypes[i],
625  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
627 
628  {
630 
631  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
632  i, NameStr(at->attname), at->attlen, at->attnum,
633  at->atttypid);
634  }
635  }
636 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
int numattr
Definition: bootstrap.c:74
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:90
Relation boot_reldesc
Definition: bootstrap.c:71
#define heap_close(r, l)
Definition: heapam.h:97
Form_pg_class rd_rel
Definition: rel.h:114
void closerel(char *name)
Definition: bootstrap.c:643
#define TypeRelationId
Definition: pg_type.h:34
#define DEBUG4
Definition: elog.h:22
#define NAMEDATALEN
#define NoLock
Definition: lockdefs.h:34
#define memmove(d, s, c)
Definition: c.h:1055
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1405
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
static struct typmap ** Typ
Definition: bootstrap.c:161
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1808
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
TupleDesc rd_att
Definition: rel.h:115
Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1318
#define ALLOC(t, c)
Definition: bootstrap.c:53
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:1031
Oid am_oid
Definition: bootstrap.c:157
int i
#define NameStr(name)
Definition: c.h:557
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:700
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 538 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

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

◆ BootstrapModeMain()

static void BootstrapModeMain ( void  )
static

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

490 {
491  int i;
492 
495 
496  /*
497  * Do backend-like initialization for bootstrap mode
498  */
499  InitProcess();
500 
501  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL);
502 
503  /* Initialize stuff for bootstrap-file processing */
504  for (i = 0; i < MAXATTR; i++)
505  {
506  attrtypes[i] = NULL;
507  Nulls[i] = false;
508  }
509 
510  /*
511  * Process bootstrap input.
512  */
514  boot_yyparse();
516 
517  /*
518  * We should now know about all mapped relations, so it's okay to write
519  * out the initial relation mapping files.
520  */
522 
523  /* Clean up and exit */
524  cleanup();
525  proc_exit(0);
526 }
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:538
void CommitTransactionCommand(void)
Definition: xact.c:2745
int boot_yyparse(void)
void proc_exit(int code)
Definition: ipc.c:99
void InitProcess(void)
Definition: proc.c:288
bool IsUnderPostmaster
Definition: globals.c:101
#define MAXATTR
Definition: bootstrap.h:24
static void cleanup(void)
Definition: bootstrap.c:873
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:680
void StartTransactionCommand(void)
Definition: xact.c:2674
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:367
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname)
Definition: postinit.c:559
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 1129 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.

1130 {
1131  for (; ILHead != NULL; ILHead = ILHead->il_next)
1132  {
1133  Relation heap;
1134  Relation ind;
1135 
1136  /* need not bother with locks during bootstrap */
1137  heap = heap_open(ILHead->il_heap, NoLock);
1138  ind = index_open(ILHead->il_ind, NoLock);
1139 
1140  index_build(heap, ind, ILHead->il_info, false, false);
1141 
1142  index_close(ind, NoLock);
1143  heap_close(heap, NoLock);
1144  }
1145 }
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
#define NoLock
Definition: lockdefs.h:34
IndexInfo * il_info
Definition: bootstrap.c:179
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isprimary, bool isreindex)
Definition: index.c:2009
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
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:151

◆ CheckerModeMain()

static void CheckerModeMain ( void  )
static

Definition at line 476 of file bootstrap.c.

References proc_exit().

Referenced by AuxiliaryProcessMain().

477 {
478  proc_exit(0);
479 }
void proc_exit(int code)
Definition: ipc.c:99

◆ cleanup()

static void cleanup ( void  )
static

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

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

◆ closerel()

void closerel ( char *  name)

Definition at line 643 of file bootstrap.c.

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

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

644 {
645  if (name)
646  {
647  if (boot_reldesc)
648  {
649  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
650  elog(ERROR, "close of %s when %s was expected",
652  }
653  else
654  elog(ERROR, "close of %s before any relation was opened",
655  name);
656  }
657 
658  if (boot_reldesc == NULL)
659  elog(ERROR, "no open relation to close");
660  else
661  {
662  elog(DEBUG4, "close relation %s",
665  boot_reldesc = NULL;
666  }
667 }
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:445
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 680 of file bootstrap.c.

References typinfo::align, AllocateAttribute(), typmap::am_oid, typmap::am_typ, Assert, 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.

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

Referenced by DefineAttr().

892 {
893  int i;
894  Relation rel;
895  HeapScanDesc scan;
896  HeapTuple tup;
897  struct typmap **app;
898 
899  if (Typ != NULL)
900  {
901  for (app = Typ; *app != NULL; app++)
902  {
903  if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
904  {
905  Ap = *app;
906  return (*app)->am_oid;
907  }
908  }
909  }
910  else
911  {
912  for (i = 0; i < n_types; i++)
913  {
914  if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
915  return i;
916  }
917  elog(DEBUG4, "external type: %s", type);
919  scan = heap_beginscan_catalog(rel, 0, NULL);
920  i = 0;
921  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
922  ++i;
923  heap_endscan(scan);
924  app = Typ = ALLOC(struct typmap *, i + 1);
925  while (i-- > 0)
926  *app++ = ALLOC(struct typmap, 1);
927  *app = NULL;
928  scan = heap_beginscan_catalog(rel, 0, NULL);
929  app = Typ;
930  while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL)
931  {
932  (*app)->am_oid = HeapTupleGetOid(tup);
933  memmove((char *) &(*app++)->am_typ,
934  (char *) GETSTRUCT(tup),
935  sizeof((*app)->am_typ));
936  }
937  heap_endscan(scan);
938  heap_close(rel, NoLock);
939  return gettype(type);
940  }
941  elog(ERROR, "unrecognized type \"%s\"", type);
942  /* not reached, here to make compiler happy */
943  return 0;
944 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
#define heap_close(r, l)
Definition: heapam.h:97
static struct typmap * Ap
Definition: bootstrap.c:162
#define TypeRelationId
Definition: pg_type.h:34
#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:1055
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1405
static struct typmap ** Typ
Definition: bootstrap.c:161
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1808
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#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:891
Oid am_oid
Definition: bootstrap.c:157
int i
#define NameStr(name)
Definition: c.h:557
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:700

◆ index_register()

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

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

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

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 855 of file bootstrap.c.

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

856 {
857  elog(DEBUG4, "inserting column %d NULL", i);
858  Assert(i >= 0 && i < MAXATTR);
859  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
860  elog(ERROR,
861  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
864  values[i] = PointerGetDatum(NULL);
865  Nulls[i] = true;
866 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:90
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:445
#define MAXATTR
Definition: bootstrap.h:24
TupleDesc rd_att
Definition: rel.h:115
#define Assert(condition)
Definition: c.h:680
static Datum values[MAXATTR]
Definition: bootstrap.c:164
int i
#define NameStr(name)
Definition: c.h:557
#define elog
Definition: elog.h:219
static bool Nulls[MAXATTR]
Definition: bootstrap.c:165

◆ InsertOneTuple()

void InsertOneTuple ( Oid  objectid)

Definition at line 785 of file bootstrap.c.

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

786 {
787  HeapTuple tuple;
788  TupleDesc tupDesc;
789  int i;
790 
791  elog(DEBUG4, "inserting row oid %u, %d columns", objectid, numattr);
792 
793  tupDesc = CreateTupleDesc(numattr,
794  RelationGetForm(boot_reldesc)->relhasoids,
795  attrtypes);
796  tuple = heap_form_tuple(tupDesc, values, Nulls);
797  if (objectid != (Oid) 0)
798  HeapTupleSetOid(tuple, objectid);
799  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
800 
802  heap_freetuple(tuple);
803  elog(DEBUG4, "row inserted");
804 
805  /*
806  * Reset null markers for next tuple
807  */
808  for (i = 0; i < numattr; i++)
809  Nulls[i] = false;
810 }
int numattr
Definition: bootstrap.c:74
#define RelationGetForm(relation)
Definition: rel.h:419
Relation boot_reldesc
Definition: bootstrap.c:71
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
TupleDesc CreateTupleDesc(int natts, bool hasoid, Form_pg_attribute *attrs)
Definition: tupdesc.c:81
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
unsigned int Oid
Definition: postgres_ext.h:31
#define DEBUG4
Definition: elog.h:22
#define HeapTupleSetOid(tuple, oid)
Definition: htup_details.h:703
void pfree(void *pointer)
Definition: mcxt.c:936
Oid simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2958
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 817 of file bootstrap.c.

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

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

◆ MapArrayTypeName()

char* MapArrayTypeName ( const char *  s)

Definition at line 1050 of file bootstrap.c.

References i, NAMEDATALEN, and pstrdup().

1051 {
1052  int i,
1053  j;
1054  char newStr[NAMEDATALEN];
1055 
1056  newStr[0] = '_';
1057  j = 1;
1058  for (i = 0; i < NAMEDATALEN - 2 && s[i] != '['; i++, j++)
1059  newStr[j] = s[i];
1060 
1061  newStr[j] = '\0';
1062 
1063  return pstrdup(newStr);
1064 }
char * pstrdup(const char *in)
Definition: mcxt.c:1063
#define NAMEDATALEN
int i

◆ ShutdownAuxiliaryProcess()

static void ShutdownAuxiliaryProcess ( int  code,
Datum  arg 
)
static

Definition at line 557 of file bootstrap.c.

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

Referenced by AuxiliaryProcessMain().

558 {
562 }
void ConditionVariableCancelSleep(void)
static void pgstat_report_wait_end(void)
Definition: pgstat.h:1244
void LWLockReleaseAll(void)
Definition: lwlock.c:1821

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(), AggregateCreate(), AlterCollation(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterOperator(), AlterPolicy(), AlterPublicationOptions(), AlterSetting(), AlterSubscription(), 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_assign_value(), 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(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), 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(), 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(), pg_ls_dir_files(), pg_prepared_statement(), pg_prepared_xact(), 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(), SetSubscriptionRelState(), shdepAddDependency(), shdepChangeDep(), show_all_file_settings(), show_all_settings(), ShowAllGUCConfig(), slot_deform_tuple(), sql_conn(), ssl_extension_info(), StartReplication(), statext_store(), StoreAttrDefault(), StoreCatalogInheritance1(), StoreIndexTuple(), storeOperators(), StorePartitionKey(), storeProcedures(), tfuncLoadRows(), ts_process_call(), tsvector_unnest(), tt_process_call(), tuple_equals_slot(), TypeCreate(), TypeShellMake(), unique_key_recheck(), update_attstats(), UpdateIndexRelation(), vacuumlo(), validate_index_heapscan(), ValuesNext(), and xpath_table().