60 #include "utils/fmgroids.h"
73 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, principal=%s)"),
291 _(
" GSS (authenticated=%s, encrypted=%s)"),
330 (
errcode(ERRCODE_UNDEFINED_DATABASE),
331 errmsg(
"database \"%s\" has disappeared from pg_database",
333 errdetail(
"Database OID %u now seems to belong to \"%s\".",
350 if (!dbform->datallowconn && !override_allow_connections)
352 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
353 errmsg(
"database \"%s\" is not currently accepting connections",
365 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
366 errmsg(
"permission denied for database \"%s\"",
name),
367 errdetail(
"User does not have CONNECT privilege.")));
379 if (dbform->datconnlimit >= 0 &&
383 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
384 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_ICU)
463 char *actual_versionstr;
464 char *collversionstr;
468 actual_versionstr =
get_collation_actual_version(dbform->datlocprovider, dbform->datlocprovider == COLLPROVIDER_ICU ? iculocale : collate);
469 if (!actual_versionstr)
472 "database \"%s\" has no actual collation version, but a version was recorded",
474 else if (strcmp(actual_versionstr, collversionstr) != 0)
476 (
errmsg(
"database \"%s\" has a collation version mismatch",
478 errdetail(
"The database was created using collation version %s, "
479 "but the operating system provides version %s.",
480 collversionstr, actual_versionstr),
481 errhint(
"Rebuild all objects in this database that use the default collation and run "
482 "ALTER DATABASE %s REFRESH COLLATION VERSION, "
483 "or build PostgreSQL with the right library version.",
516 bool last_was_escape =
false;
521 while (isspace((
unsigned char) *optstr))
533 if (isspace((
unsigned char) *optstr) && !last_was_escape)
536 if (!last_was_escape && *optstr ==
'\\')
537 last_was_escape =
true;
540 last_was_escape =
false;
576 elog(
ERROR,
"too many backends configured");
727 bool load_session_libraries,
728 bool override_allow_connections,
897 (
errcode(ERRCODE_UNDEFINED_OBJECT),
898 errmsg(
"no roles are defined in this database system"),
899 errhint(
"You should immediately run CREATE USER \"%s\" SUPERUSER;.",
934 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
935 errmsg(
"must be superuser to connect in binary upgrade mode")));
955 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
956 errmsg(
"remaining connection slots are reserved for roles with %s",
961 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
962 errmsg(
"remaining connection slots are reserved for roles with privileges of the \"%s\" role",
963 "pg_use_reserved_connections")));
973 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
974 errmsg(
"permission denied to start WAL sender"),
975 errdetail(
"Only roles with the %s attribute may start a WAL sender process.",
1019 else if (in_dbname != NULL)
1027 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1028 errmsg(
"database \"%s\" does not exist", in_dbname)));
1044 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1045 errmsg(
"database %u does not exist", dboid)));
1053 strcpy(out_dbname,
dbname);
1132 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1134 errdetail(
"It seems to have just been dropped or renamed.")));
1145 if (
access(fullpath, F_OK) == -1)
1147 if (errno == ENOENT)
1149 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1150 errmsg(
"database \"%s\" does not exist",
1152 errdetail(
"The database subdirectory \"%s\" is missing.",
1157 errmsg(
"could not access directory \"%s\": %m",
1223 if (load_session_libraries)
1251 if (
port->cmdline_options != NULL)
1262 maxac = 2 + (strlen(
port->cmdline_options) + 1) / 2;
1264 av = (
char **)
palloc(maxac *
sizeof(
char *));
1267 av[ac++] =
"postgres";
1289 gucopts =
lnext(
port->guc_options, gucopts);
1292 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
bool IsAutoVacuumLauncherProcess(void)
bool IsAutoVacuumWorkerProcess(void)
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)
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)
elog(ERROR, "%s: %s", p2, msg)
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
volatile sig_atomic_t InterruptPending
volatile sig_atomic_t IdleSessionTimeoutPending
volatile sig_atomic_t IdleInTransactionSessionTimeoutPending
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
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define IsBootstrapProcessingMode()
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)
void InitializeSessionUserId(const char *rolename, Oid roleid)
ClientConnectionInfo MyClientConnectionInfo
bool has_rolreplication(Oid roleid)
void ValidatePgVersion(const char *path)
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
void check_strxfrm_bug(void)
char * get_collation_actual_version(char collprovider, const char *collcollate)
char * pg_perm_setlocale(int category, 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)
static HeapTuple GetDatabaseTupleByOid(Oid dboid)
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bool load_session_libraries, bool override_allow_connections, char *out_dbname)
bool ClientAuthInProgress
int AuthenticationTimeout
int SuperuserReservedConnections
int CountDBConnections(Oid databaseid)
void ProcSignalInit(int pss_idx)
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)
void InitCatalogCache(void)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
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)