59 #include "utils/fmgroids.h"
72 static 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)"),
332 (
errcode(ERRCODE_UNDEFINED_DATABASE),
333 errmsg(
"database \"%s\" has disappeared from pg_database",
335 errdetail(
"Database OID %u now seems to belong to \"%s\".",
352 if (!dbform->datallowconn && !override_allow_connections)
354 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
355 errmsg(
"database \"%s\" is not currently accepting connections",
367 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
368 errmsg(
"permission denied for database \"%s\"",
name),
369 errdetail(
"User does not have CONNECT privilege.")));
381 if (dbform->datconnlimit >= 0 &&
385 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
386 errmsg(
"too many connections for database \"%s\"",
410 (
errmsg(
"database locale is incompatible with operating system"),
411 errdetail(
"The database was initialized with LC_COLLATE \"%s\", "
412 " which is not recognized by setlocale().", collate),
413 errhint(
"Recreate the database with another locale or install the missing locale.")));
417 (
errmsg(
"database locale is incompatible with operating system"),
418 errdetail(
"The database was initialized with LC_CTYPE \"%s\", "
419 " which is not recognized by setlocale().", ctype),
420 errhint(
"Recreate the database with another locale or install the missing locale.")));
422 if (strcmp(ctype,
"C") == 0 ||
423 strcmp(ctype,
"POSIX") == 0)
426 if (dbform->datlocprovider == COLLPROVIDER_BUILTIN)
436 else if (dbform->datlocprovider == COLLPROVIDER_ICU)
443 datum =
SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_daticurules, &isnull);
468 datum =
SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datcollversion,
472 char *actual_versionstr;
473 char *collversionstr;
478 if (dbform->datlocprovider == COLLPROVIDER_LIBC)
484 if (!actual_versionstr)
487 "database \"%s\" has no actual collation version, but a version was recorded",
489 else if (strcmp(actual_versionstr, collversionstr) != 0)
491 (
errmsg(
"database \"%s\" has a collation version mismatch",
493 errdetail(
"The database was created using collation version %s, "
494 "but the operating system provides version %s.",
495 collversionstr, actual_versionstr),
496 errhint(
"Rebuild all objects in this database that use the default collation and run "
497 "ALTER DATABASE %s REFRESH COLLATION VERSION, "
498 "or build PostgreSQL with the right library version.",
525 bool last_was_escape =
false;
530 while (isspace((
unsigned char) *optstr))
542 if (isspace((
unsigned char) *optstr) && !last_was_escape)
545 if (!last_was_escape && *optstr ==
'\\')
546 last_was_escape =
true;
549 last_was_escape =
false;
585 elog(
ERROR,
"too many backends configured");
901 (
errcode(ERRCODE_UNDEFINED_OBJECT),
902 errmsg(
"no roles are defined in this database system"),
903 errhint(
"You should immediately run CREATE USER \"%s\" SUPERUSER;.",
939 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
940 errmsg(
"must be superuser to connect in binary upgrade mode")));
960 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
961 errmsg(
"remaining connection slots are reserved for roles with the %s attribute",
966 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
967 errmsg(
"remaining connection slots are reserved for roles with privileges of the \"%s\" role",
968 "pg_use_reserved_connections")));
978 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
979 errmsg(
"permission denied to start WAL sender"),
980 errdetail(
"Only roles with the %s attribute may start a WAL sender process.",
1021 dboid = Template1DbOid;
1024 else if (in_dbname != NULL)
1032 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1033 errmsg(
"database \"%s\" does not exist", in_dbname)));
1035 dboid = dbform->oid;
1092 (in_dbname &&
namestrcmp(&datform->datname, in_dbname)))
1096 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1097 errmsg(
"database \"%s\" does not exist", in_dbname),
1098 errdetail(
"It seems to have just been dropped or renamed.")));
1101 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1102 errmsg(
"database %u does not exist", dboid)));
1110 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1111 errmsg(
"cannot connect to invalid database \"%s\"",
dbname),
1112 errhint(
"Use DROP DATABASE to drop invalid databases."));
1119 strcpy(out_dbname,
dbname);
1165 if (
access(fullpath, F_OK) == -1)
1167 if (errno == ENOENT)
1169 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1170 errmsg(
"database \"%s\" does not exist",
1172 errdetail(
"The database subdirectory \"%s\" is missing.",
1177 errmsg(
"could not access directory \"%s\": %m",
1272 if (
port->cmdline_options != NULL)
1283 maxac = 2 + (strlen(
port->cmdline_options) + 1) / 2;
1285 av = (
char **)
palloc(maxac *
sizeof(
char *));
1288 av[ac++] =
"postgres";
1310 gucopts =
lnext(
port->guc_options, gucopts);
1313 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 InitBufferPoolAccess(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
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
void InitializeClientEncoding(void)
const char * GetDatabaseEncodingName(void)
void SetDatabaseEncoding(int encoding)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
MemoryContext PostmasterContext
char * MemoryContextStrdup(MemoryContext context, const char *string)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define IsBootstrapProcessingMode()
#define INIT_PG_LOAD_SESSION_LIBS
#define AmAutoVacuumWorkerProcess()
#define AmBackgroundWorkerProcess()
#define AmLogicalSlotSyncWorkerProcess()
#define AmAutoVacuumLauncherProcess()
#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)
void make_icu_collator(const char *iculocstr, const char *icurules, struct pg_locale_struct *resultp)
struct pg_locale_struct default_locale
char * get_collation_actual_version(char collprovider, const char *collcollate)
char * pg_perm_setlocale(int category, const char *locale)
const char * builtin_validate_locale(int encoding, const char *locale)
static rewind_source * source
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)
bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
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)
bool check_max_connections(int *newval, void **extra, GucSource source)
static void IdleSessionTimeoutHandler(void)
bool check_max_wal_senders(int *newval, void **extra, GucSource source)
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)
static void ClientCheckTimeoutHandler(void)
bool check_max_worker_processes(int *newval, void **extra, GucSource source)
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
int CountDBConnections(Oid databaseid)
void ProcSignalInit(void)
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 GetTransactionSnapshot(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)
struct pg_locale_struct::@146::@147 builtin
union pg_locale_struct::@146 info
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)