59#include "utils/fmgroids.h"
72static void CheckMyDatabase(
const char *
name,
bool am_superuser,
bool override_allow_connections);
112 Anum_pg_database_datname,
155 Anum_pg_database_oid,
267 if (
port->application_name != NULL)
269 port->application_name);
272 if (
port->ssl_in_use)
285 _(
" GSS (authenticated=%s, encrypted=%s, delegated_credentials=%s, principal=%s)"),
292 _(
" GSS (authenticated=%s, encrypted=%s, delegated_credentials=%s)"),
331 (
errcode(ERRCODE_UNDEFINED_DATABASE),
332 errmsg(
"database \"%s\" has disappeared from pg_database",
334 errdetail(
"Database OID %u now seems to belong to \"%s\".",
351 if (!dbform->datallowconn && !override_allow_connections)
353 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
354 errmsg(
"database \"%s\" is not currently accepting connections",
362 if (!am_superuser && !override_allow_connections &&
366 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
367 errmsg(
"permission denied for database \"%s\"",
name),
368 errdetail(
"User does not have CONNECT privilege.")));
382 if (dbform->datconnlimit >= 0 &&
387 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
388 errmsg(
"too many connections for database \"%s\"",
412 (
errmsg(
"database locale is incompatible with operating system"),
413 errdetail(
"The database was initialized with LC_COLLATE \"%s\", "
414 " which is not recognized by setlocale().", collate),
415 errhint(
"Recreate the database with another locale or install the missing locale.")));
419 (
errmsg(
"database locale is incompatible with operating system"),
420 errdetail(
"The database was initialized with LC_CTYPE \"%s\", "
421 " which is not recognized by setlocale().", ctype),
422 errhint(
"Recreate the database with another locale or install the missing locale.")));
424 if (strcmp(ctype,
"C") == 0 ||
425 strcmp(ctype,
"POSIX") == 0)
435 datum =
SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datcollversion,
439 char *actual_versionstr;
440 char *collversionstr;
445 if (dbform->datlocprovider == COLLPROVIDER_LIBC)
454 if (!actual_versionstr)
457 "database \"%s\" has no actual collation version, but a version was recorded",
459 else if (strcmp(actual_versionstr, collversionstr) != 0)
461 (
errmsg(
"database \"%s\" has a collation version mismatch",
463 errdetail(
"The database was created using collation version %s, "
464 "but the operating system provides version %s.",
465 collversionstr, actual_versionstr),
466 errhint(
"Rebuild all objects in this database that use the default collation and run "
467 "ALTER DATABASE %s REFRESH COLLATION VERSION, "
468 "or build PostgreSQL with the right library version.",
495 bool last_was_escape =
false;
500 while (isspace((
unsigned char) *optstr))
512 if (isspace((
unsigned char) *optstr) && !last_was_escape)
515 if (!last_was_escape && *optstr ==
'\\')
516 last_was_escape =
true;
519 last_was_escape =
false;
555 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
556 errmsg(
"too many server processes configured"),
557 errdetail(
"\"max_connections\" (%d) plus \"autovacuum_max_workers\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.",
854 (
errcode(ERRCODE_UNDEFINED_OBJECT),
855 errmsg(
"no roles are defined in this database system"),
856 errhint(
"You should immediately run CREATE USER \"%s\" SUPERUSER;.",
892 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
893 errmsg(
"must be superuser to connect in binary upgrade mode")));
912 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
913 errmsg(
"remaining connection slots are reserved for roles with the %s attribute",
918 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
919 errmsg(
"remaining connection slots are reserved for roles with privileges of the \"%s\" role",
920 "pg_use_reserved_connections")));
930 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
931 errmsg(
"permission denied to start WAL sender"),
932 errdetail(
"Only roles with the %s attribute may start a WAL sender process.",
973 dboid = Template1DbOid;
976 else if (in_dbname != NULL)
984 (
errcode(ERRCODE_UNDEFINED_DATABASE),
985 errmsg(
"database \"%s\" does not exist", in_dbname)));
1044 (in_dbname &&
namestrcmp(&datform->datname, in_dbname)))
1048 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1049 errmsg(
"database \"%s\" does not exist", in_dbname),
1050 errdetail(
"It seems to have just been dropped or renamed.")));
1053 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1054 errmsg(
"database %u does not exist", dboid)));
1062 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1063 errmsg(
"cannot connect to invalid database \"%s\"",
dbname),
1064 errhint(
"Use DROP DATABASE to drop invalid databases."));
1071 strcpy(out_dbname,
dbname);
1117 if (
access(fullpath, F_OK) == -1)
1119 if (errno == ENOENT)
1121 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1122 errmsg(
"database \"%s\" does not exist",
1124 errdetail(
"The database subdirectory \"%s\" is missing.",
1129 errmsg(
"could not access directory \"%s\": %m",
1224 if (
port->cmdline_options != NULL)
1235 maxac = 2 + (strlen(
port->cmdline_options) + 1) / 2;
1237 av = (
char **)
palloc(maxac *
sizeof(
char *));
1240 av[ac++] =
"postgres";
1262 gucopts =
lnext(
port->guc_options, gucopts);
1265 gucopts =
lnext(
port->guc_options, gucopts);
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 ClientAuthentication(Port *port)
int autovacuum_max_workers
void pgstat_bestart(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 Assert(condition)
#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
volatile sig_atomic_t CheckClientConnectionPending
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
const char * hba_authname(UserAuth auth_method)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
HeapTuple heap_copytuple(HeapTuple tuple)
#define HeapTupleIsValid(tuple)
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)
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(bool cancel_key_valid, int32 cancel_key)
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, struct 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)