1/*-------------------------------------------------------------------------
4 * postgres initialization utilities
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/utils/init/postinit.c
14 *-------------------------------------------------------------------------
62#include "utils/fmgroids.h"
76static void CheckMyDatabase(
const char *
name,
bool am_superuser,
bool override_allow_connections);
90/*** InitPostgres support ***/
94 * GetDatabaseTuple -- fetch the pg_database row for a database
96 * This is used during backend startup when we don't yet have any access to
97 * system catalogs in general. In the worst case, we can seqscan pg_database
98 * using nothing but the hard-wired descriptor that relcache.c creates for
99 * pg_database. In more typical cases, relcache.c was able to load
100 * descriptors for both pg_database and its indexes from the shared relcache
101 * cache file, and so we can do an indexscan. criticalSharedRelcachesBuilt
102 * tells whether we got the cached descriptors.
116 Anum_pg_database_datname,
121 * Open pg_database and fetch a tuple. Force heap scan if we haven't yet
122 * built the critical shared relcache entries (i.e., we're starting up
123 * without a shared relcache cache file).
133 /* Must copy tuple before releasing buffer */
145 * GetDatabaseTupleByOid -- as above, but search by database OID
159 Anum_pg_database_oid,
164 * Open pg_database and fetch a tuple. Force heap scan if we haven't yet
165 * built the critical shared relcache entries (i.e., we're starting up
166 * without a shared relcache cache file).
176 /* Must copy tuple before releasing buffer */
189 * PerformAuthentication -- authenticate a remote client
191 * returns: nothing. Will not return at all if there's any failure.
196 /* This should be set already, but let's make sure */
200 * In EXEC_BACKEND case, we didn't inherit the contents of pg_hba.conf
201 * etcetera from the postmaster, and have to load them ourselves.
203 * FIXME: [fork/exec] Ugh. Is there a way around this overhead?
208 * load_hba() and load_ident() want to work within the PostmasterContext,
209 * so create that if it doesn't exist (which it won't). We'll delete it
210 * again later, in PostgresMain.
220 * It makes no sense to continue if we fail to load the HBA file,
221 * since there is no way to connect to the database in this case.
224 /* translator: %s is a configuration file */
231 * It is ok to continue if we fail to load the IDENT file, although it
232 * means that you cannot log in using any of the authentication
233 * methods that need a user name mapping. load_ident() already logged
234 * the details of error to the log.
239 /* Capture authentication start time for logging */
243 * Set up a timeout in case a buggy or malicious client fails to respond
244 * during authentication. Since we're inside a transaction and might do
245 * database access, we have to use the statement_timeout infrastructure.
250 * Now perform authentication exchange.
256 * Done with authentication. Disable the timeout, and log if needed.
260 /* Capture authentication end time for logging */
277 if (
port->application_name != NULL)
279 port->application_name);
282 if (
port->ssl_in_use)
295 _(
" GSS (authenticated=%s, encrypted=%s, delegated_credentials=%s, principal=%s)"),
302 _(
" GSS (authenticated=%s, encrypted=%s, delegated_credentials=%s)"),
320 * CheckMyDatabase -- fetch information from the pg_database entry for our DB
332 /* Fetch our pg_database row normally, via syscache */
338 /* This recheck is strictly paranoia */
341 (
errcode(ERRCODE_UNDEFINED_DATABASE),
342 errmsg(
"database \"%s\" has disappeared from pg_database",
344 errdetail(
"Database OID %u now seems to belong to \"%s\".",
348 * Check permissions to connect to the database.
350 * These checks are not enforced when in standalone mode, so that there is
351 * a way to recover from disabling all access to all databases, for
352 * example "UPDATE pg_database SET datallowconn = false;".
357 * Check that the database is currently allowing connections.
358 * (Background processes can override this test and the next one by
359 * setting override_allow_connections.)
361 if (!dbform->datallowconn && !override_allow_connections)
363 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
364 errmsg(
"database \"%s\" is not currently accepting connections",
368 * Check privilege to connect to the database. (The am_superuser test
369 * is redundant, but since we have the flag, might as well check it
370 * and save a few cycles.)
372 if (!am_superuser && !override_allow_connections &&
376 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
377 errmsg(
"permission denied for database \"%s\"",
name),
378 errdetail(
"User does not have CONNECT privilege.")));
381 * Check connection limit for this database. We enforce the limit
382 * only for regular backends, since other process types have their own
385 * There is a race condition here --- we create our PGPROC before
386 * checking for other PGPROCs. If two backends did this at about the
387 * same time, they might both think they were over the limit, while
388 * ideally one should succeed and one fail. Getting that to work
389 * exactly seems more trouble than it is worth, however; instead we
390 * just document that the connection limit is approximate.
392 if (dbform->datconnlimit >= 0 &&
397 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
398 errmsg(
"too many connections for database \"%s\"",
403 * OK, we're golden. Next to-do item is to save the encoding info out of
404 * the pg_database tuple.
407 /* Record it as a GUC internal option, too */
410 /* If we have no other source of client_encoding, use server encoding */
414 /* assign locale variables */
421 * Historcally, we set LC_COLLATE from datcollate, as well. That's no
422 * longer necessary because all collation behavior is handled through
428 (
errmsg(
"database locale is incompatible with operating system"),
429 errdetail(
"The database was initialized with LC_CTYPE \"%s\", "
430 " which is not recognized by setlocale().", ctype),
431 errhint(
"Recreate the database with another locale or install the missing locale.")));
433 if (strcmp(ctype,
"C") == 0 ||
434 strcmp(ctype,
"POSIX") == 0)
440 * Check collation version. See similar code in
441 * pg_newlocale_from_collation(). Note that here we warn instead of error
442 * in any case, so that we don't prevent connecting.
444 datum =
SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datcollversion,
448 char *actual_versionstr;
449 char *collversionstr;
454 if (dbform->datlocprovider == COLLPROVIDER_LIBC)
463 if (!actual_versionstr)
464 /* should not happen */
466 "database \"%s\" has no actual collation version, but a version was recorded",
468 else if (strcmp(actual_versionstr, collversionstr) != 0)
470 (
errmsg(
"database \"%s\" has a collation version mismatch",
472 errdetail(
"The database was created using collation version %s, "
473 "but the operating system provides version %s.",
474 collversionstr, actual_versionstr),
475 errhint(
"Rebuild all objects in this database that use the default collation and run "
476 "ALTER DATABASE %s REFRESH COLLATION VERSION, "
477 "or build PostgreSQL with the right library version.",
486 * pg_split_opts -- split a string of options and append it to an argv array
488 * The caller is responsible for ensuring the argv array is large enough. The
489 * maximum possible number of arguments added by this routine is
490 * (strlen(optstr) + 1) / 2.
492 * Because some option values can contain spaces we allow escaping using
493 * backslashes, with \\ representing a literal backslash.
504 bool last_was_escape =
false;
508 /* skip over leading space */
509 while (isspace((
unsigned char) *optstr))
516 * Parse a single option, stopping at the first space, unless it's
521 if (isspace((
unsigned char) *optstr) && !last_was_escape)
524 if (!last_was_escape && *optstr ==
'\\')
525 last_was_escape =
true;
528 last_was_escape =
false;
535 /* now store the option in the next argv[] position */
543 * Initialize MaxBackends value from config options.
545 * This must be called after modules have had the chance to alter GUCs in
546 * shared_preload_libraries and before shared memory size is determined.
548 * Note that in EXEC_BACKEND environment, the value is passed down from
549 * postmaster to subprocesses via BackendParameters in SubPostmasterMain; only
550 * postmaster itself and processes not under postmaster control should call
558 /* Note that this does not include "auxiliary" processes */
564 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
565 errmsg(
"too many server processes configured"),
566 errdetail(
"\"max_connections\" (%d) plus \"autovacuum_worker_slots\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.",
573 * Initialize the number of fast-path lock slots in PGPROC.
575 * This must be called after modules have had the chance to alter GUCs in
576 * shared_preload_libraries and before shared memory size is determined.
581 /* Should be initialized only once. */
585 * Based on the max_locks_per_transaction GUC, as that's a good indicator
586 * of the expected number of locks, figure out the value for
587 * FastPathLockGroupsPerBackend. This must be a power-of-two. We cap the
588 * value at FP_LOCK_GROUPS_PER_BACKEND_MAX and insist the value is at
591 * The default max_locks_per_transaction = 64 means 4 groups by default.
597 /* Validate we did get a power-of-two */
603 * Early initialization of a backend (either standalone or under postmaster).
604 * This happens even before InitPostgres.
606 * This is separate from InitPostgres because it is also called by auxiliary
607 * processes, such as the background writer process, which may not call
608 * InitPostgres at all.
616 * Initialize our input/output/debugging file descriptors.
621 * Initialize file access. Done early so other subsystems can access
627 * Initialize statistics reporting. This needs to happen early to ensure
628 * that pgstat's shutdown callback runs after the shutdown callbacks of
629 * all subsystems that can produce stats (like e.g. transaction commits
635 * Initialize AIO before infrastructure that might need to actually
640 /* Do local initialization of storage and buffer managers */
646 * Initialize temporary file access after pgstat, so that the temporary
647 * file shutdown hook can report temporary file statistics.
652 * Initialize local buffers for WAL record construction, in case we ever
653 * try to insert XLOG.
657 /* Initialize lock manager's local structs */
661 * Initialize replication slots after pgstat. The exit hook might need to
662 * drop ephemeral slots, which in turn triggers stats reporting.
668/* --------------------------------
670 * Initialize POSTGRES.
673 * in_dbname, dboid: specify database to connect to, as described below
674 * username, useroid: specify role to connect as, as described below
676 * - INIT_PG_LOAD_SESSION_LIBS to honor [session|local]_preload_libraries.
677 * - INIT_PG_OVERRIDE_ALLOW_CONNS to connect despite !datallowconn.
678 * - INIT_PG_OVERRIDE_ROLE_LOGIN to connect despite !rolcanlogin.
679 * out_dbname: optional output parameter, see below; pass NULL if not used
681 * The database can be specified by name, using the in_dbname parameter, or by
682 * OID, using the dboid parameter. Specify NULL or InvalidOid respectively
683 * for the unused parameter. If dboid is provided, the actual database
684 * name can be returned to the caller in out_dbname. If out_dbname isn't
685 * NULL, it must point to a buffer of size NAMEDATALEN.
687 * Similarly, the role can be passed by name, using the username parameter,
688 * or by OID using the useroid parameter.
690 * In bootstrap mode the database and username parameters are NULL/InvalidOid.
691 * The autovacuum launcher process doesn't specify these parameters either,
692 * because it only goes far enough to be able to read pg_database; it doesn't
693 * connect to any particular database. An autovacuum worker specifies a
694 * database but not a username; conversely, a physical walsender specifies
695 * username but not database.
697 * By convention, INIT_PG_LOAD_SESSION_LIBS should be passed in "flags" in
698 * "interactive" sessions (including standalone backends), but not in
699 * background processes such as autovacuum. Note in particular that it
700 * shouldn't be true in parallel worker processes; those have another
701 * mechanism for replicating their leader's set of loaded libraries.
703 * We expect that InitProcess() was already called, so we already have a
704 * PGPROC struct ... but it's not completely filled in yet.
707 * Be very careful with the order of calls in the InitPostgres function.
708 * --------------------------------
725 * Add my PGPROC struct to the ProcArray.
727 * Once I have done this, I am visible to other backends!
731 /* Initialize status reporting */
735 * And initialize an entry in the PgBackendStatus array. That way, if
736 * LWLocks or third-party authentication should happen to hang, it is
737 * possible to retrieve some information about what is going on.
746 * Initialize my entry in the shared-invalidation manager's array of
754 * Also set up timeout handlers needed for backend operation. We need
755 * these in every case except bootstrap.
772 * If this is either a bootstrap process or a standalone backend, start up
773 * the XLOG machinery, and register to have it closed down at exit. In
774 * other cases, the startup process is responsible for starting up the
775 * XLOG machinery, and the checkpointer for closing it down.
780 * We don't yet have an aux-process resource owner, but StartupXLOG
781 * and ShutdownXLOG will need one. Hence, create said resource owner
782 * (and register a callback to clean it up after ShutdownXLOG runs).
787 /* Release (and warn about) any buffer pins leaked in StartupXLOG */
789 /* Reset CurrentResourceOwner to nothing for the moment */
793 * Use before_shmem_exit() so that ShutdownXLOG() can rely on DSM
794 * segments etc to work (which in turn is required for pgstats).
801 * Initialize the relation cache and the system catalog caches. Note that
802 * no catalog access happens here; we only set up the hashtable structure.
803 * We must do this before starting a transaction because transaction abort
804 * would try to touch these hashtables.
810 /* Initialize portal manager */
814 * Load relcache entries for the shared system catalogs. This must create
815 * at least entries for pg_database and catalogs used for authentication.
820 * Set up process-exit callback to do pre-shutdown cleanup. This is the
821 * one of the first before_shmem_exit callbacks we register; thus, this
822 * will be one the last things we do before low-level modules like the
823 * buffer manager begin to close down. We need to have this in place
824 * before we begin our first transaction --- if we fail during the
825 * initialization transaction, as is entirely possible, we need the
826 * AbortTransaction call to clean up.
830 /* The autovacuum launcher is done here */
833 /* fill in the remainder of this entry in the PgBackendStatus array */
840 * Start a new transaction here before first access to db.
844 /* statement_timestamp must be set for timeouts to work correctly */
849 * transaction_isolation will have been set to the default by the
850 * above. If the default is "serializable", and we are in hot
851 * standby, we will fail if we don't change it to something lower.
852 * Fortunately, "read committed" is plenty good enough.
858 * Perform client authentication if necessary, then figure out our
859 * postgres user ID, and see if we are a superuser.
861 * In standalone mode, autovacuum worker processes and slot sync worker
862 * process, we use a fixed ID, otherwise we figure it out from the
863 * authenticated user name.
876 (
errcode(ERRCODE_UNDEFINED_OBJECT),
877 errmsg(
"no roles are defined in this database system"),
878 errhint(
"You should immediately run CREATE USER \"%s\" SUPERUSER;.",
897 /* normal multiuser case */
901 /* ensure that auth_method is actually valid, aka authn_id is not NULL */
908 /* Report any SSL/GSS details for the session. */
917 * Binary upgrades only allowed super-user connections
922 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
923 errmsg(
"must be superuser to connect in binary upgrade mode")));
927 * The last few regular connection slots are reserved for superusers and
928 * roles with privileges of pg_use_reserved_connections. We do not apply
929 * these limits to background processes, since they all have their own
930 * pools of PGPROC slots.
932 * Note: At this point, the new backend has already claimed a proc struct,
933 * so we must check whether the number of free slots is strictly less than
934 * the reserved connection limits.
942 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
943 errmsg(
"remaining connection slots are reserved for roles with the %s attribute",
948 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
949 errmsg(
"remaining connection slots are reserved for roles with privileges of the \"%s\" role",
950 "pg_use_reserved_connections")));
953 /* Check replication permissions needed for walsender processes. */
960 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
961 errmsg(
"permission denied to start WAL sender"),
962 errdetail(
"Only roles with the %s attribute may start a WAL sender process.",
967 * If this is a plain walsender only supporting physical replication, we
968 * don't want to connect to any particular database. Just finish the
969 * backend startup by processing any options from the startup packet, and
974 /* process any options passed in the startup packet */
978 /* Apply PostAuthDelay as soon as we've read all options */
982 /* initialize client encoding */
985 /* fill in the remainder of this entry in the PgBackendStatus array */
988 /* close the transaction we started above */
995 * Set up the global variables holding database id and default tablespace.
996 * But note we won't actually try to touch the database just yet.
998 * We take a shortcut in the bootstrap case, otherwise we have to look up
999 * the db's entry in pg_database.
1003 dboid = Template1DbOid;
1006 else if (in_dbname != NULL)
1014 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1015 errmsg(
"database \"%s\" does not exist", in_dbname)));
1017 dboid = dbform->oid;
1022 * If this is a background worker not bound to any particular
1023 * database, we're done now. Everything that follows only makes sense
1024 * if we are bound to a specific database. We do need to close the
1025 * transaction we started before returning.
1036 * Now, take a writer's lock on the database we are trying to connect to.
1037 * If there is a concurrently running DROP DATABASE on that database, this
1038 * will block us until it finishes (and has committed its update of
1041 * Note that the lock is not held long, only until the end of this startup
1042 * transaction. This is OK since we will advertise our use of the
1043 * database in the ProcArray before dropping the lock (in fact, that's the
1044 * next thing to do). Anyone trying a DROP DATABASE after this point will
1045 * see us in the array once they have the lock. Ordering is important for
1046 * this because we don't want to advertise ourselves as being in this
1047 * database until we have the lock; otherwise we create what amounts to a
1048 * deadlock with CountOtherDBBackends().
1050 * Note: use of RowExclusiveLock here is reasonable because we envision
1051 * our session as being a concurrent writer of the database. If we had a
1052 * way of declaring a session as being guaranteed-read-only, we could use
1053 * AccessShareLock for such sessions and thereby not conflict against
1060 * Recheck pg_database to make sure the target database hasn't gone away.
1061 * If there was a concurrent DROP DATABASE, this ensures we will die
1062 * cleanly without creating a mess.
1074 (in_dbname &&
namestrcmp(&datform->datname, in_dbname)))
1078 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1079 errmsg(
"database \"%s\" does not exist", in_dbname),
1080 errdetail(
"It seems to have just been dropped or renamed.")));
1083 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1084 errmsg(
"database %u does not exist", dboid)));
1092 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1093 errmsg(
"cannot connect to invalid database \"%s\"",
dbname),
1094 errhint(
"Use DROP DATABASE to drop invalid databases."));
1099 /* pass the database name back to the caller */
1101 strcpy(out_dbname,
dbname);
1105 * Now that we rechecked, we are certain to be connected to a database and
1106 * thus can set MyDatabaseId.
1108 * It is important that MyDatabaseId only be set once we are sure that the
1109 * target database can no longer be concurrently dropped or renamed. For
1110 * example, without this guarantee, pgstat_update_dbstats() could create
1111 * entries for databases that were just dropped in the pgstat shutdown
1112 * callback, which could confuse other code paths like the autovacuum
1118 * Now we can mark our PGPROC entry with the database ID.
1120 * We assume this is an atomic store so no lock is needed; though actually
1121 * things would work fine even if it weren't atomic. Anyone searching the
1122 * ProcArray for this database's ID should hold the database lock, so they
1123 * would not be executing concurrently with this store. A process looking
1124 * for another database's ID could in theory see a chance match if it read
1125 * a partially-updated databaseId value; but as long as all such searches
1126 * wait and retry, as in CountOtherDBBackends(), they will certainly see
1127 * the correct value on their next try.
1132 * We established a catalog snapshot while reading pg_authid and/or
1133 * pg_database; but until we have set up MyDatabaseId, we won't react to
1134 * incoming sinval messages for unshared catalogs, so we won't realize it
1135 * if the snapshot has been invalidated. Assume it's no good anymore.
1140 * Now we should be able to access the database directory safely. Verify
1141 * it's there and looks reasonable.
1147 if (
access(fullpath, F_OK) == -1)
1149 if (errno == ENOENT)
1151 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1152 errmsg(
"database \"%s\" does not exist",
1154 errdetail(
"The database subdirectory \"%s\" is missing.",
1159 errmsg(
"could not access directory \"%s\": %m",
1170 * It's now possible to do real access to the system catalogs.
1172 * Load relcache entries for the system catalogs. This must create at
1173 * least the minimum set of "nailed-in" cache entries.
1177 /* set up ACL framework (so CheckMyDatabase can check permissions) */
1181 * Re-read the pg_database row for our database, check permissions and set
1182 * up database-specific GUC settings. We can't do this until all the
1183 * database-access infrastructure is up. (Also, it wants to know if the
1184 * user is a superuser, so the above stuff has to happen first.)
1191 * Now process any command-line switches and any additional GUC variable
1192 * settings passed in the startup packet. We couldn't do this before
1193 * because we didn't know if client is a superuser.
1198 /* Process pg_db_role_setting options */
1201 /* Apply PostAuthDelay as soon as we've read all options */
1206 * Initialize various default states that can't be set up until we've
1207 * selected the active user and gotten the right GUC settings.
1210 /* set default namespace search path */
1213 /* initialize client encoding */
1216 /* Initialize this backend's session state. */
1220 * If this is an interactive session, load any libraries that should be
1221 * preloaded at backend start. Since those are determined by GUCs, this
1222 * can't happen until GUC settings are complete, but we want it to happen
1223 * during the initial transaction in case anything that requires database
1224 * access needs to be done.
1229 /* fill in the remainder of this entry in the PgBackendStatus array */
1233 /* close the transaction we started above */
1239 * Process any command-line switches and any additional GUC variable
1240 * settings passed in the startup packet.
1251 * First process any command-line switches that were included in the
1252 * startup packet, if we are in a regular backend.
1254 if (
port->cmdline_options != NULL)
1257 * The maximum possible number of commandline arguments that could
1258 * come from port->cmdline_options is (strlen + 1) / 2; see
1265 maxac = 2 + (strlen(
port->cmdline_options) + 1) / 2;
1267 av = (
char **)
palloc(maxac *
sizeof(
char *));
1270 av[ac++] =
"postgres";
1282 * Process any additional GUC variable settings passed in startup packet.
1283 * These are handled exactly like command-line variables.
1292 gucopts =
lnext(
port->guc_options, gucopts);
1295 gucopts =
lnext(
port->guc_options, gucopts);
1302 * Load GUC settings from pg_db_role_setting.
1304 * We try specific settings for the database/role combination, as well as
1305 * general for this database and for this user.
1318 /* read all the settings under the same snapshot for efficiency */
1321 /* Later settings are ignored if set earlier. */
1332 * Backend-shutdown callback. Do cleanup that we want to be sure happens
1333 * before all the supporting modules begin to nail their doors shut via
1334 * their own callbacks.
1336 * User-level cleanup, such as temp-relation removal and UNLISTEN, happens
1337 * via separate callbacks that execute before this one. We don't combine the
1338 * callbacks because we still want this one to happen if the user-level
1344 /* Make sure we've killed any active transaction */
1348 * User locks are not released by transaction end, so be sure to release
1356 * STATEMENT_TIMEOUT handler: trigger a query-cancel interrupt.
1364 * During authentication the timeout is used to deal with
1365 * authentication_timeout - we want to quit in response to such timeouts.
1371 /* try to signal whole process group */
1378 * LOCK_TIMEOUT handler: trigger a query-cancel interrupt.
1384 /* try to signal whole process group */
1431 * Returns true if at least one role is defined in this database cluster.
void initialize_acl(void)
bool has_privs_of_role(Oid member, Oid role)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
void pgaio_init_backend(void)
void ClientAuthentication(Port *port)
int autovacuum_worker_slots
TimestampTz GetCurrentTimestamp(void)
ConnectionTiming conn_timing
@ LOG_CONNECTION_AUTHORIZATION
void pgstat_bestart_security(void)
void pgstat_bestart_initial(void)
void pgstat_bestart_final(void)
bool be_gssapi_get_auth(Port *port)
bool be_gssapi_get_enc(Port *port)
const char * be_gssapi_get_princ(Port *port)
bool be_gssapi_get_delegation(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 InitBufferManagerAccess(void)
#define TextDatumGetCString(d)
#define OidIsValid(objectId)
bool database_is_invalid_form(Form_pg_database datform)
int errmsg_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void InitFileAccess(void)
void InitTemporaryFileAccess(void)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
volatile sig_atomic_t IdleStatsUpdateTimeoutPending
bool MyDatabaseHasLoginEventTriggers
volatile sig_atomic_t InterruptPending
volatile sig_atomic_t IdleSessionTimeoutPending
volatile sig_atomic_t IdleInTransactionSessionTimeoutPending
volatile sig_atomic_t TransactionTimeoutPending
uint8 MyCancelKey[MAX_CANCEL_KEY_LENGTH]
volatile sig_atomic_t CheckClientConnectionPending
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Assert(PointerIsAligned(start, uint64))
const char * hba_authname(UserAuth auth_method)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
HeapTuple heap_copytuple(HeapTuple tuple)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
#define INJECTION_POINT(name, arg)
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
void SetLatch(Latch *latch)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void InitLockManagerAccess(void)
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
int FastPathLockGroupsPerBackend
void InitializeClientEncoding(void)
const char * GetDatabaseEncodingName(void)
void SetDatabaseEncoding(int encoding)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
MemoryContext PostmasterContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define IsBootstrapProcessingMode()
#define INIT_PG_LOAD_SESSION_LIBS
#define AmAutoVacuumWorkerProcess()
#define AmBackgroundWorkerProcess()
#define AmLogicalSlotSyncWorkerProcess()
#define AmAutoVacuumLauncherProcess()
#define AmRegularBackendProcess()
#define INIT_PG_OVERRIDE_ROLE_LOGIN
#define INIT_PG_OVERRIDE_ALLOW_CONNS
void InitializeSessionUserId(const char *rolename, Oid roleid, bool bypass_login_check)
void InitializeSystemUser(const char *authn_id, const char *auth_method)
void InitializeSessionUserIdStandalone(void)
void process_session_preload_libraries(void)
Oid GetSessionUserId(void)
void SetDatabasePath(const char *path)
ClientConnectionInfo MyClientConnectionInfo
bool has_rolreplication(Oid roleid)
void ValidatePgVersion(const char *path)
int namestrcmp(Name name, const char *str)
void InitializeSearchPath(void)
static uint32 pg_nextpower2_32(uint32 num)
FormData_pg_database * Form_pg_database
void ApplySetting(Snapshot snapshot, Oid databaseid, Oid roleid, Relation relsetting, GucSource source)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
char * get_collation_actual_version(char collprovider, const char *collcollate)
char * pg_perm_setlocale(int category, const char *locale)
void init_database_collation(void)
void pgstat_initialize(void)
void pgstat_before_server_shutdown(int code, Datum arg)
size_t strlcpy(char *dst, const char *src, size_t siz)
void EnablePortalManager(void)
void process_postgres_switches(int argc, char *argv[], GucContext ctx, const char **dbname)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static void ShutdownPostgres(int code, Datum arg)
static void IdleInTransactionSessionTimeoutHandler(void)
static void LockTimeoutHandler(void)
void InitializeMaxBackends(void)
void pg_split_opts(char **argv, int *argcp, const char *optstr)
static void IdleStatsUpdateTimeoutHandler(void)
static void process_settings(Oid databaseid, Oid roleid)
static void IdleSessionTimeoutHandler(void)
static void process_startup_options(Port *port, bool am_superuser)
static void StatementTimeoutHandler(void)
static void CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connections)
static bool ThereIsAtLeastOneRole(void)
static void PerformAuthentication(Port *port)
void InitializeFastPathLocks(void)
static void ClientCheckTimeoutHandler(void)
static HeapTuple GetDatabaseTuple(const char *dbname)
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
static HeapTuple GetDatabaseTupleByOid(Oid dboid)
static void TransactionTimeoutHandler(void)
bool ClientAuthInProgress
int AuthenticationTimeout
int SuperuserReservedConnections
#define FP_LOCK_GROUPS_PER_BACKEND_MAX
#define FP_LOCK_SLOTS_PER_GROUP
#define NUM_SPECIAL_WORKER_PROCS
int CountDBConnections(Oid databaseid)
void ProcSignalInit(const uint8 *cancel_key, int cancel_key_len)
static void set_ps_display(const char *activity)
bool criticalSharedRelcachesBuilt
void RelationCacheInitializePhase3(void)
void RelationCacheInitialize(void)
void RelationCacheInitializePhase2(void)
char * GetDatabasePath(Oid dbOid, Oid spcOid)
void ReleaseAuxProcessResources(bool isCommit)
ResourceOwner CurrentResourceOwner
void CreateAuxProcessResourceOwner(void)
const char * quote_identifier(const char *ident)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void InitializeSession(void)
void pg_usleep(long microsec)
void SharedInvalBackendInit(bool sendOnly)
void ReplicationSlotInitialize(void)
Snapshot GetCatalogSnapshot(Oid relid)
void UnregisterSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
void InvalidateCatalogSnapshot(void)
bool HaveNFreeProcs(int n, int *nfree)
void CheckDeadLockAlert(void)
void InitProcessPhase2(void)
#define BTEqualStrategyNumber
void resetStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
void InitCatalogCache(void)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
void enable_timeout_after(TimeoutId id, int delay_ms)
void disable_timeout(TimeoutId id, bool keep_indicator)
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
@ IDLE_IN_TRANSACTION_SESSION_TIMEOUT
@ IDLE_STATS_UPDATE_TIMEOUT
@ CLIENT_CONNECTION_CHECK_TIMEOUT
void StartTransactionCommand(void)
void SetCurrentStatementStartTimestamp(void)
void CommitTransactionCommand(void)
void AbortOutOfAnyTransaction(void)
#define XACT_READ_COMMITTED
void ShutdownXLOG(int code, Datum arg)
void InitXLogInsert(void)