|
PostgreSQL Source Code git master
|
#include "postgres.h"#include <fcntl.h>#include <unistd.h>#include <sys/stat.h>#include "access/genam.h"#include "access/heapam.h"#include "access/htup_details.h"#include "access/multixact.h"#include "access/tableam.h"#include "access/xact.h"#include "access/xloginsert.h"#include "access/xlogrecovery.h"#include "access/xlogutils.h"#include "catalog/catalog.h"#include "catalog/dependency.h"#include "catalog/indexing.h"#include "catalog/objectaccess.h"#include "catalog/pg_authid.h"#include "catalog/pg_collation.h"#include "catalog/pg_database.h"#include "catalog/pg_db_role_setting.h"#include "catalog/pg_subscription.h"#include "catalog/pg_tablespace.h"#include "commands/comment.h"#include "commands/dbcommands.h"#include "commands/dbcommands_xlog.h"#include "commands/defrem.h"#include "commands/seclabel.h"#include "commands/tablespace.h"#include "common/file_perm.h"#include "mb/pg_wchar.h"#include "miscadmin.h"#include "pgstat.h"#include "postmaster/bgwriter.h"#include "replication/slot.h"#include "storage/copydir.h"#include "storage/fd.h"#include "storage/ipc.h"#include "storage/lmgr.h"#include "storage/md.h"#include "storage/procarray.h"#include "storage/procsignal.h"#include "storage/smgr.h"#include "utils/acl.h"#include "utils/builtins.h"#include "utils/fmgroids.h"#include "utils/lsyscache.h"#include "utils/pg_locale.h"#include "utils/relmapper.h"#include "utils/snapmgr.h"#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
| struct | createdb_failure_params |
| struct | movedb_failure_params |
| struct | CreateDBRelInfo |
Typedefs | |
| typedef enum CreateDBStrategy | CreateDBStrategy |
| typedef struct CreateDBRelInfo | CreateDBRelInfo |
Enumerations | |
| enum | CreateDBStrategy { CREATEDB_WAL_LOG , CREATEDB_FILE_COPY } |
| Enumerator | |
|---|---|
| CREATEDB_WAL_LOG | |
| CREATEDB_FILE_COPY | |
Definition at line 84 of file dbcommands.c.
| Oid AlterDatabase | ( | ParseState * | pstate, |
| AlterDatabaseStmt * | stmt, | ||
| bool | isTopLevel | ||
| ) |
Definition at line 2382 of file dbcommands.c.
References aclcheck_error(), ACLCHECK_NOT_OWNER, BoolGetDatum(), BTEqualStrategyNumber, CatalogTupleUpdate(), CStringGetDatum(), database_is_invalid_form(), DATCONNLIMIT_UNLIMITED, defGetBoolean(), defGetInt32(), defGetString(), ereport, errcode(), errhint(), errmsg(), ERROR, errorConflictingDefElem(), FATAL, fb(), Form_pg_database, GETSTRUCT(), GetUserId(), heap_modify_tuple(), HeapTupleIsValid, InplaceUpdateTupleLock, Int32GetDatum(), InvalidOid, InvokeObjectPostAlterHook, lfirst, list_length(), LockTuple(), movedb(), MyDatabaseId, NoLock, OBJECT_DATABASE, object_ownercheck(), parser_errposition(), PreventInTransactionBlock(), RelationGetDescr, RowExclusiveLock, ScanKeyInit(), stmt, systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), table_open(), and UnlockTuple().
Referenced by standard_ProcessUtility().
| ObjectAddress AlterDatabaseOwner | ( | const char * | dbname, |
| Oid | newOwnerId | ||
| ) |
Definition at line 2678 of file dbcommands.c.
References aclcheck_error(), ACLCHECK_NOT_OWNER, aclnewowner(), BTEqualStrategyNumber, CatalogTupleUpdate(), changeDependencyOnOwner(), check_can_set_role(), CStringGetDatum(), DatumGetAclP, dbname, ereport, errcode(), errmsg(), ERROR, fb(), Form_pg_database, GETSTRUCT(), GetUserId(), have_createdb_privilege(), heap_freetuple(), heap_getattr(), heap_modify_tuple(), HeapTupleIsValid, InplaceUpdateTupleLock, InvokeObjectPostAlterHook, LockTuple(), NoLock, OBJECT_DATABASE, object_ownercheck(), ObjectAddressSet, ObjectIdGetDatum(), PointerGetDatum(), RelationGetDescr, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), table_open(), and UnlockTuple().
Referenced by ExecAlterOwnerStmt().
| ObjectAddress AlterDatabaseRefreshColl | ( | AlterDatabaseRefreshCollStmt * | stmt | ) |
Definition at line 2555 of file dbcommands.c.
References aclcheck_error(), ACLCHECK_NOT_OWNER, BTEqualStrategyNumber, CatalogTupleUpdate(), CStringGetDatum(), CStringGetTextDatum, elog, ereport, errcode(), errmsg(), ERROR, fb(), Form_pg_database, get_collation_actual_version(), GETSTRUCT(), GetUserId(), heap_freetuple(), heap_getattr(), heap_modify_tuple(), HeapTupleIsValid, InplaceUpdateTupleLock, InvokeObjectPostAlterHook, LockTuple(), NoLock, NOTICE, OBJECT_DATABASE, object_ownercheck(), ObjectAddressSet, RelationGetDescr, RowExclusiveLock, ScanKeyInit(), stmt, systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), table_open(), TextDatumGetCString, UnlockTuple(), and values.
Referenced by standard_ProcessUtility().
| Oid AlterDatabaseSet | ( | AlterDatabaseSetStmt * | stmt | ) |
Definition at line 2652 of file dbcommands.c.
References AccessShareLock, aclcheck_error(), ACLCHECK_NOT_OWNER, AlterSetting(), fb(), get_database_oid(), GetUserId(), InvalidOid, OBJECT_DATABASE, object_ownercheck(), shdepLockAndCheckObject(), stmt, and UnlockSharedObject().
Referenced by standard_ProcessUtility().
Definition at line 3108 of file dbcommands.c.
References AccessShareLock, dstpath, fb(), Form_pg_tablespace, ForwardScanDirection, GetDatabasePath(), GETSTRUCT(), heap_getnext(), lstat, pfree(), table_beginscan_catalog(), table_close(), table_endscan(), and table_open().
Referenced by createdb().
Definition at line 1604 of file dbcommands.c.
References encoding, ereport, errcode(), errdetail(), errmsg(), ERROR, fb(), pg_encoding_to_char, pg_get_encoding_from_locale(), PG_SQL_ASCII, PG_UTF8, and superuser().
Referenced by createdb(), and DefineCollation().
|
static |
Definition at line 553 of file dbcommands.c.
References AccessShareLock, CHECKPOINT_FAST, CHECKPOINT_FLUSH_UNLOGGED, CHECKPOINT_FORCE, CHECKPOINT_WAIT, copydir(), xl_dbase_create_file_copy_rec::db_id, directory_is_empty(), dstpath, fb(), Form_pg_tablespace, ForwardScanDirection, GetDatabasePath(), GETSTRUCT(), heap_getnext(), IsBinaryUpgrade, pfree(), RequestCheckpoint(), S_ISDIR, stat::st_mode, stat, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), XLOG_DBASE_CREATE_FILE_COPY, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLR_SPECIAL_REL_UPDATE.
Referenced by createdb().
|
static |
Definition at line 150 of file dbcommands.c.
References AccessShareLock, Assert, CreateAndCopyRelationData(), CreateDirAndVersionFile(), dstpath, fb(), GetDatabasePath(), lfirst, list_free_deep(), LockRelationId(), NIL, pfree(), RelationMapCopy(), ScanSourceDatabasePgClass(), and UnlockRelationId().
Referenced by createdb().
| Oid createdb | ( | ParseState * | pstate, |
| const CreatedbStmt * | stmt | ||
| ) |
Definition at line 686 of file dbcommands.c.
References AccessShareLock, ACL_CREATE, aclcheck_error(), ACLCHECK_OK, allowSystemTableMods, Assert, BoolGetDatum(), builtin_validate_locale(), CatalogTupleInsert(), CharGetDatum(), check_can_set_role(), check_db_file_conflict(), check_encoding_locale_matches(), check_locale(), copyTemplateDependencies(), CountOtherDBBackends(), CreateDatabaseUsingFileCopy(), CreateDatabaseUsingWalLog(), createdb_failure_callback(), CREATEDB_FILE_COPY, CREATEDB_WAL_LOG, CStringGetDatum(), CStringGetTextDatum, database_is_invalid_oid(), DATCONNLIMIT_UNLIMITED, dbname, defGetBoolean(), defGetInt32(), defGetObjectId(), defGetString(), DirectFunctionCall1, directory_is_empty(), elog, encoding, ereport, errcode(), errdetail(), errdetail_busy_db(), errhint(), errmsg(), ERROR, errorConflictingDefElem(), fb(), FirstNormalObjectId, ForceSyncCommit(), get_collation_actual_version(), get_database_name(), get_database_oid(), get_db_info(), get_role_oid(), get_tablespace_oid(), GetDatabasePath(), GetNewOidWithIndex(), GetUserId(), have_createdb_privilege(), heap_form_tuple(), icu_language_tag(), icu_validate_locale(), icu_validation_level, Int32GetDatum(), InvalidMultiXactId, InvalidOid, InvalidTransactionId, InvokeObjectPostCreateHook, is_encoding_supported_by_icu(), IsA, IsBinaryUpgrade, IsUnderPostmaster, lfirst, LockSharedObject(), namein(), NoLock, NOTICE, object_aclcheck(), object_ownercheck(), OBJECT_TABLESPACE, ObjectIdGetDatum(), OidIsValid, parser_errposition(), pfree(), pg_encoding_to_char, PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, pg_strcasecmp(), PG_VALID_BE_ENCODING, pg_valid_server_encoding, PointerGetDatum(), quote_identifier(), recordDependencyOnOwner(), RelationGetDescr, RowExclusiveLock, S_ISDIR, ShareLock, stat::st_mode, stat, stmt, table_close(), table_open(), TransactionIdGetDatum(), and WARNING.
Referenced by CreateRole(), main(), and standard_ProcessUtility().
Definition at line 1642 of file dbcommands.c.
References AccessShareLock, arg, CREATEDB_WAL_LOG, DatumGetPointer(), DropDatabaseBuffers(), fb(), ForgetDatabaseSyncRequests(), remove_dbtablespaces(), ShareLock, and UnlockSharedObject().
Referenced by createdb().
Definition at line 459 of file dbcommands.c.
References buf, CloseTransientFile(), data_sync_elevel(), END_CRIT_SECTION, ereport, errcode_for_file_access(), errmsg(), ERROR, fb(), fd(), fsync_fname(), MakePGDirectory(), MAXPGPATH, OpenTransientFile(), PG_BINARY, pg_fsync(), pgstat_report_wait_end(), pgstat_report_wait_start(), snprintf, sprintf, START_CRIT_SECTION, write, XLOG_DBASE_CREATE_WAL_LOG, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().
Referenced by CreateDatabaseUsingWalLog(), and dbase_redo().
| bool database_is_invalid_form | ( | Form_pg_database | datform | ) |
Definition at line 3228 of file dbcommands.c.
References DATCONNLIMIT_INVALID_DB, and fb().
Referenced by AlterDatabase(), database_is_invalid_oid(), get_database_list(), InitPostgres(), and vac_truncate_clog().
Definition at line 3238 of file dbcommands.c.
References database_is_invalid_form(), elog, ERROR, fb(), Form_pg_database, GETSTRUCT(), HeapTupleIsValid, invalid, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().
Referenced by createdb().
| void dbase_redo | ( | XLogReaderState * | record | ) |
Definition at line 3300 of file dbcommands.c.
References AccessExclusiveLock, Assert, copydir(), CreateDirAndVersionFile(), DropDatabaseBuffers(), elog, EmitProcSignalBarrier(), ereport, errmsg(), FATAL, fb(), FlushDatabaseBuffers(), ForgetDatabaseSyncRequests(), get_parent_directory(), GetDatabasePath(), i, InHotStandby, LockSharedObjectForSession(), PANIC, pfree(), PROCSIGNAL_BARRIER_SMGRRELEASE, pstrdup(), recovery_create_dbdir(), ReplicationSlotsDropDBSlots(), ResolveRecoveryConflictWithDatabase(), rmtree(), S_ISDIR, stat::st_mode, stat, UnlockSharedObjectForSession(), WaitForProcSignalBarrier(), WARNING, XLOG_DBASE_CREATE_FILE_COPY, XLOG_DBASE_CREATE_WAL_LOG, XLOG_DBASE_DROP, XLogDropDatabase(), XLogRecGetData, XLogRecGetInfo, and XLogRecHasAnyBlockRefs.
| void DropDatabase | ( | ParseState * | pstate, |
| DropdbStmt * | stmt | ||
| ) |
Definition at line 2356 of file dbcommands.c.
References DefElem::defname, dropdb(), ereport, errcode(), errmsg(), ERROR, fb(), lfirst, DefElem::location, parser_errposition(), and stmt.
Referenced by standard_ProcessUtility().
Definition at line 1681 of file dbcommands.c.
References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, BTEqualStrategyNumber, CatalogTupleDelete(), CHECKPOINT_FAST, CHECKPOINT_FORCE, CHECKPOINT_WAIT, CountDBSubscriptions(), CountOtherDBBackends(), CStringGetDatum(), DATCONNLIMIT_INVALID_DB, dbname, DeleteSharedComments(), DeleteSharedSecurityLabel(), DropDatabaseBuffers(), dropDatabaseDependencies(), DropSetting(), elog, EmitProcSignalBarrier(), ereport, errcode(), errdetail_busy_db(), errdetail_plural(), errmsg(), ERROR, fb(), ForceSyncCommit(), ForgetDatabaseSyncRequests(), Form_pg_database, get_db_info(), GETSTRUCT(), GetUserId(), heap_freetuple(), HeapTupleIsValid, InvalidOid, InvokeObjectDropHook, MyDatabaseId, NoLock, NOTICE, OBJECT_DATABASE, object_ownercheck(), pgstat_drop_database(), PROCSIGNAL_BARRIER_SMGRRELEASE, remove_dbtablespaces(), ReplicationSlotsCountDBSlots(), ReplicationSlotsDropDBSlots(), RequestCheckpoint(), RowExclusiveLock, ScanKeyInit(), systable_inplace_update_begin(), systable_inplace_update_finish(), table_close(), table_open(), TerminateOtherDBBackends(), WaitForProcSignalBarrier(), XactLastRecEnd, and XLogFlush().
Referenced by DropDatabase().
Definition at line 3151 of file dbcommands.c.
References errdetail(), errdetail_plural(), and fb().
Referenced by createdb(), dropdb(), movedb(), and RenameDatabase().
Definition at line 3181 of file dbcommands.c.
References AccessShareLock, BTEqualStrategyNumber, CStringGetDatum(), dbname, ereport, errcode(), errmsg(), ERROR, fb(), Form_pg_database, GETSTRUCT(), HeapTupleIsValid, InvalidOid, OidIsValid, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by AlterDatabaseSet(), AlterRoleSet(), CommentObject(), convert_database_name(), createdb(), get_object_address_unqualified(), pg_database_size_name(), regdatabasein(), RenameDatabase(), sepgsql_database_post_create(), synchronize_slots(), and worker_spi_launch().
|
static |
Definition at line 2835 of file dbcommands.c.
References AccessShareLock, Assert, BTEqualStrategyNumber, CStringGetDatum(), fb(), Form_pg_database, GETSTRUCT(), HeapTupleIsValid, LockSharedObject(), name, NameStr, NoLock, ObjectIdGetDatum(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, and UnlockSharedObject().
Referenced by createdb(), dropdb(), movedb(), and RenameDatabase().
Definition at line 2993 of file dbcommands.c.
References fb(), Form_pg_authid, GETSTRUCT(), GetUserId(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), rolcreatedb, SearchSysCache1(), and superuser().
Referenced by AlterDatabaseOwner(), AlterRole(), createdb(), CreateRole(), and RenameDatabase().
Definition at line 2017 of file dbcommands.c.
References AccessExclusiveLock, ACL_CREATE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, AllocateDir(), BTEqualStrategyNumber, CatalogTupleUpdate(), CHECKPOINT_FAST, CHECKPOINT_FLUSH_UNLOGGED, CHECKPOINT_FORCE, CHECKPOINT_WAIT, CommitTransactionCommand(), copydir(), CountOtherDBBackends(), CStringGetDatum(), xl_dbase_create_file_copy_rec::db_id, xl_dbase_drop_rec::db_id, dbname, DropDatabaseBuffers(), elog, EmitProcSignalBarrier(), ereport, errcode(), errdetail_busy_db(), errhint(), errmsg(), ERROR, fb(), ForceSyncCommit(), FreeDir(), get_db_info(), get_tablespace_oid(), GetDatabasePath(), GetUserId(), heap_modify_tuple(), HeapTupleIsValid, InplaceUpdateTupleLock, InvokeObjectPostAlterHook, LockSharedObjectForSession(), LockTuple(), movedb_failure_callback(), MyDatabaseId, NoLock, object_aclcheck(), OBJECT_DATABASE, object_ownercheck(), OBJECT_TABLESPACE, ObjectIdGetDatum(), pfree(), PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, PointerGetDatum(), PopActiveSnapshot(), PROCSIGNAL_BARRIER_SMGRRELEASE, ReadDir(), RelationGetDescr, RequestCheckpoint(), rmtree(), RowExclusiveLock, ScanKeyInit(), StartTransactionCommand(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), table_open(), UnlockSharedObjectForSession(), UnlockTuple(), WaitForProcSignalBarrier(), WARNING, XLOG_DBASE_CREATE_FILE_COPY, XLOG_DBASE_DROP, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLR_SPECIAL_REL_UPDATE.
Referenced by AlterDatabase().
Definition at line 2339 of file dbcommands.c.
References arg, DatumGetPointer(), dstpath, fb(), GetDatabasePath(), pfree(), and rmtree().
Referenced by movedb().
| Datum pg_database_collation_actual_version | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2791 of file dbcommands.c.
References cstring_to_text(), datlocprovider, ereport, errcode(), errmsg(), ERROR, fb(), Form_pg_database, get_collation_actual_version(), GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TEXT_P, ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttrNotNull(), and TextDatumGetCString.
Definition at line 3271 of file dbcommands.c.
References allow_in_place_tablespaces, Assert, DEBUG1, elog, ereport, errmsg(), fb(), PANIC, pg_dir_create_mode, pg_mkdir_p(), PG_TBLSPC_DIR_SLASH, reachedConsistency, RecoveryInProgress(), stat, and WARNING.
Referenced by dbase_redo().
Definition at line 3018 of file dbcommands.c.
References AccessShareLock, xl_dbase_drop_rec::db_id, dstpath, ereport, errmsg(), fb(), Form_pg_tablespace, ForwardScanDirection, GetDatabasePath(), GETSTRUCT(), heap_getnext(), i, lappend_oid(), lfirst_oid, list_free(), list_length(), lstat, MinSizeOfDbaseDropRec, NIL, palloc(), pfree(), rmtree(), S_ISDIR, stat::st_mode, table_beginscan_catalog(), table_close(), table_endscan(), table_open(), WARNING, XLOG_DBASE_DROP, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLR_SPECIAL_REL_UPDATE.
Referenced by createdb_failure_callback(), and dropdb().
| ObjectAddress RenameDatabase | ( | const char * | oldname, |
| const char * | newname | ||
| ) |
Definition at line 1910 of file dbcommands.c.
References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), CountOtherDBBackends(), datname, elog, ereport, errcode(), errdetail_busy_db(), errmsg(), ERROR, fb(), Form_pg_database, get_database_oid(), get_db_info(), GETSTRUCT(), GetUserId(), have_createdb_privilege(), HeapTupleIsValid, InplaceUpdateTupleLock, InvokeObjectPostAlterHook, MyDatabaseId, namestrcpy(), NoLock, OBJECT_DATABASE, object_ownercheck(), ObjectAddressSet, ObjectIdGetDatum(), OidIsValid, RowExclusiveLock, SearchSysCacheLockedCopy1(), table_close(), table_open(), UnlockTuple(), and WARNING.
Referenced by ExecRenameStmt().
Definition at line 252 of file dbcommands.c.
References AccessShareLock, BAS_BULKREAD, buf, BUFFER_LOCK_SHARE, BufferGetPage(), CHECK_FOR_INTERRUPTS, LockRelId::dbId, RelFileLocator::dbOid, fb(), GetAccessStrategy(), GetLatestSnapshot(), INVALID_PROC_NUMBER, LockBuffer(), LockRelationId(), MAIN_FORKNUM, NIL, PageIsEmpty(), PageIsNew(), RBM_NORMAL, ReadBufferWithoutRelcache(), RegisterSnapshot(), RelationMapOidToFilenumberForDatabase(), LockRelId::relId, RelFileLocator::relNumber, ScanSourceDatabasePgClassPage(), smgrclose(), smgrnblocks(), smgropen(), RelFileLocator::spcOid, UnlockRelationId(), UnlockReleaseBuffer(), and UnregisterSnapshot().
Referenced by CreateDatabaseUsingWalLog().
|
static |
Definition at line 331 of file dbcommands.c.
References Assert, buf, BufferGetBlockNumber(), fb(), FirstOffsetNumber, HeapTupleSatisfiesVisibility(), ItemIdGetLength, ItemIdIsDead, ItemIdIsNormal, ItemIdIsRedirected, ItemIdIsUsed, ItemPointerSet(), lappend(), OffsetNumberNext, PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), ScanSourceDatabasePgClassTuple(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, and HeapTupleData::t_tableOid.
Referenced by ScanSourceDatabasePgClass().
|
static |
Definition at line 394 of file dbcommands.c.
References Assert, elog, ERROR, fb(), GETSTRUCT(), InvalidRelFileNumber, OidIsValid, palloc_object, RelationMapOidToFilenumberForDatabase(), and RelFileNumberIsValid.
Referenced by ScanSourceDatabasePgClassPage().