PostgreSQL Source Code  git master
postinit.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * postinit.c
4  * postgres initialization utilities
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/utils/init/postinit.c
12  *
13  *
14  *-------------------------------------------------------------------------
15  */
16 #include "postgres.h"
17 
18 #include <ctype.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 
22 #include "access/genam.h"
23 #include "access/heapam.h"
24 #include "access/htup_details.h"
25 #include "access/session.h"
26 #include "access/sysattr.h"
27 #include "access/tableam.h"
28 #include "access/xact.h"
29 #include "access/xlog.h"
30 #include "catalog/catalog.h"
31 #include "catalog/namespace.h"
32 #include "catalog/pg_authid.h"
33 #include "catalog/pg_database.h"
35 #include "catalog/pg_tablespace.h"
36 #include "libpq/auth.h"
37 #include "libpq/libpq-be.h"
38 #include "mb/pg_wchar.h"
39 #include "miscadmin.h"
40 #include "pgstat.h"
41 #include "postmaster/autovacuum.h"
42 #include "postmaster/postmaster.h"
43 #include "replication/walsender.h"
44 #include "storage/bufmgr.h"
45 #include "storage/fd.h"
46 #include "storage/ipc.h"
47 #include "storage/lmgr.h"
48 #include "storage/proc.h"
49 #include "storage/procarray.h"
50 #include "storage/procsignal.h"
51 #include "storage/sinvaladt.h"
52 #include "storage/smgr.h"
53 #include "storage/sync.h"
54 #include "tcop/tcopprot.h"
55 #include "utils/acl.h"
56 #include "utils/fmgroids.h"
57 #include "utils/guc.h"
58 #include "utils/memutils.h"
59 #include "utils/pg_locale.h"
60 #include "utils/portal.h"
61 #include "utils/ps_status.h"
62 #include "utils/snapmgr.h"
63 #include "utils/syscache.h"
64 #include "utils/timeout.h"
65 
66 static HeapTuple GetDatabaseTuple(const char *dbname);
67 static HeapTuple GetDatabaseTupleByOid(Oid dboid);
68 static void PerformAuthentication(Port *port);
69 static void CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connections);
70 static void ShutdownPostgres(int code, Datum arg);
71 static void StatementTimeoutHandler(void);
72 static void LockTimeoutHandler(void);
74 static void IdleSessionTimeoutHandler(void);
75 static void ClientCheckTimeoutHandler(void);
76 static bool ThereIsAtLeastOneRole(void);
77 static void process_startup_options(Port *port, bool am_superuser);
78 static void process_settings(Oid databaseid, Oid roleid);
79 
80 
81 /*** InitPostgres support ***/
82 
83 
84 /*
85  * GetDatabaseTuple -- fetch the pg_database row for a database
86  *
87  * This is used during backend startup when we don't yet have any access to
88  * system catalogs in general. In the worst case, we can seqscan pg_database
89  * using nothing but the hard-wired descriptor that relcache.c creates for
90  * pg_database. In more typical cases, relcache.c was able to load
91  * descriptors for both pg_database and its indexes from the shared relcache
92  * cache file, and so we can do an indexscan. criticalSharedRelcachesBuilt
93  * tells whether we got the cached descriptors.
94  */
95 static HeapTuple
97 {
98  HeapTuple tuple;
99  Relation relation;
100  SysScanDesc scan;
101  ScanKeyData key[1];
102 
103  /*
104  * form a scan key
105  */
106  ScanKeyInit(&key[0],
107  Anum_pg_database_datname,
108  BTEqualStrategyNumber, F_NAMEEQ,
110 
111  /*
112  * Open pg_database and fetch a tuple. Force heap scan if we haven't yet
113  * built the critical shared relcache entries (i.e., we're starting up
114  * without a shared relcache cache file).
115  */
116  relation = table_open(DatabaseRelationId, AccessShareLock);
117  scan = systable_beginscan(relation, DatabaseNameIndexId,
119  NULL,
120  1, key);
121 
122  tuple = systable_getnext(scan);
123 
124  /* Must copy tuple before releasing buffer */
125  if (HeapTupleIsValid(tuple))
126  tuple = heap_copytuple(tuple);
127 
128  /* all done */
129  systable_endscan(scan);
130  table_close(relation, AccessShareLock);
131 
132  return tuple;
133 }
134 
135 /*
136  * GetDatabaseTupleByOid -- as above, but search by database OID
137  */
138 static HeapTuple
140 {
141  HeapTuple tuple;
142  Relation relation;
143  SysScanDesc scan;
144  ScanKeyData key[1];
145 
146  /*
147  * form a scan key
148  */
149  ScanKeyInit(&key[0],
150  Anum_pg_database_oid,
151  BTEqualStrategyNumber, F_OIDEQ,
152  ObjectIdGetDatum(dboid));
153 
154  /*
155  * Open pg_database and fetch a tuple. Force heap scan if we haven't yet
156  * built the critical shared relcache entries (i.e., we're starting up
157  * without a shared relcache cache file).
158  */
159  relation = table_open(DatabaseRelationId, AccessShareLock);
160  scan = systable_beginscan(relation, DatabaseOidIndexId,
162  NULL,
163  1, key);
164 
165  tuple = systable_getnext(scan);
166 
167  /* Must copy tuple before releasing buffer */
168  if (HeapTupleIsValid(tuple))
169  tuple = heap_copytuple(tuple);
170 
171  /* all done */
172  systable_endscan(scan);
173  table_close(relation, AccessShareLock);
174 
175  return tuple;
176 }
177 
178 
179 /*
180  * PerformAuthentication -- authenticate a remote client
181  *
182  * returns: nothing. Will not return at all if there's any failure.
183  */
184 static void
186 {
187  /* This should be set already, but let's make sure */
188  ClientAuthInProgress = true; /* limit visibility of log messages */
189 
190  /*
191  * In EXEC_BACKEND case, we didn't inherit the contents of pg_hba.conf
192  * etcetera from the postmaster, and have to load them ourselves.
193  *
194  * FIXME: [fork/exec] Ugh. Is there a way around this overhead?
195  */
196 #ifdef EXEC_BACKEND
197 
198  /*
199  * load_hba() and load_ident() want to work within the PostmasterContext,
200  * so create that if it doesn't exist (which it won't). We'll delete it
201  * again later, in PostgresMain.
202  */
203  if (PostmasterContext == NULL)
205  "Postmaster",
207 
208  if (!load_hba())
209  {
210  /*
211  * It makes no sense to continue if we fail to load the HBA file,
212  * since there is no way to connect to the database in this case.
213  */
214  ereport(FATAL,
215  (errmsg("could not load pg_hba.conf")));
216  }
217 
218  if (!load_ident())
219  {
220  /*
221  * It is ok to continue if we fail to load the IDENT file, although it
222  * means that you cannot log in using any of the authentication
223  * methods that need a user name mapping. load_ident() already logged
224  * the details of error to the log.
225  */
226  }
227 #endif
228 
229  /*
230  * Set up a timeout in case a buggy or malicious client fails to respond
231  * during authentication. Since we're inside a transaction and might do
232  * database access, we have to use the statement_timeout infrastructure.
233  */
235 
236  /*
237  * Now perform authentication exchange.
238  */
239  set_ps_display("authentication");
240  ClientAuthentication(port); /* might not return, if failure */
241 
242  /*
243  * Done with authentication. Disable the timeout, and log if needed.
244  */
246 
247  if (Log_connections)
248  {
249  StringInfoData logmsg;
250 
251  initStringInfo(&logmsg);
252  if (am_walsender)
253  appendStringInfo(&logmsg, _("replication connection authorized: user=%s"),
254  port->user_name);
255  else
256  appendStringInfo(&logmsg, _("connection authorized: user=%s"),
257  port->user_name);
258  if (!am_walsender)
259  appendStringInfo(&logmsg, _(" database=%s"), port->database_name);
260 
261  if (port->application_name != NULL)
262  appendStringInfo(&logmsg, _(" application_name=%s"),
263  port->application_name);
264 
265 #ifdef USE_SSL
266  if (port->ssl_in_use)
267  appendStringInfo(&logmsg, _(" SSL enabled (protocol=%s, cipher=%s, bits=%d)"),
271 #endif
272 #ifdef ENABLE_GSS
273  if (port->gss)
274  {
275  const char *princ = be_gssapi_get_princ(port);
276 
277  if (princ)
278  appendStringInfo(&logmsg,
279  _(" GSS (authenticated=%s, encrypted=%s, principal=%s)"),
280  be_gssapi_get_auth(port) ? _("yes") : _("no"),
281  be_gssapi_get_enc(port) ? _("yes") : _("no"),
282  princ);
283  else
284  appendStringInfo(&logmsg,
285  _(" GSS (authenticated=%s, encrypted=%s)"),
286  be_gssapi_get_auth(port) ? _("yes") : _("no"),
287  be_gssapi_get_enc(port) ? _("yes") : _("no"));
288  }
289 #endif
290 
291  ereport(LOG, errmsg_internal("%s", logmsg.data));
292  pfree(logmsg.data);
293  }
294 
295  set_ps_display("startup");
296 
297  ClientAuthInProgress = false; /* client_min_messages is active now */
298 }
299 
300 
301 /*
302  * CheckMyDatabase -- fetch information from the pg_database entry for our DB
303  */
304 static void
305 CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connections)
306 {
307  HeapTuple tup;
308  Form_pg_database dbform;
309  char *collate;
310  char *ctype;
311 
312  /* Fetch our pg_database row normally, via syscache */
314  if (!HeapTupleIsValid(tup))
315  elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
316  dbform = (Form_pg_database) GETSTRUCT(tup);
317 
318  /* This recheck is strictly paranoia */
319  if (strcmp(name, NameStr(dbform->datname)) != 0)
320  ereport(FATAL,
321  (errcode(ERRCODE_UNDEFINED_DATABASE),
322  errmsg("database \"%s\" has disappeared from pg_database",
323  name),
324  errdetail("Database OID %u now seems to belong to \"%s\".",
325  MyDatabaseId, NameStr(dbform->datname))));
326 
327  /*
328  * Check permissions to connect to the database.
329  *
330  * These checks are not enforced when in standalone mode, so that there is
331  * a way to recover from disabling all access to all databases, for
332  * example "UPDATE pg_database SET datallowconn = false;".
333  *
334  * We do not enforce them for autovacuum worker processes either.
335  */
337  {
338  /*
339  * Check that the database is currently allowing connections.
340  */
341  if (!dbform->datallowconn && !override_allow_connections)
342  ereport(FATAL,
343  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
344  errmsg("database \"%s\" is not currently accepting connections",
345  name)));
346 
347  /*
348  * Check privilege to connect to the database. (The am_superuser test
349  * is redundant, but since we have the flag, might as well check it
350  * and save a few cycles.)
351  */
352  if (!am_superuser &&
355  ereport(FATAL,
356  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
357  errmsg("permission denied for database \"%s\"", name),
358  errdetail("User does not have CONNECT privilege.")));
359 
360  /*
361  * Check connection limit for this database.
362  *
363  * There is a race condition here --- we create our PGPROC before
364  * checking for other PGPROCs. If two backends did this at about the
365  * same time, they might both think they were over the limit, while
366  * ideally one should succeed and one fail. Getting that to work
367  * exactly seems more trouble than it is worth, however; instead we
368  * just document that the connection limit is approximate.
369  */
370  if (dbform->datconnlimit >= 0 &&
371  !am_superuser &&
372  CountDBConnections(MyDatabaseId) > dbform->datconnlimit)
373  ereport(FATAL,
374  (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
375  errmsg("too many connections for database \"%s\"",
376  name)));
377  }
378 
379  /*
380  * OK, we're golden. Next to-do item is to save the encoding info out of
381  * the pg_database tuple.
382  */
383  SetDatabaseEncoding(dbform->encoding);
384  /* Record it as a GUC internal option, too */
385  SetConfigOption("server_encoding", GetDatabaseEncodingName(),
387  /* If we have no other source of client_encoding, use server encoding */
388  SetConfigOption("client_encoding", GetDatabaseEncodingName(),
390 
391  /* assign locale variables */
392  collate = NameStr(dbform->datcollate);
393  ctype = NameStr(dbform->datctype);
394 
395  if (pg_perm_setlocale(LC_COLLATE, collate) == NULL)
396  ereport(FATAL,
397  (errmsg("database locale is incompatible with operating system"),
398  errdetail("The database was initialized with LC_COLLATE \"%s\", "
399  " which is not recognized by setlocale().", collate),
400  errhint("Recreate the database with another locale or install the missing locale.")));
401 
402  if (pg_perm_setlocale(LC_CTYPE, ctype) == NULL)
403  ereport(FATAL,
404  (errmsg("database locale is incompatible with operating system"),
405  errdetail("The database was initialized with LC_CTYPE \"%s\", "
406  " which is not recognized by setlocale().", ctype),
407  errhint("Recreate the database with another locale or install the missing locale.")));
408 
409  /* Make the locale settings visible as GUC variables, too */
410  SetConfigOption("lc_collate", collate, PGC_INTERNAL, PGC_S_OVERRIDE);
411  SetConfigOption("lc_ctype", ctype, PGC_INTERNAL, PGC_S_OVERRIDE);
412 
414 
415  ReleaseSysCache(tup);
416 }
417 
418 
419 /*
420  * pg_split_opts -- split a string of options and append it to an argv array
421  *
422  * The caller is responsible for ensuring the argv array is large enough. The
423  * maximum possible number of arguments added by this routine is
424  * (strlen(optstr) + 1) / 2.
425  *
426  * Because some option values can contain spaces we allow escaping using
427  * backslashes, with \\ representing a literal backslash.
428  */
429 void
430 pg_split_opts(char **argv, int *argcp, const char *optstr)
431 {
432  StringInfoData s;
433 
434  initStringInfo(&s);
435 
436  while (*optstr)
437  {
438  bool last_was_escape = false;
439 
440  resetStringInfo(&s);
441 
442  /* skip over leading space */
443  while (isspace((unsigned char) *optstr))
444  optstr++;
445 
446  if (*optstr == '\0')
447  break;
448 
449  /*
450  * Parse a single option, stopping at the first space, unless it's
451  * escaped.
452  */
453  while (*optstr)
454  {
455  if (isspace((unsigned char) *optstr) && !last_was_escape)
456  break;
457 
458  if (!last_was_escape && *optstr == '\\')
459  last_was_escape = true;
460  else
461  {
462  last_was_escape = false;
463  appendStringInfoChar(&s, *optstr);
464  }
465 
466  optstr++;
467  }
468 
469  /* now store the option in the next argv[] position */
470  argv[(*argcp)++] = pstrdup(s.data);
471  }
472 
473  pfree(s.data);
474 }
475 
476 /*
477  * Initialize MaxBackends value from config options.
478  *
479  * This must be called after modules have had the chance to register background
480  * workers in shared_preload_libraries, and before shared memory size is
481  * determined.
482  *
483  * Note that in EXEC_BACKEND environment, the value is passed down from
484  * postmaster to subprocesses via BackendParameters in SubPostmasterMain; only
485  * postmaster itself and processes not under postmaster control should call
486  * this.
487  */
488 void
490 {
491  Assert(MaxBackends == 0);
492 
493  /* the extra unit accounts for the autovacuum launcher */
496 
497  /* internal error because the values were all checked previously */
499  elog(ERROR, "too many backends configured");
500 }
501 
502 /*
503  * Early initialization of a backend (either standalone or under postmaster).
504  * This happens even before InitPostgres.
505  *
506  * This is separate from InitPostgres because it is also called by auxiliary
507  * processes, such as the background writer process, which may not call
508  * InitPostgres at all.
509  */
510 void
511 BaseInit(void)
512 {
513  Assert(MyProc != NULL);
514 
515  /*
516  * Initialize our input/output/debugging file descriptors.
517  */
518  DebugFileOpen();
519 
520  /*
521  * Initialize file access. Done early so other subsystems can access
522  * files.
523  */
524  InitFileAccess();
525 
526  /*
527  * Initialize statistics reporting. This needs to happen early to ensure
528  * that pgstat's shutdown callback runs after the shutdown callbacks of
529  * all subsystems that can produce stats (like e.g. transaction commits
530  * can).
531  */
533 
534  /* Do local initialization of storage and buffer managers */
535  InitSync();
536  smgrinit();
538 
539  /*
540  * Initialize temporary file access after pgstat, so that the temporary
541  * file shutdown hook can report temporary file statistics.
542  */
544 
545  /*
546  * Initialize local buffers for WAL record construction, in case we
547  * ever try to insert XLOG.
548  */
549  InitXLogInsert();
550 }
551 
552 
553 /* --------------------------------
554  * InitPostgres
555  * Initialize POSTGRES.
556  *
557  * The database can be specified by name, using the in_dbname parameter, or by
558  * OID, using the dboid parameter. In the latter case, the actual database
559  * name can be returned to the caller in out_dbname. If out_dbname isn't
560  * NULL, it must point to a buffer of size NAMEDATALEN.
561  *
562  * Similarly, the username can be passed by name, using the username parameter,
563  * or by OID using the useroid parameter.
564  *
565  * In bootstrap mode no parameters are used. The autovacuum launcher process
566  * doesn't use any parameters either, because it only goes far enough to be
567  * able to read pg_database; it doesn't connect to any particular database.
568  * In walsender mode only username is used.
569  *
570  * As of PostgreSQL 8.2, we expect InitProcess() was already called, so we
571  * already have a PGPROC struct ... but it's not completely filled in yet.
572  *
573  * Note:
574  * Be very careful with the order of calls in the InitPostgres function.
575  * --------------------------------
576  */
577 void
578 InitPostgres(const char *in_dbname, Oid dboid, const char *username,
579  Oid useroid, char *out_dbname, bool override_allow_connections)
580 {
581  bool bootstrap = IsBootstrapProcessingMode();
582  bool am_superuser;
583  char *fullpath;
584  char dbname[NAMEDATALEN];
585 
586  elog(DEBUG3, "InitPostgres");
587 
588  /*
589  * Add my PGPROC struct to the ProcArray.
590  *
591  * Once I have done this, I am visible to other backends!
592  */
594 
595  /*
596  * Initialize my entry in the shared-invalidation manager's array of
597  * per-backend data.
598  *
599  * Sets up MyBackendId, a unique backend identifier.
600  */
602 
603  SharedInvalBackendInit(false);
604 
605  if (MyBackendId > MaxBackends || MyBackendId <= 0)
606  elog(FATAL, "bad backend ID: %d", MyBackendId);
607 
608  /* Now that we have a BackendId, we can participate in ProcSignal */
610 
611  /*
612  * Also set up timeout handlers needed for backend operation. We need
613  * these in every case except bootstrap.
614  */
615  if (!bootstrap)
616  {
624  }
625 
626  /*
627  * If this is either a bootstrap process nor a standalone backend, start
628  * up the XLOG machinery, and register to have it closed down at exit.
629  * In other cases, the startup process is responsible for starting up
630  * the XLOG machinery, and the checkpointer for closing it down.
631  */
632  if (!IsUnderPostmaster)
633  {
634  /*
635  * We don't yet have an aux-process resource owner, but StartupXLOG
636  * and ShutdownXLOG will need one. Hence, create said resource owner
637  * (and register a callback to clean it up after ShutdownXLOG runs).
638  */
640 
641  StartupXLOG();
642  /* Release (and warn about) any buffer pins leaked in StartupXLOG */
644  /* Reset CurrentResourceOwner to nothing for the moment */
645  CurrentResourceOwner = NULL;
646 
647  /*
648  * Use before_shmem_exit() so that ShutdownXLOG() can rely on DSM
649  * segments etc to work (which in turn is required for pgstats).
650  */
652  }
653 
654  /*
655  * Initialize the relation cache and the system catalog caches. Note that
656  * no catalog access happens here; we only set up the hashtable structure.
657  * We must do this before starting a transaction because transaction abort
658  * would try to touch these hashtables.
659  */
662  InitPlanCache();
663 
664  /* Initialize portal manager */
666 
667  /* Initialize status reporting */
668  pgstat_beinit();
669 
670  /*
671  * Load relcache entries for the shared system catalogs. This must create
672  * at least entries for pg_database and catalogs used for authentication.
673  */
675 
676  /*
677  * Set up process-exit callback to do pre-shutdown cleanup. This is the
678  * one of the first before_shmem_exit callbacks we register; thus, this
679  * will be one the last things we do before low-level modules like the
680  * buffer manager begin to close down. We need to have this in place
681  * before we begin our first transaction --- if we fail during the
682  * initialization transaction, as is entirely possible, we need the
683  * AbortTransaction call to clean up.
684  */
686 
687  /* The autovacuum launcher is done here */
689  {
690  /* report this backend in the PgBackendStatus array */
691  pgstat_bestart();
692 
693  return;
694  }
695 
696  /*
697  * Start a new transaction here before first access to db, and get a
698  * snapshot. We don't have a use for the snapshot itself, but we're
699  * interested in the secondary effect that it sets RecentGlobalXmin. (This
700  * is critical for anything that reads heap pages, because HOT may decide
701  * to prune them even if the process doesn't attempt to modify any
702  * tuples.)
703  *
704  * FIXME: This comment is inaccurate / the code buggy. A snapshot that is
705  * not pushed/active does not reliably prevent HOT pruning (->xmin could
706  * e.g. be cleared when cache invalidations are processed).
707  */
708  if (!bootstrap)
709  {
710  /* statement_timestamp must be set for timeouts to work correctly */
713 
714  /*
715  * transaction_isolation will have been set to the default by the
716  * above. If the default is "serializable", and we are in hot
717  * standby, we will fail if we don't change it to something lower.
718  * Fortunately, "read committed" is plenty good enough.
719  */
721 
722  (void) GetTransactionSnapshot();
723  }
724 
725  /*
726  * Perform client authentication if necessary, then figure out our
727  * postgres user ID, and see if we are a superuser.
728  *
729  * In standalone mode and in autovacuum worker processes, we use a fixed
730  * ID, otherwise we figure it out from the authenticated user name.
731  */
732  if (bootstrap || IsAutoVacuumWorkerProcess())
733  {
735  am_superuser = true;
736  }
737  else if (!IsUnderPostmaster)
738  {
740  am_superuser = true;
741  if (!ThereIsAtLeastOneRole())
743  (errcode(ERRCODE_UNDEFINED_OBJECT),
744  errmsg("no roles are defined in this database system"),
745  errhint("You should immediately run CREATE USER \"%s\" SUPERUSER;.",
746  username != NULL ? username : "postgres")));
747  }
748  else if (IsBackgroundWorker)
749  {
750  if (username == NULL && !OidIsValid(useroid))
751  {
753  am_superuser = true;
754  }
755  else
756  {
758  am_superuser = superuser();
759  }
760  }
761  else
762  {
763  /* normal multiuser case */
764  Assert(MyProcPort != NULL);
767  am_superuser = superuser();
768  }
769 
770  /*
771  * If we're trying to shut down, only superusers can connect, and new
772  * replication connections are not allowed.
773  */
774  if ((!am_superuser || am_walsender) &&
775  MyProcPort != NULL &&
777  {
778  if (am_walsender)
779  ereport(FATAL,
780  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
781  errmsg("new replication connections are not allowed during database shutdown")));
782  else
783  ereport(FATAL,
784  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
785  errmsg("must be superuser to connect during database shutdown")));
786  }
787 
788  /*
789  * Binary upgrades only allowed super-user connections
790  */
791  if (IsBinaryUpgrade && !am_superuser)
792  {
793  ereport(FATAL,
794  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
795  errmsg("must be superuser to connect in binary upgrade mode")));
796  }
797 
798  /*
799  * The last few connection slots are reserved for superusers. Replication
800  * connections are drawn from slots reserved with max_wal_senders and not
801  * limited by max_connections or superuser_reserved_connections.
802  */
803  if (!am_superuser && !am_walsender &&
804  ReservedBackends > 0 &&
806  ereport(FATAL,
807  (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
808  errmsg("remaining connection slots are reserved for non-replication superuser connections")));
809 
810  /* Check replication permissions needed for walsender processes. */
811  if (am_walsender)
812  {
813  Assert(!bootstrap);
814 
815  if (!superuser() && !has_rolreplication(GetUserId()))
816  ereport(FATAL,
817  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
818  errmsg("must be superuser or replication role to start walsender")));
819  }
820 
821  /*
822  * If this is a plain walsender only supporting physical replication, we
823  * don't want to connect to any particular database. Just finish the
824  * backend startup by processing any options from the startup packet, and
825  * we're done.
826  */
828  {
829  /* process any options passed in the startup packet */
830  if (MyProcPort != NULL)
831  process_startup_options(MyProcPort, am_superuser);
832 
833  /* Apply PostAuthDelay as soon as we've read all options */
834  if (PostAuthDelay > 0)
835  pg_usleep(PostAuthDelay * 1000000L);
836 
837  /* initialize client encoding */
839 
840  /* report this backend in the PgBackendStatus array */
841  pgstat_bestart();
842 
843  /* close the transaction we started above */
845 
846  return;
847  }
848 
849  /*
850  * Set up the global variables holding database id and default tablespace.
851  * But note we won't actually try to touch the database just yet.
852  *
853  * We take a shortcut in the bootstrap case, otherwise we have to look up
854  * the db's entry in pg_database.
855  */
856  if (bootstrap)
857  {
858  MyDatabaseId = TemplateDbOid;
859  MyDatabaseTableSpace = DEFAULTTABLESPACE_OID;
860  }
861  else if (in_dbname != NULL)
862  {
863  HeapTuple tuple;
864  Form_pg_database dbform;
865 
866  tuple = GetDatabaseTuple(in_dbname);
867  if (!HeapTupleIsValid(tuple))
868  ereport(FATAL,
869  (errcode(ERRCODE_UNDEFINED_DATABASE),
870  errmsg("database \"%s\" does not exist", in_dbname)));
871  dbform = (Form_pg_database) GETSTRUCT(tuple);
872  MyDatabaseId = dbform->oid;
873  MyDatabaseTableSpace = dbform->dattablespace;
874  /* take database name from the caller, just for paranoia */
875  strlcpy(dbname, in_dbname, sizeof(dbname));
876  }
877  else if (OidIsValid(dboid))
878  {
879  /* caller specified database by OID */
880  HeapTuple tuple;
881  Form_pg_database dbform;
882 
883  tuple = GetDatabaseTupleByOid(dboid);
884  if (!HeapTupleIsValid(tuple))
885  ereport(FATAL,
886  (errcode(ERRCODE_UNDEFINED_DATABASE),
887  errmsg("database %u does not exist", dboid)));
888  dbform = (Form_pg_database) GETSTRUCT(tuple);
889  MyDatabaseId = dbform->oid;
890  MyDatabaseTableSpace = dbform->dattablespace;
891  Assert(MyDatabaseId == dboid);
892  strlcpy(dbname, NameStr(dbform->datname), sizeof(dbname));
893  /* pass the database name back to the caller */
894  if (out_dbname)
895  strcpy(out_dbname, dbname);
896  }
897  else
898  {
899  /*
900  * If this is a background worker not bound to any particular
901  * database, we're done now. Everything that follows only makes sense
902  * if we are bound to a specific database. We do need to close the
903  * transaction we started before returning.
904  */
905  if (!bootstrap)
906  {
907  pgstat_bestart();
909  }
910  return;
911  }
912 
913  /*
914  * Now, take a writer's lock on the database we are trying to connect to.
915  * If there is a concurrently running DROP DATABASE on that database, this
916  * will block us until it finishes (and has committed its update of
917  * pg_database).
918  *
919  * Note that the lock is not held long, only until the end of this startup
920  * transaction. This is OK since we will advertise our use of the
921  * database in the ProcArray before dropping the lock (in fact, that's the
922  * next thing to do). Anyone trying a DROP DATABASE after this point will
923  * see us in the array once they have the lock. Ordering is important for
924  * this because we don't want to advertise ourselves as being in this
925  * database until we have the lock; otherwise we create what amounts to a
926  * deadlock with CountOtherDBBackends().
927  *
928  * Note: use of RowExclusiveLock here is reasonable because we envision
929  * our session as being a concurrent writer of the database. If we had a
930  * way of declaring a session as being guaranteed-read-only, we could use
931  * AccessShareLock for such sessions and thereby not conflict against
932  * CREATE DATABASE.
933  */
934  if (!bootstrap)
935  LockSharedObject(DatabaseRelationId, MyDatabaseId, 0,
937 
938  /*
939  * Now we can mark our PGPROC entry with the database ID.
940  *
941  * We assume this is an atomic store so no lock is needed; though actually
942  * things would work fine even if it weren't atomic. Anyone searching the
943  * ProcArray for this database's ID should hold the database lock, so they
944  * would not be executing concurrently with this store. A process looking
945  * for another database's ID could in theory see a chance match if it read
946  * a partially-updated databaseId value; but as long as all such searches
947  * wait and retry, as in CountOtherDBBackends(), they will certainly see
948  * the correct value on their next try.
949  */
951 
952  /*
953  * We established a catalog snapshot while reading pg_authid and/or
954  * pg_database; but until we have set up MyDatabaseId, we won't react to
955  * incoming sinval messages for unshared catalogs, so we won't realize it
956  * if the snapshot has been invalidated. Assume it's no good anymore.
957  */
959 
960  /*
961  * Recheck pg_database to make sure the target database hasn't gone away.
962  * If there was a concurrent DROP DATABASE, this ensures we will die
963  * cleanly without creating a mess.
964  */
965  if (!bootstrap)
966  {
967  HeapTuple tuple;
968 
969  tuple = GetDatabaseTuple(dbname);
970  if (!HeapTupleIsValid(tuple) ||
971  MyDatabaseId != ((Form_pg_database) GETSTRUCT(tuple))->oid ||
972  MyDatabaseTableSpace != ((Form_pg_database) GETSTRUCT(tuple))->dattablespace)
973  ereport(FATAL,
974  (errcode(ERRCODE_UNDEFINED_DATABASE),
975  errmsg("database \"%s\" does not exist", dbname),
976  errdetail("It seems to have just been dropped or renamed.")));
977  }
978 
979  /*
980  * Now we should be able to access the database directory safely. Verify
981  * it's there and looks reasonable.
982  */
984 
985  if (!bootstrap)
986  {
987  if (access(fullpath, F_OK) == -1)
988  {
989  if (errno == ENOENT)
990  ereport(FATAL,
991  (errcode(ERRCODE_UNDEFINED_DATABASE),
992  errmsg("database \"%s\" does not exist",
993  dbname),
994  errdetail("The database subdirectory \"%s\" is missing.",
995  fullpath)));
996  else
997  ereport(FATAL,
999  errmsg("could not access directory \"%s\": %m",
1000  fullpath)));
1001  }
1002 
1003  ValidatePgVersion(fullpath);
1004  }
1005 
1006  SetDatabasePath(fullpath);
1007 
1008  /*
1009  * It's now possible to do real access to the system catalogs.
1010  *
1011  * Load relcache entries for the system catalogs. This must create at
1012  * least the minimum set of "nailed-in" cache entries.
1013  */
1015 
1016  /* set up ACL framework (so CheckMyDatabase can check permissions) */
1017  initialize_acl();
1018 
1019  /*
1020  * Re-read the pg_database row for our database, check permissions and set
1021  * up database-specific GUC settings. We can't do this until all the
1022  * database-access infrastructure is up. (Also, it wants to know if the
1023  * user is a superuser, so the above stuff has to happen first.)
1024  */
1025  if (!bootstrap)
1026  CheckMyDatabase(dbname, am_superuser, override_allow_connections);
1027 
1028  /*
1029  * Now process any command-line switches and any additional GUC variable
1030  * settings passed in the startup packet. We couldn't do this before
1031  * because we didn't know if client is a superuser.
1032  */
1033  if (MyProcPort != NULL)
1034  process_startup_options(MyProcPort, am_superuser);
1035 
1036  /* Process pg_db_role_setting options */
1038 
1039  /* Apply PostAuthDelay as soon as we've read all options */
1040  if (PostAuthDelay > 0)
1041  pg_usleep(PostAuthDelay * 1000000L);
1042 
1043  /*
1044  * Initialize various default states that can't be set up until we've
1045  * selected the active user and gotten the right GUC settings.
1046  */
1047 
1048  /* set default namespace search path */
1050 
1051  /* initialize client encoding */
1053 
1054  /* Initialize this backend's session state. */
1056 
1057  /* report this backend in the PgBackendStatus array */
1058  if (!bootstrap)
1059  pgstat_bestart();
1060 
1061  /* close the transaction we started above */
1062  if (!bootstrap)
1064 }
1065 
1066 /*
1067  * Process any command-line switches and any additional GUC variable
1068  * settings passed in the startup packet.
1069  */
1070 static void
1071 process_startup_options(Port *port, bool am_superuser)
1072 {
1073  GucContext gucctx;
1074  ListCell *gucopts;
1075 
1076  gucctx = am_superuser ? PGC_SU_BACKEND : PGC_BACKEND;
1077 
1078  /*
1079  * First process any command-line switches that were included in the
1080  * startup packet, if we are in a regular backend.
1081  */
1082  if (port->cmdline_options != NULL)
1083  {
1084  /*
1085  * The maximum possible number of commandline arguments that could
1086  * come from port->cmdline_options is (strlen + 1) / 2; see
1087  * pg_split_opts().
1088  */
1089  char **av;
1090  int maxac;
1091  int ac;
1092 
1093  maxac = 2 + (strlen(port->cmdline_options) + 1) / 2;
1094 
1095  av = (char **) palloc(maxac * sizeof(char *));
1096  ac = 0;
1097 
1098  av[ac++] = "postgres";
1099 
1100  pg_split_opts(av, &ac, port->cmdline_options);
1101 
1102  av[ac] = NULL;
1103 
1104  Assert(ac < maxac);
1105 
1106  (void) process_postgres_switches(ac, av, gucctx, NULL);
1107  }
1108 
1109  /*
1110  * Process any additional GUC variable settings passed in startup packet.
1111  * These are handled exactly like command-line variables.
1112  */
1113  gucopts = list_head(port->guc_options);
1114  while (gucopts)
1115  {
1116  char *name;
1117  char *value;
1118 
1119  name = lfirst(gucopts);
1120  gucopts = lnext(port->guc_options, gucopts);
1121 
1122  value = lfirst(gucopts);
1123  gucopts = lnext(port->guc_options, gucopts);
1124 
1126  }
1127 }
1128 
1129 /*
1130  * Load GUC settings from pg_db_role_setting.
1131  *
1132  * We try specific settings for the database/role combination, as well as
1133  * general for this database and for this user.
1134  */
1135 static void
1136 process_settings(Oid databaseid, Oid roleid)
1137 {
1138  Relation relsetting;
1139  Snapshot snapshot;
1140 
1141  if (!IsUnderPostmaster)
1142  return;
1143 
1144  relsetting = table_open(DbRoleSettingRelationId, AccessShareLock);
1145 
1146  /* read all the settings under the same snapshot for efficiency */
1147  snapshot = RegisterSnapshot(GetCatalogSnapshot(DbRoleSettingRelationId));
1148 
1149  /* Later settings are ignored if set earlier. */
1150  ApplySetting(snapshot, databaseid, roleid, relsetting, PGC_S_DATABASE_USER);
1151  ApplySetting(snapshot, InvalidOid, roleid, relsetting, PGC_S_USER);
1152  ApplySetting(snapshot, databaseid, InvalidOid, relsetting, PGC_S_DATABASE);
1153  ApplySetting(snapshot, InvalidOid, InvalidOid, relsetting, PGC_S_GLOBAL);
1154 
1155  UnregisterSnapshot(snapshot);
1156  table_close(relsetting, AccessShareLock);
1157 }
1158 
1159 /*
1160  * Backend-shutdown callback. Do cleanup that we want to be sure happens
1161  * before all the supporting modules begin to nail their doors shut via
1162  * their own callbacks.
1163  *
1164  * User-level cleanup, such as temp-relation removal and UNLISTEN, happens
1165  * via separate callbacks that execute before this one. We don't combine the
1166  * callbacks because we still want this one to happen if the user-level
1167  * cleanup fails.
1168  */
1169 static void
1171 {
1172  /* Make sure we've killed any active transaction */
1174 
1175  /*
1176  * User locks are not released by transaction end, so be sure to release
1177  * them explicitly.
1178  */
1180 }
1181 
1182 
1183 /*
1184  * STATEMENT_TIMEOUT handler: trigger a query-cancel interrupt.
1185  */
1186 static void
1188 {
1189  int sig = SIGINT;
1190 
1191  /*
1192  * During authentication the timeout is used to deal with
1193  * authentication_timeout - we want to quit in response to such timeouts.
1194  */
1196  sig = SIGTERM;
1197 
1198 #ifdef HAVE_SETSID
1199  /* try to signal whole process group */
1200  kill(-MyProcPid, sig);
1201 #endif
1202  kill(MyProcPid, sig);
1203 }
1204 
1205 /*
1206  * LOCK_TIMEOUT handler: trigger a query-cancel interrupt.
1207  */
1208 static void
1210 {
1211 #ifdef HAVE_SETSID
1212  /* try to signal whole process group */
1213  kill(-MyProcPid, SIGINT);
1214 #endif
1215  kill(MyProcPid, SIGINT);
1216 }
1217 
1218 static void
1220 {
1222  InterruptPending = true;
1223  SetLatch(MyLatch);
1224 }
1225 
1226 static void
1228 {
1230  InterruptPending = true;
1231  SetLatch(MyLatch);
1232 }
1233 
1234 static void
1236 {
1238  InterruptPending = true;
1239  SetLatch(MyLatch);
1240 }
1241 
1242 /*
1243  * Returns true if at least one role is defined in this database cluster.
1244  */
1245 static bool
1247 {
1248  Relation pg_authid_rel;
1249  TableScanDesc scan;
1250  bool result;
1251 
1252  pg_authid_rel = table_open(AuthIdRelationId, AccessShareLock);
1253 
1254  scan = table_beginscan_catalog(pg_authid_rel, 0, NULL);
1255  result = (heap_getnext(scan, ForwardScanDirection) != NULL);
1256 
1257  table_endscan(scan);
1258  table_close(pg_authid_rel, AccessShareLock);
1259 
1260  return result;
1261 }
void initialize_acl(void)
Definition: acl.c:4648
@ ACLCHECK_OK
Definition: acl.h:179
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4708
void ClientAuthentication(Port *port)
Definition: auth.c:385
int autovacuum_max_workers
Definition: autovacuum.c:115
bool IsAutoVacuumLauncherProcess(void)
Definition: autovacuum.c:3405
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3411
void pgstat_beinit(void)
void pgstat_bestart(void)
#define InvalidBackendId
Definition: backendid.h:23
bool be_gssapi_get_auth(Port *port)
bool be_gssapi_get_enc(Port *port)
const char * be_gssapi_get_princ(Port *port)
const char * be_tls_get_version(Port *port)
int be_tls_get_cipher_bits(Port *port)
const char * be_tls_get_cipher(Port *port)
void InitBufferPoolAccess(void)
Definition: bufmgr.c:2596
#define NameStr(name)
Definition: c.h:681
#define OidIsValid(objectId)
Definition: c.h:710
int errmsg_internal(const char *fmt,...)
Definition: elog.c:991
void DebugFileOpen(void)
Definition: elog.c:1917
int errcode_for_file_access(void)
Definition: elog.c:716
int errdetail(const char *fmt,...)
Definition: elog.c:1037
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define _(x)
Definition: elog.c:89
#define LOG
Definition: elog.h:25
#define DEBUG3
Definition: elog.h:22
#define FATAL
Definition: elog.h:35
#define WARNING
Definition: elog.h:30
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
void InitFileAccess(void)
Definition: fd.c:883
void InitTemporaryFileAccess(void)
Definition: fd.c:913
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:598
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:505
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:386
volatile sig_atomic_t InterruptPending
Definition: globals.c:30
volatile sig_atomic_t IdleSessionTimeoutPending
Definition: globals.c:36
bool IsBinaryUpgrade
Definition: globals.c:113
volatile sig_atomic_t IdleInTransactionSessionTimeoutPending
Definition: globals.c:35
int MyProcPid
Definition: globals.c:43
bool IsUnderPostmaster
Definition: globals.c:112
int MaxConnections
Definition: globals.c:136
bool IsBackgroundWorker
Definition: globals.c:114
BackendId MyBackendId
Definition: globals.c:84
Oid MyDatabaseTableSpace
Definition: globals.c:90
int MaxBackends
Definition: globals.c:139
struct Port * MyProcPort
Definition: globals.c:46
struct Latch * MyLatch
Definition: globals.c:57
volatile sig_atomic_t CheckClientConnectionPending
Definition: globals.c:33
int max_worker_processes
Definition: globals.c:137
Oid MyDatabaseId
Definition: globals.c:88
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8141
@ PGC_S_DYNAMIC_DEFAULT
Definition: guc.h:107
@ PGC_S_GLOBAL
Definition: guc.h:111
@ PGC_S_DATABASE
Definition: guc.h:112
@ PGC_S_OVERRIDE
Definition: guc.h:116
@ PGC_S_CLIENT
Definition: guc.h:115
@ PGC_S_DATABASE_USER
Definition: guc.h:114
@ PGC_S_USER
Definition: guc.h:113
GucContext
Definition: guc.h:69
@ PGC_INTERNAL
Definition: guc.h:70
@ PGC_SU_BACKEND
Definition: guc.h:73
@ PGC_BACKEND
Definition: guc.h:74
bool load_ident(void)
Definition: hba.c:3029
bool load_hba(void)
Definition: hba.c:2235
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1340
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
static struct @142 value
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
void SetLatch(Latch *latch)
Definition: latch.c:567
@ CAC_SUPERUSER
Definition: libpq-be.h:79
Assert(fmt[strlen(fmt) - 1] !='\n')
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1018
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
Definition: lock.c:2180
#define USER_LOCKMETHOD
Definition: lock.h:131
#define AccessShareLock
Definition: lockdefs.h:36
#define RowExclusiveLock
Definition: lockdefs.h:38
void InitializeClientEncoding(void)
Definition: mbutils.c:281
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1216
void SetDatabaseEncoding(int encoding)
Definition: mbutils.c:1104
char * pstrdup(const char *in)
Definition: mcxt.c:1299
void pfree(void *pointer)
Definition: mcxt.c:1169
MemoryContext TopMemoryContext
Definition: mcxt.c:48
MemoryContext PostmasterContext
Definition: mcxt.c:50
void * palloc(Size size)
Definition: mcxt.c:1062
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
void InitializeSessionUserIdStandalone(void)
Definition: miscinit.c:797
Oid GetUserId(void)
Definition: miscinit.c:495
Oid GetSessionUserId(void)
Definition: miscinit.c:529
void SetDatabasePath(const char *path)
Definition: miscinit.c:308
void InitializeSessionUserId(const char *rolename, Oid roleid)
Definition: miscinit.c:694
bool has_rolreplication(Oid roleid)
Definition: miscinit.c:676
void ValidatePgVersion(const char *path)
Definition: miscinit.c:1547
void InitializeSearchPath(void)
Definition: namespace.c:4369
#define ACL_CONNECT
Definition: parsenodes.h:93
void * arg
#define NAMEDATALEN
static int sig
Definition: pg_ctl.c:84
FormData_pg_database * Form_pg_database
Definition: pg_database.h:81
void ApplySetting(Snapshot snapshot, Oid databaseid, Oid roleid, Relation relsetting, GucSource source)
#define lfirst(lc)
Definition: pg_list.h:169
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:322
void check_strxfrm_bug(void)
Definition: pg_locale.c:1187
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:143
static int port
Definition: pg_regress.c:92
const char * username
Definition: pgbench.c:282
void pgstat_initialize(void)
Definition: pgstat.c:3173
void InitPlanCache(void)
Definition: plancache.c:127
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
void EnablePortalManager(void)
Definition: portalmem.c:104
void process_postgres_switches(int argc, char *argv[], GucContext ctx, const char **dbname)
Definition: postgres.c:3676
int PostAuthDelay
Definition: postgres.c:104
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
static void ShutdownPostgres(int code, Datum arg)
Definition: postinit.c:1170
static void IdleInTransactionSessionTimeoutHandler(void)
Definition: postinit.c:1219
static void LockTimeoutHandler(void)
Definition: postinit.c:1209
void InitializeMaxBackends(void)
Definition: postinit.c:489
void pg_split_opts(char **argv, int *argcp, const char *optstr)
Definition: postinit.c:430
static void process_settings(Oid databaseid, Oid roleid)
Definition: postinit.c:1136
void BaseInit(void)
Definition: postinit.c:511
static void IdleSessionTimeoutHandler(void)
Definition: postinit.c:1227
static void process_startup_options(Port *port, bool am_superuser)
Definition: postinit.c:1071
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname, bool override_allow_connections)
Definition: postinit.c:578
static void StatementTimeoutHandler(void)
Definition: postinit.c:1187
static void CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connections)
Definition: postinit.c:305
static bool ThereIsAtLeastOneRole(void)
Definition: postinit.c:1246
static void PerformAuthentication(Port *port)
Definition: postinit.c:185
static void ClientCheckTimeoutHandler(void)
Definition: postinit.c:1235
static HeapTuple GetDatabaseTuple(const char *dbname)
Definition: postinit.c:96
static HeapTuple GetDatabaseTupleByOid(Oid dboid)
Definition: postinit.c:139
bool Log_connections
Definition: postmaster.c:241
bool ClientAuthInProgress
Definition: postmaster.c:365
int AuthenticationTimeout
Definition: postmaster.c:238
int ReservedBackends
Definition: postmaster.c:218
#define MAX_BACKENDS
Definition: postmaster.h:75
int CountDBConnections(Oid databaseid)
Definition: procarray.c:3574
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:161
void set_ps_display(const char *activity)
Definition: ps_status.c:349
bool criticalSharedRelcachesBuilt
Definition: relcache.c:143
void RelationCacheInitializePhase3(void)
Definition: relcache.c:3949
void RelationCacheInitialize(void)
Definition: relcache.c:3844
void RelationCacheInitializePhase2(void)
Definition: relcache.c:3890
char * GetDatabasePath(Oid dbNode, Oid spcNode)
Definition: relpath.c:110
void ReleaseAuxProcessResources(bool isCommit)
Definition: resowner.c:908
ResourceOwner CurrentResourceOwner
Definition: resowner.c:146
void CreateAuxProcessResourceOwner(void)
Definition: resowner.c:887
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
@ ForwardScanDirection
Definition: sdir.h:26
struct @10::@11 av[32]
void InitializeSession(void)
Definition: session.c:54
void pg_usleep(long microsec)
Definition: signal.c:53
void SharedInvalBackendInit(bool sendOnly)
Definition: sinvaladt.c:257
void smgrinit(void)
Definition: smgr.c:111
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:250
Snapshot GetCatalogSnapshot(Oid relid)
Definition: snapmgr.c:386
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:867
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:825
void InvalidateCatalogSnapshot(void)
Definition: snapmgr.c:456
PGPROC * MyProc
Definition: proc.c:68
void CheckDeadLockAlert(void)
Definition: proc.c:1854
void InitProcessPhase2(void)
Definition: proc.c:480
bool HaveNFreeProcs(int n)
Definition: proc.c:659
#define BTEqualStrategyNumber
Definition: stratnum.h:31
char * dbname
Definition: streamutil.c:51
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:75
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Oid databaseId
Definition: proc.h:157
Definition: libpq-be.h:126
CAC_state canAcceptConnections
Definition: libpq-be.h:138
bool superuser(void)
Definition: superuser.c:46
void InitSync(void)
Definition: sync.c:129
void InitCatalogCache(void)
Definition: syscache.c:1044
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1198
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1150
@ DATABASEOID
Definition: syscache.h:55
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:112
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:993
void enable_timeout_after(TimeoutId id, int delay_ms)
Definition: timeout.c:551
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:676
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:496
@ IDLE_SESSION_TIMEOUT
Definition: timeout.h:34
@ IDLE_IN_TRANSACTION_SESSION_TIMEOUT
Definition: timeout.h:33
@ LOCK_TIMEOUT
Definition: timeout.h:28
@ STATEMENT_TIMEOUT
Definition: timeout.h:29
@ DEADLOCK_TIMEOUT
Definition: timeout.h:27
@ CLIENT_CONNECTION_CHECK_TIMEOUT
Definition: timeout.h:35
bool am_walsender
Definition: walsender.c:115
bool am_db_walsender
Definition: walsender.c:118
int max_wal_senders
Definition: walsender.c:121
#define kill(pid, sig)
Definition: win32_port.h:464
void StartTransactionCommand(void)
Definition: xact.c:2909
int XactIsoLevel
Definition: xact.c:77
void SetCurrentStatementStartTimestamp(void)
Definition: xact.c:885
void CommitTransactionCommand(void)
Definition: xact.c:3010
void AbortOutOfAnyTransaction(void)
Definition: xact.c:4650
#define XACT_READ_COMMITTED
Definition: xact.h:37
void StartupXLOG(void)
Definition: xlog.c:6680
void ShutdownXLOG(int code, Datum arg)
Definition: xlog.c:8799
void InitXLogInsert(void)
Definition: xloginsert.c:1251