mirror of
https://github.com/postgres/postgres.git
synced 2026-03-29 05:43:27 -04:00
Because this strategy logs changes on a block-by-block basis, it avoids the need to checkpoint before and after the operation. However, because it logs each changed block individually, it might generate a lot of extra write-ahead logging if the template database is large. Therefore, the older strategy remains available via a new STRATEGY parameter to CREATE DATABASE, and a corresponding --strategy option to createdb. Somewhat controversially, this patch assembles the list of relations to be copied to the new database by reading the pg_class relation of the template database. Cross-database access like this isn't normally possible, but it can be made to work here because there can't be any connections to the database being copied, nor can it contain any in-doubt transactions. Even so, we have to use lower-level interfaces than normal, since the table scan and relcache interfaces will not work for a database to which we're not connected. The advantage of this approach is that we do not need to rely on the filesystem to determine what ought to be copied, but instead on PostgreSQL's own knowledge of the database structure. This avoids, for example, copying stray files that happen to be located in the source database directory. Dilip Kumar, with a fairly large number of cosmetic changes by me. Reviewed and tested by Ashutosh Sharma, Andres Freund, John Naylor, Greg Nancarrow, Neha Sharma. Additional feedback from Bruce Momjian, Heikki Linnakangas, Julien Rouhaud, Adam Brusselback, Kyotaro Horiguchi, Tomas Vondra, Andrew Dunstan, Álvaro Herrera, and others. Discussion: http://postgr.es/m/CA+TgmoYtcdxBjLh31DLxUXHxFVMPGzrU5_T=CYCvRyFHywSBUQ@mail.gmail.com
115 lines
4.5 KiB
C
115 lines
4.5 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* lmgr.h
|
|
* POSTGRES lock manager definitions.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/storage/lmgr.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef LMGR_H
|
|
#define LMGR_H
|
|
|
|
#include "lib/stringinfo.h"
|
|
#include "storage/itemptr.h"
|
|
#include "storage/lock.h"
|
|
#include "utils/rel.h"
|
|
|
|
|
|
/* XactLockTableWait operations */
|
|
typedef enum XLTW_Oper
|
|
{
|
|
XLTW_None,
|
|
XLTW_Update,
|
|
XLTW_Delete,
|
|
XLTW_Lock,
|
|
XLTW_LockUpdated,
|
|
XLTW_InsertIndex,
|
|
XLTW_InsertIndexUnique,
|
|
XLTW_FetchUpdated,
|
|
XLTW_RecheckExclusionConstr
|
|
} XLTW_Oper;
|
|
|
|
extern void RelationInitLockInfo(Relation relation);
|
|
|
|
/* Lock a relation */
|
|
extern void LockRelationOid(Oid relid, LOCKMODE lockmode);
|
|
extern void LockRelationId(LockRelId *relid, LOCKMODE lockmode);
|
|
extern bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode);
|
|
extern void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode);
|
|
extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode);
|
|
|
|
extern void LockRelation(Relation relation, LOCKMODE lockmode);
|
|
extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode);
|
|
extern void UnlockRelation(Relation relation, LOCKMODE lockmode);
|
|
extern bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode,
|
|
bool orstronger);
|
|
extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
|
|
|
|
extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
|
|
extern void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
|
|
|
|
/* Lock a relation for extension */
|
|
extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode);
|
|
extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode);
|
|
extern bool ConditionalLockRelationForExtension(Relation relation,
|
|
LOCKMODE lockmode);
|
|
extern int RelationExtensionLockWaiterCount(Relation relation);
|
|
|
|
/* Lock to recompute pg_database.datfrozenxid in the current database */
|
|
extern void LockDatabaseFrozenIds(LOCKMODE lockmode);
|
|
|
|
/* Lock a page (currently only used within indexes) */
|
|
extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
|
extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
|
extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
|
|
|
/* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
|
|
extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
|
|
extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
|
|
LOCKMODE lockmode);
|
|
extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
|
|
|
|
/* Lock an XID (used to wait for a transaction to finish) */
|
|
extern void XactLockTableInsert(TransactionId xid);
|
|
extern void XactLockTableDelete(TransactionId xid);
|
|
extern void XactLockTableWait(TransactionId xid, Relation rel,
|
|
ItemPointer ctid, XLTW_Oper oper);
|
|
extern bool ConditionalXactLockTableWait(TransactionId xid);
|
|
|
|
/* Lock VXIDs, specified by conflicting locktags */
|
|
extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress);
|
|
extern void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress);
|
|
|
|
/* Lock an XID for tuple insertion (used to wait for an insertion to finish) */
|
|
extern uint32 SpeculativeInsertionLockAcquire(TransactionId xid);
|
|
extern void SpeculativeInsertionLockRelease(TransactionId xid);
|
|
extern void SpeculativeInsertionWait(TransactionId xid, uint32 token);
|
|
|
|
/* Lock a general object (other than a relation) of the current database */
|
|
extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
|
|
LOCKMODE lockmode);
|
|
extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
|
|
LOCKMODE lockmode);
|
|
|
|
/* Lock a shared-across-databases object (other than a relation) */
|
|
extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
|
|
LOCKMODE lockmode);
|
|
extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
|
|
LOCKMODE lockmode);
|
|
|
|
extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
|
|
LOCKMODE lockmode);
|
|
extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
|
|
LOCKMODE lockmode);
|
|
|
|
/* Describe a locktag for error messages */
|
|
extern void DescribeLockTag(StringInfo buf, const LOCKTAG *tag);
|
|
|
|
extern const char *GetLockNameFromTagType(uint16 locktag_type);
|
|
|
|
#endif /* LMGR_H */
|