PostgreSQL Source Code  git master
xact.h File Reference
#include "access/transam.h"
#include "access/xlogreader.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
#include "storage/relfilenode.h"
#include "storage/sinval.h"
Include dependency graph for xact.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SavedTransactionCharacteristics
 
struct  xl_xact_assignment
 
struct  xl_xact_xinfo
 
struct  xl_xact_dbinfo
 
struct  xl_xact_subxacts
 
struct  xl_xact_relfilenodes
 
struct  xl_xact_stats_item
 
struct  xl_xact_stats_items
 
struct  xl_xact_invals
 
struct  xl_xact_twophase
 
struct  xl_xact_origin
 
struct  xl_xact_commit
 
struct  xl_xact_abort
 
struct  xl_xact_prepare
 
struct  xl_xact_parsed_commit
 
struct  xl_xact_parsed_abort
 

Macros

#define GIDSIZE   200
 
#define XACT_READ_UNCOMMITTED   0
 
#define XACT_READ_COMMITTED   1
 
#define XACT_REPEATABLE_READ   2
 
#define XACT_SERIALIZABLE   3
 
#define IsolationUsesXactSnapshot()   (XactIsoLevel >= XACT_REPEATABLE_READ)
 
#define IsolationIsSerializable()   (XactIsoLevel == XACT_SERIALIZABLE)
 
#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH
 
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE   (1U << 0)
 
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)
 
#define XLOG_XACT_COMMIT   0x00
 
#define XLOG_XACT_PREPARE   0x10
 
#define XLOG_XACT_ABORT   0x20
 
#define XLOG_XACT_COMMIT_PREPARED   0x30
 
#define XLOG_XACT_ABORT_PREPARED   0x40
 
#define XLOG_XACT_ASSIGNMENT   0x50
 
#define XLOG_XACT_INVALIDATIONS   0x60
 
#define XLOG_XACT_OPMASK   0x70
 
#define XLOG_XACT_HAS_INFO   0x80
 
#define XACT_XINFO_HAS_DBINFO   (1U << 0)
 
#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)
 
#define XACT_XINFO_HAS_RELFILENODES   (1U << 2)
 
#define XACT_XINFO_HAS_INVALS   (1U << 3)
 
#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)
 
#define XACT_XINFO_HAS_ORIGIN   (1U << 5)
 
#define XACT_XINFO_HAS_AE_LOCKS   (1U << 6)
 
#define XACT_XINFO_HAS_GID   (1U << 7)
 
#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)
 
#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)
 
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)
 
#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)
 
#define XactCompletionApplyFeedback(xinfo)    ((xinfo & XACT_COMPLETION_APPLY_FEEDBACK) != 0)
 
#define XactCompletionRelcacheInitFileInval(xinfo)    ((xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) != 0)
 
#define XactCompletionForceSyncCommit(xinfo)    ((xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) != 0)
 
#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)
 
#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)
 
#define MinSizeOfXactRelfilenodes   offsetof(xl_xact_relfilenodes, xnodes)
 
#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)
 
#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)
 
#define MinSizeOfXactCommit   (offsetof(xl_xact_commit, xact_time) + sizeof(TimestampTz))
 
#define MinSizeOfXactAbort   sizeof(xl_xact_abort)
 

Typedefs

typedef void(* XactCallback) (XactEvent event, void *arg)
 
typedef void(* SubXactCallback) (SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
 
typedef struct SavedTransactionCharacteristics SavedTransactionCharacteristics
 
typedef struct xl_xact_assignment xl_xact_assignment
 
typedef struct xl_xact_xinfo xl_xact_xinfo
 
typedef struct xl_xact_dbinfo xl_xact_dbinfo
 
typedef struct xl_xact_subxacts xl_xact_subxacts
 
typedef struct xl_xact_relfilenodes xl_xact_relfilenodes
 
typedef struct xl_xact_stats_item xl_xact_stats_item
 
typedef struct xl_xact_stats_items xl_xact_stats_items
 
typedef struct xl_xact_invals xl_xact_invals
 
typedef struct xl_xact_twophase xl_xact_twophase
 
typedef struct xl_xact_origin xl_xact_origin
 
typedef struct xl_xact_commit xl_xact_commit
 
typedef struct xl_xact_abort xl_xact_abort
 
typedef struct xl_xact_prepare xl_xact_prepare
 
typedef struct xl_xact_parsed_commit xl_xact_parsed_commit
 
typedef xl_xact_parsed_commit xl_xact_parsed_prepare
 
typedef struct xl_xact_parsed_abort xl_xact_parsed_abort
 

Enumerations

enum  SyncCommitLevel {
  SYNCHRONOUS_COMMIT_OFF , SYNCHRONOUS_COMMIT_LOCAL_FLUSH , SYNCHRONOUS_COMMIT_REMOTE_WRITE , SYNCHRONOUS_COMMIT_REMOTE_FLUSH ,
  SYNCHRONOUS_COMMIT_REMOTE_APPLY
}
 
enum  XactEvent {
  XACT_EVENT_COMMIT , XACT_EVENT_PARALLEL_COMMIT , XACT_EVENT_ABORT , XACT_EVENT_PARALLEL_ABORT ,
  XACT_EVENT_PREPARE , XACT_EVENT_PRE_COMMIT , XACT_EVENT_PARALLEL_PRE_COMMIT , XACT_EVENT_PRE_PREPARE
}
 
enum  SubXactEvent { SUBXACT_EVENT_START_SUB , SUBXACT_EVENT_COMMIT_SUB , SUBXACT_EVENT_ABORT_SUB , SUBXACT_EVENT_PRE_COMMIT_SUB }
 

Functions

bool IsTransactionState (void)
 
bool IsAbortedTransactionBlockState (void)
 
TransactionId GetTopTransactionId (void)
 
TransactionId GetTopTransactionIdIfAny (void)
 
TransactionId GetCurrentTransactionId (void)
 
TransactionId GetCurrentTransactionIdIfAny (void)
 
TransactionId GetStableLatestTransactionId (void)
 
SubTransactionId GetCurrentSubTransactionId (void)
 
FullTransactionId GetTopFullTransactionId (void)
 
FullTransactionId GetTopFullTransactionIdIfAny (void)
 
FullTransactionId GetCurrentFullTransactionId (void)
 
FullTransactionId GetCurrentFullTransactionIdIfAny (void)
 
void MarkCurrentTransactionIdLoggedIfAny (void)
 
bool SubTransactionIsActive (SubTransactionId subxid)
 
CommandId GetCurrentCommandId (bool used)
 
void SetParallelStartTimestamps (TimestampTz xact_ts, TimestampTz stmt_ts)
 
TimestampTz GetCurrentTransactionStartTimestamp (void)
 
TimestampTz GetCurrentStatementStartTimestamp (void)
 
TimestampTz GetCurrentTransactionStopTimestamp (void)
 
void SetCurrentStatementStartTimestamp (void)
 
int GetCurrentTransactionNestLevel (void)
 
bool TransactionIdIsCurrentTransactionId (TransactionId xid)
 
void CommandCounterIncrement (void)
 
void ForceSyncCommit (void)
 
void StartTransactionCommand (void)
 
void SaveTransactionCharacteristics (SavedTransactionCharacteristics *s)
 
void RestoreTransactionCharacteristics (const SavedTransactionCharacteristics *s)
 
void CommitTransactionCommand (void)
 
void AbortCurrentTransaction (void)
 
void BeginTransactionBlock (void)
 
bool EndTransactionBlock (bool chain)
 
bool PrepareTransactionBlock (const char *gid)
 
void UserAbortTransactionBlock (bool chain)
 
void BeginImplicitTransactionBlock (void)
 
void EndImplicitTransactionBlock (void)
 
void ReleaseSavepoint (const char *name)
 
void DefineSavepoint (const char *name)
 
void RollbackToSavepoint (const char *name)
 
void BeginInternalSubTransaction (const char *name)
 
void ReleaseCurrentSubTransaction (void)
 
void RollbackAndReleaseCurrentSubTransaction (void)
 
bool IsSubTransaction (void)
 
Size EstimateTransactionStateSpace (void)
 
void SerializeTransactionState (Size maxsize, char *start_address)
 
void StartParallelWorkerTransaction (char *tstatespace)
 
void EndParallelWorkerTransaction (void)
 
bool IsTransactionBlock (void)
 
bool IsTransactionOrTransactionBlock (void)
 
char TransactionBlockStatusCode (void)
 
void AbortOutOfAnyTransaction (void)
 
void PreventInTransactionBlock (bool isTopLevel, const char *stmtType)
 
void RequireTransactionBlock (bool isTopLevel, const char *stmtType)
 
void WarnNoTransactionBlock (bool isTopLevel, const char *stmtType)
 
bool IsInTransactionBlock (bool isTopLevel)
 
void RegisterXactCallback (XactCallback callback, void *arg)
 
void UnregisterXactCallback (XactCallback callback, void *arg)
 
void RegisterSubXactCallback (SubXactCallback callback, void *arg)
 
void UnregisterSubXactCallback (SubXactCallback callback, void *arg)
 
bool IsSubxactTopXidLogPending (void)
 
void MarkSubxactTopXidLogged (void)
 
int xactGetCommittedChildren (TransactionId **ptr)
 
XLogRecPtr XactLogCommitRecord (TimestampTz commit_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileNode *rels, int nstats, xl_xact_stats_item *stats, int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInval, int xactflags, TransactionId twophase_xid, const char *twophase_gid)
 
XLogRecPtr XactLogAbortRecord (TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileNode *rels, int nstats, xl_xact_stats_item *stats, int xactflags, TransactionId twophase_xid, const char *twophase_gid)
 
void xact_redo (XLogReaderState *record)
 
void xact_desc (StringInfo buf, XLogReaderState *record)
 
const char * xact_identify (uint8 info)
 
void ParseCommitRecord (uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
 
void ParseAbortRecord (uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
 
void ParsePrepareRecord (uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *parsed)
 
void EnterParallelMode (void)
 
void ExitParallelMode (void)
 
bool IsInParallelMode (void)
 

Variables

PGDLLIMPORT int DefaultXactIsoLevel
 
PGDLLIMPORT int XactIsoLevel
 
PGDLLIMPORT bool DefaultXactReadOnly
 
PGDLLIMPORT bool XactReadOnly
 
PGDLLIMPORT bool xact_is_sampled
 
PGDLLIMPORT bool DefaultXactDeferrable
 
PGDLLIMPORT bool XactDeferrable
 
PGDLLIMPORT int synchronous_commit
 
PGDLLIMPORT TransactionId CheckXidAlive
 
PGDLLIMPORT bool bsysscan
 
PGDLLIMPORT int MyXactFlags
 

Macro Definition Documentation

◆ GIDSIZE

#define GIDSIZE   200

Definition at line 31 of file xact.h.

◆ IsolationIsSerializable

#define IsolationIsSerializable ( )    (XactIsoLevel == XACT_SERIALIZABLE)

Definition at line 52 of file xact.h.

◆ IsolationUsesXactSnapshot

#define IsolationUsesXactSnapshot ( )    (XactIsoLevel >= XACT_REPEATABLE_READ)

Definition at line 51 of file xact.h.

◆ MinSizeOfXactAbort

#define MinSizeOfXactAbort   sizeof(xl_xact_abort)

Definition at line 331 of file xact.h.

◆ MinSizeOfXactAssignment

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 212 of file xact.h.

◆ MinSizeOfXactCommit

#define MinSizeOfXactCommit   (offsetof(xl_xact_commit, xact_time) + sizeof(TimestampTz))

Definition at line 315 of file xact.h.

◆ MinSizeOfXactInvals

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 288 of file xact.h.

◆ MinSizeOfXactRelfilenodes

#define MinSizeOfXactRelfilenodes   offsetof(xl_xact_relfilenodes, xnodes)

Definition at line 260 of file xact.h.

◆ MinSizeOfXactStatsItems

#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)

Definition at line 281 of file xact.h.

◆ MinSizeOfXactSubxacts

#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)

Definition at line 253 of file xact.h.

◆ SYNCHRONOUS_COMMIT_ON

#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH

Definition at line 80 of file xact.h.

◆ XACT_COMPLETION_APPLY_FEEDBACK

#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)

Definition at line 193 of file xact.h.

◆ XACT_COMPLETION_FORCE_SYNC_COMMIT

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 195 of file xact.h.

◆ XACT_COMPLETION_UPDATE_RELCACHE_FILE

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 194 of file xact.h.

◆ XACT_FLAGS_ACCESSEDTEMPNAMESPACE

#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE   (1U << 0)

Definition at line 102 of file xact.h.

◆ XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK

#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)

Definition at line 108 of file xact.h.

◆ XACT_READ_COMMITTED

#define XACT_READ_COMMITTED   1

Definition at line 37 of file xact.h.

◆ XACT_READ_UNCOMMITTED

#define XACT_READ_UNCOMMITTED   0

Definition at line 36 of file xact.h.

◆ XACT_REPEATABLE_READ

#define XACT_REPEATABLE_READ   2

Definition at line 38 of file xact.h.

◆ XACT_SERIALIZABLE

#define XACT_SERIALIZABLE   3

Definition at line 39 of file xact.h.

◆ XACT_XINFO_HAS_AE_LOCKS

#define XACT_XINFO_HAS_AE_LOCKS   (1U << 6)

Definition at line 181 of file xact.h.

◆ XACT_XINFO_HAS_DBINFO

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 175 of file xact.h.

◆ XACT_XINFO_HAS_DROPPED_STATS

#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)

Definition at line 183 of file xact.h.

◆ XACT_XINFO_HAS_GID

#define XACT_XINFO_HAS_GID   (1U << 7)

Definition at line 182 of file xact.h.

◆ XACT_XINFO_HAS_INVALS

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 178 of file xact.h.

◆ XACT_XINFO_HAS_ORIGIN

#define XACT_XINFO_HAS_ORIGIN   (1U << 5)

Definition at line 180 of file xact.h.

◆ XACT_XINFO_HAS_RELFILENODES

#define XACT_XINFO_HAS_RELFILENODES   (1U << 2)

Definition at line 177 of file xact.h.

◆ XACT_XINFO_HAS_SUBXACTS

#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)

Definition at line 176 of file xact.h.

◆ XACT_XINFO_HAS_TWOPHASE

#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)

Definition at line 179 of file xact.h.

◆ XactCompletionApplyFeedback

#define XactCompletionApplyFeedback (   xinfo)     ((xinfo & XACT_COMPLETION_APPLY_FEEDBACK) != 0)

Definition at line 198 of file xact.h.

◆ XactCompletionForceSyncCommit

#define XactCompletionForceSyncCommit (   xinfo)     ((xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) != 0)

Definition at line 202 of file xact.h.

◆ XactCompletionRelcacheInitFileInval

#define XactCompletionRelcacheInitFileInval (   xinfo)     ((xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) != 0)

Definition at line 200 of file xact.h.

◆ XLOG_XACT_ABORT

#define XLOG_XACT_ABORT   0x20

Definition at line 158 of file xact.h.

◆ XLOG_XACT_ABORT_PREPARED

#define XLOG_XACT_ABORT_PREPARED   0x40

Definition at line 160 of file xact.h.

◆ XLOG_XACT_ASSIGNMENT

#define XLOG_XACT_ASSIGNMENT   0x50

Definition at line 161 of file xact.h.

◆ XLOG_XACT_COMMIT

#define XLOG_XACT_COMMIT   0x00

Definition at line 156 of file xact.h.

◆ XLOG_XACT_COMMIT_PREPARED

#define XLOG_XACT_COMMIT_PREPARED   0x30

Definition at line 159 of file xact.h.

◆ XLOG_XACT_HAS_INFO

#define XLOG_XACT_HAS_INFO   0x80

Definition at line 169 of file xact.h.

◆ XLOG_XACT_INVALIDATIONS

#define XLOG_XACT_INVALIDATIONS   0x60

Definition at line 162 of file xact.h.

◆ XLOG_XACT_OPMASK

#define XLOG_XACT_OPMASK   0x70

Definition at line 166 of file xact.h.

◆ XLOG_XACT_PREPARE

#define XLOG_XACT_PREPARE   0x10

Definition at line 157 of file xact.h.

Typedef Documentation

◆ SavedTransactionCharacteristics

◆ SubXactCallback

typedef void(* SubXactCallback) (SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)

Definition at line 135 of file xact.h.

◆ XactCallback

typedef void(* XactCallback) (XactEvent event, void *arg)

Definition at line 125 of file xact.h.

◆ xl_xact_abort

typedef struct xl_xact_abort xl_xact_abort

◆ xl_xact_assignment

◆ xl_xact_commit

◆ xl_xact_dbinfo

◆ xl_xact_invals

◆ xl_xact_origin

◆ xl_xact_parsed_abort

◆ xl_xact_parsed_commit

◆ xl_xact_parsed_prepare

Definition at line 389 of file xact.h.

◆ xl_xact_prepare

◆ xl_xact_relfilenodes

◆ xl_xact_stats_item

◆ xl_xact_stats_items

◆ xl_xact_subxacts

◆ xl_xact_twophase

◆ xl_xact_xinfo

typedef struct xl_xact_xinfo xl_xact_xinfo

Enumeration Type Documentation

◆ SubXactEvent

Enumerator
SUBXACT_EVENT_START_SUB 
SUBXACT_EVENT_COMMIT_SUB 
SUBXACT_EVENT_ABORT_SUB 
SUBXACT_EVENT_PRE_COMMIT_SUB 

Definition at line 127 of file xact.h.

128 {
133 } SubXactEvent;
SubXactEvent
Definition: xact.h:128
@ SUBXACT_EVENT_PRE_COMMIT_SUB
Definition: xact.h:132
@ SUBXACT_EVENT_START_SUB
Definition: xact.h:129
@ SUBXACT_EVENT_ABORT_SUB
Definition: xact.h:131
@ SUBXACT_EVENT_COMMIT_SUB
Definition: xact.h:130

◆ SyncCommitLevel

Enumerator
SYNCHRONOUS_COMMIT_OFF 
SYNCHRONOUS_COMMIT_LOCAL_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_WRITE 
SYNCHRONOUS_COMMIT_REMOTE_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_APPLY 

Definition at line 68 of file xact.h.

69 {
70  SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */
71  SYNCHRONOUS_COMMIT_LOCAL_FLUSH, /* wait for local flush only */
72  SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote
73  * write */
74  SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */
75  SYNCHRONOUS_COMMIT_REMOTE_APPLY /* wait for local and remote flush and
76  * remote apply */
SyncCommitLevel
Definition: xact.h:69
@ SYNCHRONOUS_COMMIT_LOCAL_FLUSH
Definition: xact.h:71
@ SYNCHRONOUS_COMMIT_REMOTE_WRITE
Definition: xact.h:72
@ SYNCHRONOUS_COMMIT_REMOTE_APPLY
Definition: xact.h:75
@ SYNCHRONOUS_COMMIT_REMOTE_FLUSH
Definition: xact.h:74
@ SYNCHRONOUS_COMMIT_OFF
Definition: xact.h:70

◆ XactEvent

enum XactEvent
Enumerator
XACT_EVENT_COMMIT 
XACT_EVENT_PARALLEL_COMMIT 
XACT_EVENT_ABORT 
XACT_EVENT_PARALLEL_ABORT 
XACT_EVENT_PREPARE 
XACT_EVENT_PRE_COMMIT 
XACT_EVENT_PARALLEL_PRE_COMMIT 
XACT_EVENT_PRE_PREPARE 

Definition at line 113 of file xact.h.

114 {
123 } XactEvent;
XactEvent
Definition: xact.h:114
@ XACT_EVENT_PRE_PREPARE
Definition: xact.h:122
@ XACT_EVENT_COMMIT
Definition: xact.h:115
@ XACT_EVENT_PARALLEL_PRE_COMMIT
Definition: xact.h:121
@ XACT_EVENT_PARALLEL_COMMIT
Definition: xact.h:116
@ XACT_EVENT_ABORT
Definition: xact.h:117
@ XACT_EVENT_PRE_COMMIT
Definition: xact.h:120
@ XACT_EVENT_PARALLEL_ABORT
Definition: xact.h:118
@ XACT_EVENT_PREPARE
Definition: xact.h:119

Function Documentation

◆ AbortCurrentTransaction()

void AbortCurrentTransaction ( void  )

Definition at line 3293 of file xact.c.

3294 {
3296 
3297  switch (s->blockState)
3298  {
3299  case TBLOCK_DEFAULT:
3300  if (s->state == TRANS_DEFAULT)
3301  {
3302  /* we are idle, so nothing to do */
3303  }
3304  else
3305  {
3306  /*
3307  * We can get here after an error during transaction start
3308  * (state will be TRANS_START). Need to clean up the
3309  * incompletely started transaction. First, adjust the
3310  * low-level state to suppress warning message from
3311  * AbortTransaction.
3312  */
3313  if (s->state == TRANS_START)
3314  s->state = TRANS_INPROGRESS;
3315  AbortTransaction();
3317  }
3318  break;
3319 
3320  /*
3321  * If we aren't in a transaction block, we just do the basic abort
3322  * & cleanup transaction. For this purpose, we treat an implicit
3323  * transaction block as if it were a simple statement.
3324  */
3325  case TBLOCK_STARTED:
3327  AbortTransaction();
3330  break;
3331 
3332  /*
3333  * If we are in TBLOCK_BEGIN it means something screwed up right
3334  * after reading "BEGIN TRANSACTION". We assume that the user
3335  * will interpret the error as meaning the BEGIN failed to get him
3336  * into a transaction block, so we should abort and return to idle
3337  * state.
3338  */
3339  case TBLOCK_BEGIN:
3340  AbortTransaction();
3343  break;
3344 
3345  /*
3346  * We are somewhere in a transaction block and we've gotten a
3347  * failure, so we abort the transaction and set up the persistent
3348  * ABORT state. We will stay in ABORT until we get a ROLLBACK.
3349  */
3350  case TBLOCK_INPROGRESS:
3352  AbortTransaction();
3353  s->blockState = TBLOCK_ABORT;
3354  /* CleanupTransaction happens when we exit TBLOCK_ABORT_END */
3355  break;
3356 
3357  /*
3358  * Here, we failed while trying to COMMIT. Clean up the
3359  * transaction and return to idle state (we do not want to stay in
3360  * the transaction).
3361  */
3362  case TBLOCK_END:
3363  AbortTransaction();
3366  break;
3367 
3368  /*
3369  * Here, we are already in an aborted transaction state and are
3370  * waiting for a ROLLBACK, but for some reason we failed again! So
3371  * we just remain in the abort state.
3372  */
3373  case TBLOCK_ABORT:
3374  case TBLOCK_SUBABORT:
3375  break;
3376 
3377  /*
3378  * We are in a failed transaction and we got the ROLLBACK command.
3379  * We have already aborted, we just need to cleanup and go to idle
3380  * state.
3381  */
3382  case TBLOCK_ABORT_END:
3385  break;
3386 
3387  /*
3388  * We are in a live transaction and we got a ROLLBACK command.
3389  * Abort, cleanup, go to idle state.
3390  */
3391  case TBLOCK_ABORT_PENDING:
3392  AbortTransaction();
3395  break;
3396 
3397  /*
3398  * Here, we failed while trying to PREPARE. Clean up the
3399  * transaction and return to idle state (we do not want to stay in
3400  * the transaction).
3401  */
3402  case TBLOCK_PREPARE:
3403  AbortTransaction();
3406  break;
3407 
3408  /*
3409  * We got an error inside a subtransaction. Abort just the
3410  * subtransaction, and go to the persistent SUBABORT state until
3411  * we get ROLLBACK.
3412  */
3413  case TBLOCK_SUBINPROGRESS:
3416  break;
3417 
3418  /*
3419  * If we failed while trying to create a subtransaction, clean up
3420  * the broken subtransaction and abort the parent. The same
3421  * applies if we get a failure while ending a subtransaction.
3422  */
3423  case TBLOCK_SUBBEGIN:
3424  case TBLOCK_SUBRELEASE:
3425  case TBLOCK_SUBCOMMIT:
3427  case TBLOCK_SUBRESTART:
3431  break;
3432 
3433  /*
3434  * Same as above, except the Abort() was already done.
3435  */
3436  case TBLOCK_SUBABORT_END:
3440  break;
3441  }
3442 }
TransState state
Definition: xact.c:194
TBlockState blockState
Definition: xact.c:195
static void CleanupSubTransaction(void)
Definition: xact.c:5167
static void CleanupTransaction(void)
Definition: xact.c:2876
@ TRANS_INPROGRESS
Definition: xact.c:144
@ TRANS_START
Definition: xact.c:143
@ TRANS_DEFAULT
Definition: xact.c:142
static void AbortSubTransaction(void)
Definition: xact.c:5008
@ TBLOCK_DEFAULT
Definition: xact.c:159
@ TBLOCK_SUBABORT_END
Definition: xact.c:179
@ TBLOCK_STARTED
Definition: xact.c:160
@ TBLOCK_SUBCOMMIT
Definition: xact.c:177
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:165
@ TBLOCK_ABORT_END
Definition: xact.c:169
@ TBLOCK_PREPARE
Definition: xact.c:171
@ TBLOCK_ABORT_PENDING
Definition: xact.c:170
@ TBLOCK_ABORT
Definition: xact.c:168
@ TBLOCK_SUBRELEASE
Definition: xact.c:176
@ TBLOCK_SUBBEGIN
Definition: xact.c:174
@ TBLOCK_SUBABORT
Definition: xact.c:178
@ TBLOCK_SUBRESTART
Definition: xact.c:181
@ TBLOCK_INPROGRESS
Definition: xact.c:164
@ TBLOCK_END
Definition: xact.c:167
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:166
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:182
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:180
@ TBLOCK_BEGIN
Definition: xact.c:163
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:175
static void AbortTransaction(void)
Definition: xact.c:2685
static TransactionState CurrentTransactionState
Definition: xact.c:253
void AbortCurrentTransaction(void)
Definition: xact.c:3293

References AbortSubTransaction(), AbortTransaction(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::state, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, TRANS_DEFAULT, TRANS_INPROGRESS, and TRANS_START.

Referenced by _SPI_commit(), _SPI_rollback(), AutoVacLauncherMain(), PostgresMain(), ReorderBufferImmediateInvalidation(), ReorderBufferProcessTXN(), and SnapBuildClearExportedSnapshot().

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4662 of file xact.c.

4663 {
4665 
4666  /* Ensure we're not running in a doomed memory context */
4667  AtAbort_Memory();
4668 
4669  /*
4670  * Get out of any transaction or nested transaction
4671  */
4672  do
4673  {
4674  switch (s->blockState)
4675  {
4676  case TBLOCK_DEFAULT:
4677  if (s->state == TRANS_DEFAULT)
4678  {
4679  /* Not in a transaction, do nothing */
4680  }
4681  else
4682  {
4683  /*
4684  * We can get here after an error during transaction start
4685  * (state will be TRANS_START). Need to clean up the
4686  * incompletely started transaction. First, adjust the
4687  * low-level state to suppress warning message from
4688  * AbortTransaction.
4689  */
4690  if (s->state == TRANS_START)
4691  s->state = TRANS_INPROGRESS;
4692  AbortTransaction();
4694  }
4695  break;
4696  case TBLOCK_STARTED:
4697  case TBLOCK_BEGIN:
4698  case TBLOCK_INPROGRESS:
4701  case TBLOCK_END:
4702  case TBLOCK_ABORT_PENDING:
4703  case TBLOCK_PREPARE:
4704  /* In a transaction, so clean up */
4705  AbortTransaction();
4708  break;
4709  case TBLOCK_ABORT:
4710  case TBLOCK_ABORT_END:
4711 
4712  /*
4713  * AbortTransaction is already done, still need Cleanup.
4714  * However, if we failed partway through running ROLLBACK,
4715  * there will be an active portal running that command, which
4716  * we need to shut down before doing CleanupTransaction.
4717  */
4718  AtAbort_Portals();
4721  break;
4722 
4723  /*
4724  * In a subtransaction, so clean it up and abort parent too
4725  */
4726  case TBLOCK_SUBBEGIN:
4727  case TBLOCK_SUBINPROGRESS:
4728  case TBLOCK_SUBRELEASE:
4729  case TBLOCK_SUBCOMMIT:
4731  case TBLOCK_SUBRESTART:
4734  s = CurrentTransactionState; /* changed by pop */
4735  break;
4736 
4737  case TBLOCK_SUBABORT:
4738  case TBLOCK_SUBABORT_END:
4740  /* As above, but AbortSubTransaction already done */
4741  if (s->curTransactionOwner)
4742  {
4743  /* As in TBLOCK_ABORT, might have a live portal to zap */
4748  }
4750  s = CurrentTransactionState; /* changed by pop */
4751  break;
4752  }
4753  } while (s->blockState != TBLOCK_DEFAULT);
4754 
4755  /* Should be out of all subxacts now */
4756  Assert(s->parent == NULL);
4757 
4758  /* If we didn't actually have anything to do, revert to TopMemoryContext */
4759  AtCleanup_Memory();
4760 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void AtAbort_Portals(void)
Definition: portalmem.c:782
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:980
SubTransactionId subTransactionId
Definition: xact.c:191
struct TransactionStateData * parent
Definition: xact.c:211
ResourceOwner curTransactionOwner
Definition: xact.c:199
static void AtCleanup_Memory(void)
Definition: xact.c:1911
static void AtAbort_Memory(void)
Definition: xact.c:1821

References AbortSubTransaction(), AbortTransaction(), Assert(), AtAbort_Memory(), AtAbort_Portals(), AtCleanup_Memory(), AtSubAbort_Portals(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::curTransactionOwner, TransactionStateData::parent, TransactionStateData::state, TransactionStateData::subTransactionId, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, TRANS_DEFAULT, TRANS_INPROGRESS, and TRANS_START.

Referenced by DisableSubscriptionAndExit(), do_autovacuum(), perform_work_item(), RemoveTempRelationsCallback(), ShutdownPostgres(), start_apply(), and start_table_sync().

◆ BeginImplicitTransactionBlock()

void BeginImplicitTransactionBlock ( void  )

Definition at line 4122 of file xact.c.

4123 {
4125 
4126  /*
4127  * If we are in STARTED state (that is, no transaction block is open),
4128  * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4129  * block.
4130  *
4131  * For caller convenience, we consider all other transaction states as
4132  * legal here; otherwise the caller would need its own state check, which
4133  * seems rather pointless.
4134  */
4135  if (s->blockState == TBLOCK_STARTED)
4137 }

References TransactionStateData::blockState, CurrentTransactionState, TBLOCK_IMPLICIT_INPROGRESS, and TBLOCK_STARTED.

Referenced by exec_simple_query().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4490 of file xact.c.

4491 {
4493 
4494  /*
4495  * Workers synchronize transaction state at the beginning of each parallel
4496  * operation, so we can't account for new subtransactions after that
4497  * point. We might be able to make an exception for the type of
4498  * subtransaction established by this function, which is typically used in
4499  * contexts where we're going to release or roll back the subtransaction
4500  * before proceeding further, so that no enduring change to the
4501  * transaction state occurs. For now, however, we prohibit this case along
4502  * with all the others.
4503  */
4504  if (IsInParallelMode())
4505  ereport(ERROR,
4506  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4507  errmsg("cannot start subtransactions during a parallel operation")));
4508 
4509  switch (s->blockState)
4510  {
4511  case TBLOCK_STARTED:
4512  case TBLOCK_INPROGRESS:
4514  case TBLOCK_END:
4515  case TBLOCK_PREPARE:
4516  case TBLOCK_SUBINPROGRESS:
4517  /* Normal subtransaction start */
4518  PushTransaction();
4519  s = CurrentTransactionState; /* changed by push */
4520 
4521  /*
4522  * Savepoint names, like the TransactionState block itself, live
4523  * in TopTransactionContext.
4524  */
4525  if (name)
4527  break;
4528 
4529  /* These cases are invalid. */
4530  case TBLOCK_DEFAULT:
4531  case TBLOCK_BEGIN:
4533  case TBLOCK_SUBBEGIN:
4534  case TBLOCK_SUBRELEASE:
4535  case TBLOCK_SUBCOMMIT:
4536  case TBLOCK_ABORT:
4537  case TBLOCK_SUBABORT:
4538  case TBLOCK_ABORT_END:
4539  case TBLOCK_SUBABORT_END:
4540  case TBLOCK_ABORT_PENDING:
4542  case TBLOCK_SUBRESTART:
4544  elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4546  break;
4547  }
4548 
4551 }
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define FATAL
Definition: elog.h:35
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
MemoryContext TopTransactionContext
Definition: mcxt.c:53
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1292
static void PushTransaction(void)
Definition: xact.c:5200
void StartTransactionCommand(void)
Definition: xact.c:2925
bool IsInParallelMode(void)
Definition: xact.c:1065
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5480
void CommitTransactionCommand(void)
Definition: xact.c:3022

References TransactionStateData::blockState, BlockStateAsString(), CommitTransactionCommand(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), MemoryContextStrdup(), TransactionStateData::name, name, PushTransaction(), StartTransactionCommand(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and TopTransactionContext.

Referenced by exec_stmt_block(), ExecEvalJsonExprSubtrans(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), pltcl_returnnext(), pltcl_subtrans_begin(), pltcl_subtransaction(), PLy_spi_subtransaction_begin(), PLy_subtransaction_enter(), ReorderBufferImmediateInvalidation(), and ReorderBufferProcessTXN().

◆ BeginTransactionBlock()

void BeginTransactionBlock ( void  )

Definition at line 3720 of file xact.c.

3721 {
3723 
3724  switch (s->blockState)
3725  {
3726  /*
3727  * We are not inside a transaction block, so allow one to begin.
3728  */
3729  case TBLOCK_STARTED:
3730  s->blockState = TBLOCK_BEGIN;
3731  break;
3732 
3733  /*
3734  * BEGIN converts an implicit transaction block to a regular one.
3735  * (Note that we allow this even if we've already done some
3736  * commands, which is a bit odd but matches historical practice.)
3737  */
3739  s->blockState = TBLOCK_BEGIN;
3740  break;
3741 
3742  /*
3743  * Already a transaction block in progress.
3744  */
3745  case TBLOCK_INPROGRESS:
3747  case TBLOCK_SUBINPROGRESS:
3748  case TBLOCK_ABORT:
3749  case TBLOCK_SUBABORT:
3750  ereport(WARNING,
3751  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3752  errmsg("there is already a transaction in progress")));
3753  break;
3754 
3755  /* These cases are invalid. */
3756  case TBLOCK_DEFAULT:
3757  case TBLOCK_BEGIN:
3758  case TBLOCK_SUBBEGIN:
3759  case TBLOCK_END:
3760  case TBLOCK_SUBRELEASE:
3761  case TBLOCK_SUBCOMMIT:
3762  case TBLOCK_ABORT_END:
3763  case TBLOCK_SUBABORT_END:
3764  case TBLOCK_ABORT_PENDING:
3766  case TBLOCK_SUBRESTART:
3768  case TBLOCK_PREPARE:
3769  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3771  break;
3772  }
3773 }
#define WARNING
Definition: elog.h:30

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and WARNING.

Referenced by apply_handle_prepare_internal(), and standard_ProcessUtility().

◆ CommandCounterIncrement()

void CommandCounterIncrement ( void  )

Definition at line 1074 of file xact.c.

1075 {
1076  /*
1077  * If the current value of the command counter hasn't been "used" to mark
1078  * tuples, we need not increment it, since there's no need to distinguish
1079  * a read-only command from others. This helps postpone command counter
1080  * overflow, and keeps no-op CommandCounterIncrement operations cheap.
1081  */
1083  {
1084  /*
1085  * Workers synchronize transaction state at the beginning of each
1086  * parallel operation, so we can't account for new commands after that
1087  * point.
1088  */
1090  elog(ERROR, "cannot start commands during a parallel operation");
1091 
1092  currentCommandId += 1;
1094  {
1095  currentCommandId -= 1;
1096  ereport(ERROR,
1097  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1098  errmsg("cannot have more than 2^32-2 commands in a transaction")));
1099  }
1100  currentCommandIdUsed = false;
1101 
1102  /* Propagate new command ID into static snapshots */
1104 
1105  /*
1106  * Make any catalog changes done by the just-completed command visible
1107  * in the local syscache. We obviously don't need to do this after a
1108  * read-only command. (But see hacks in inval.c to make real sure we
1109  * don't think a command that queued inval messages was read-only.)
1110  */
1111  AtCCI_LocalCache();
1112  }
1113 }
#define InvalidCommandId
Definition: c.h:604
#define IsParallelWorker()
Definition: parallel.h:61
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:490
static bool currentCommandIdUsed
Definition: xact.c:261
static CommandId currentCommandId
Definition: xact.c:260
static void AtCCI_LocalCache(void)
Definition: xact.c:1538

References AtCCI_LocalCache(), currentCommandId, currentCommandIdUsed, elog, ereport, errcode(), errmsg(), ERROR, InvalidCommandId, IsInParallelMode(), IsParallelWorker, and SnapshotSetCommandId().

Referenced by _SPI_execute_plan(), acquire_inherited_sample_rows(), addFkRecurseReferenced(), addFkRecurseReferencing(), AddRoleMems(), AlterPublicationOptions(), AlterRole(), ATAddCheckConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecCmd(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropExpression(), ATExecDropIdentity(), ATExecSetCompression(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), btadjustmembers(), CloneFkReferencing(), CommitSubTransaction(), CommitTransactionCommand(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineQueryRewrite(), DefineRelation(), DefineVirtualRelation(), deleteOneObject(), DelRoleMems(), DetachPartitionFinalize(), DropClonedTriggersFromPartition(), DropRole(), end_replication_step(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Parameter(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), execute_sql_string(), ExplainOnePlan(), finish_heap_swap(), fmgr_sql(), hashadjustmembers(), ImportForeignSchema(), index_build(), index_create(), IndexSetParentIndex(), InitTempTableNamespace(), inv_create(), inv_drop(), inv_truncate(), inv_write(), LogicalRepSyncTableStart(), make_new_heap(), makeConfigurationDependencies(), moveArrayTypeName(), objectNamesToOids(), OperatorShellMake(), OperatorUpd(), pg_import_system_collations(), PortalRunMulti(), ProcedureCreate(), ProcessUtilitySlow(), recordExtensionInitPrivWorker(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), RelationSetNewRelfilenode(), RemoveRoleFromObjectPolicy(), RenumberEnumType(), replorigin_create(), replorigin_drop_guts(), ri_PerformCheck(), SetDefaultACL(), SetMatViewPopulatedState(), shdepReassignOwned(), SPI_cursor_open_internal(), standard_ProcessUtility(), StoreConstraints(), StorePartitionBound(), tryAttachPartitionForeignKey(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3022 of file xact.c.

3023 {
3026 
3028 
3029  switch (s->blockState)
3030  {
3031  /*
3032  * These shouldn't happen. TBLOCK_DEFAULT means the previous
3033  * StartTransactionCommand didn't set the STARTED state
3034  * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended
3035  * by EndParallelWorkerTransaction(), not this function.
3036  */
3037  case TBLOCK_DEFAULT:
3039  elog(FATAL, "CommitTransactionCommand: unexpected state %s",
3041  break;
3042 
3043  /*
3044  * If we aren't in a transaction block, just do our usual
3045  * transaction commit, and return to the idle state.
3046  */
3047  case TBLOCK_STARTED:
3050  break;
3051 
3052  /*
3053  * We are completing a "BEGIN TRANSACTION" command, so we change
3054  * to the "transaction block in progress" state and return. (We
3055  * assume the BEGIN did nothing to the database, so we need no
3056  * CommandCounterIncrement.)
3057  */
3058  case TBLOCK_BEGIN:
3060  break;
3061 
3062  /*
3063  * This is the case when we have finished executing a command
3064  * someplace within a transaction block. We increment the command
3065  * counter and return.
3066  */
3067  case TBLOCK_INPROGRESS:
3069  case TBLOCK_SUBINPROGRESS:
3071  break;
3072 
3073  /*
3074  * We are completing a "COMMIT" command. Do it and return to the
3075  * idle state.
3076  */
3077  case TBLOCK_END:
3080  if (s->chain)
3081  {
3082  StartTransaction();
3084  s->chain = false;
3086  }
3087  break;
3088 
3089  /*
3090  * Here we are in the middle of a transaction block but one of the
3091  * commands caused an abort so we do nothing but remain in the
3092  * abort state. Eventually we will get a ROLLBACK command.
3093  */
3094  case TBLOCK_ABORT:
3095  case TBLOCK_SUBABORT:
3096  break;
3097 
3098  /*
3099  * Here we were in an aborted transaction block and we just got
3100  * the ROLLBACK command from the user, so clean up the
3101  * already-aborted transaction and return to the idle state.
3102  */
3103  case TBLOCK_ABORT_END:
3106  if (s->chain)
3107  {
3108  StartTransaction();
3110  s->chain = false;
3112  }
3113  break;
3114 
3115  /*
3116  * Here we were in a perfectly good transaction block but the user
3117  * told us to ROLLBACK anyway. We have to abort the transaction
3118  * and then clean up.
3119  */
3120  case TBLOCK_ABORT_PENDING:
3121  AbortTransaction();
3124  if (s->chain)
3125  {
3126  StartTransaction();
3128  s->chain = false;
3130  }
3131  break;
3132 
3133  /*
3134  * We are completing a "PREPARE TRANSACTION" command. Do it and
3135  * return to the idle state.
3136  */
3137  case TBLOCK_PREPARE:
3140  break;
3141 
3142  /*
3143  * We were just issued a SAVEPOINT inside a transaction block.
3144  * Start a subtransaction. (DefineSavepoint already did
3145  * PushTransaction, so as to have someplace to put the SUBBEGIN
3146  * state.)
3147  */
3148  case TBLOCK_SUBBEGIN:
3151  break;
3152 
3153  /*
3154  * We were issued a RELEASE command, so we end the current
3155  * subtransaction and return to the parent transaction. The parent
3156  * might be ended too, so repeat till we find an INPROGRESS
3157  * transaction or subtransaction.
3158  */
3159  case TBLOCK_SUBRELEASE:
3160  do
3161  {
3163  s = CurrentTransactionState; /* changed by pop */
3164  } while (s->blockState == TBLOCK_SUBRELEASE);
3165 
3168  break;
3169 
3170  /*
3171  * We were issued a COMMIT, so we end the current subtransaction
3172  * hierarchy and perform final commit. We do this by rolling up
3173  * any subtransactions into their parent, which leads to O(N^2)
3174  * operations with respect to resource owners - this isn't that
3175  * bad until we approach a thousands of savepoints but is
3176  * necessary for correctness should after triggers create new
3177  * resource owners.
3178  */
3179  case TBLOCK_SUBCOMMIT:
3180  do
3181  {
3183  s = CurrentTransactionState; /* changed by pop */
3184  } while (s->blockState == TBLOCK_SUBCOMMIT);
3185  /* If we had a COMMIT command, finish off the main xact too */
3186  if (s->blockState == TBLOCK_END)
3187  {
3188  Assert(s->parent == NULL);
3191  if (s->chain)
3192  {
3193  StartTransaction();
3195  s->chain = false;
3197  }
3198  }
3199  else if (s->blockState == TBLOCK_PREPARE)
3200  {
3201  Assert(s->parent == NULL);
3204  }
3205  else
3206  elog(ERROR, "CommitTransactionCommand: unexpected state %s",
3208  break;
3209 
3210  /*
3211  * The current already-failed subtransaction is ending due to a
3212  * ROLLBACK or ROLLBACK TO command, so pop it and recursively
3213  * examine the parent (which could be in any of several states).
3214  */
3215  case TBLOCK_SUBABORT_END:
3218  break;
3219 
3220  /*
3221  * As above, but it's not dead yet, so abort first.
3222  */
3227  break;
3228 
3229  /*
3230  * The current subtransaction is the target of a ROLLBACK TO
3231  * command. Abort and pop it, then start a new subtransaction
3232  * with the same name.
3233  */
3234  case TBLOCK_SUBRESTART:
3235  {
3236  char *name;
3237  int savepointLevel;
3238 
3239  /* save name and keep Cleanup from freeing it */
3240  name = s->name;
3241  s->name = NULL;
3242  savepointLevel = s->savepointLevel;
3243 
3246 
3247  DefineSavepoint(NULL);
3248  s = CurrentTransactionState; /* changed by push */
3249  s->name = name;
3250  s->savepointLevel = savepointLevel;
3251 
3252  /* This is the same as TBLOCK_SUBBEGIN case */
3256  }
3257  break;
3258 
3259  /*
3260  * Same as above, but the subtransaction had already failed, so we
3261  * don't need AbortSubTransaction.
3262  */
3264  {
3265  char *name;
3266  int savepointLevel;
3267 
3268  /* save name and keep Cleanup from freeing it */
3269  name = s->name;
3270  s->name = NULL;
3271  savepointLevel = s->savepointLevel;
3272 
3274 
3275  DefineSavepoint(NULL);
3276  s = CurrentTransactionState; /* changed by push */
3277  s->name = name;
3278  s->savepointLevel = savepointLevel;
3279 
3280  /* This is the same as TBLOCK_SUBBEGIN case */
3284  }
3285  break;
3286  }
3287 }
#define AssertState(condition)
Definition: c.h:807
void SaveTransactionCharacteristics(SavedTransactionCharacteristics *s)
Definition: xact.c:3002
void RestoreTransactionCharacteristics(const SavedTransactionCharacteristics *s)
Definition: xact.c:3010
static void StartTransaction(void)
Definition: xact.c:1982
void DefineSavepoint(const char *name)
Definition: xact.c:4169
static void CommitSubTransaction(void)
Definition: xact.c:4899
void CommandCounterIncrement(void)
Definition: xact.c:1074
static void CommitTransaction(void)
Definition: xact.c:2141
static void PrepareTransaction(void)
Definition: xact.c:2400
static void StartSubTransaction(void)
Definition: xact.c:4862

References AbortSubTransaction(), AbortTransaction(), Assert(), AssertState, TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CleanupSubTransaction(), CleanupTransaction(), CommandCounterIncrement(), CommitSubTransaction(), CommitTransaction(), CurrentTransactionState, DefineSavepoint(), elog, ERROR, FATAL, TransactionStateData::name, name, TransactionStateData::parent, PrepareTransaction(), RestoreTransactionCharacteristics(), TransactionStateData::savepointLevel, SaveTransactionCharacteristics(), StartSubTransaction(), StartTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by _SPI_commit(), AllTablesyncsReady(), apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), apply_handle_stream_abort(), apply_handle_stream_prepare(), apply_handle_stream_stop(), ApplyWorkerMain(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), exec_replication_command(), finish_xact_command(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), ParallelWorkerMain(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), shell_check_detail(), vacuum(), and vacuum_rel().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4169 of file xact.c.

4170 {
4172 
4173  /*
4174  * Workers synchronize transaction state at the beginning of each parallel
4175  * operation, so we can't account for new subtransactions after that
4176  * point. (Note that this check will certainly error out if s->blockState
4177  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4178  * below.)
4179  */
4180  if (IsInParallelMode())
4181  ereport(ERROR,
4182  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4183  errmsg("cannot define savepoints during a parallel operation")));
4184 
4185  switch (s->blockState)
4186  {
4187  case TBLOCK_INPROGRESS:
4188  case TBLOCK_SUBINPROGRESS:
4189  /* Normal subtransaction start */
4190  PushTransaction();
4191  s = CurrentTransactionState; /* changed by push */
4192 
4193  /*
4194  * Savepoint names, like the TransactionState block itself, live
4195  * in TopTransactionContext.
4196  */
4197  if (name)
4199  break;
4200 
4201  /*
4202  * We disallow savepoint commands in implicit transaction blocks.
4203  * There would be no great difficulty in allowing them so far as
4204  * this module is concerned, but a savepoint seems inconsistent
4205  * with exec_simple_query's behavior of abandoning the whole query
4206  * string upon error. Also, the point of an implicit transaction
4207  * block (as opposed to a regular one) is to automatically close
4208  * after an error, so it's hard to see how a savepoint would fit
4209  * into that.
4210  *
4211  * The error messages for this are phrased as if there were no
4212  * active transaction block at all, which is historical but
4213  * perhaps could be improved.
4214  */
4216  ereport(ERROR,
4217  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4218  /* translator: %s represents an SQL statement name */
4219  errmsg("%s can only be used in transaction blocks",
4220  "SAVEPOINT")));
4221  break;
4222 
4223  /* These cases are invalid. */
4224  case TBLOCK_DEFAULT:
4225  case TBLOCK_STARTED:
4226  case TBLOCK_BEGIN:
4228  case TBLOCK_SUBBEGIN:
4229  case TBLOCK_END:
4230  case TBLOCK_SUBRELEASE:
4231  case TBLOCK_SUBCOMMIT:
4232  case TBLOCK_ABORT:
4233  case TBLOCK_SUBABORT:
4234  case TBLOCK_ABORT_END:
4235  case TBLOCK_SUBABORT_END:
4236  case TBLOCK_ABORT_PENDING:
4238  case TBLOCK_SUBRESTART:
4240  case TBLOCK_PREPARE:
4241  elog(FATAL, "DefineSavepoint: unexpected state %s",
4243  break;
4244  }
4245 }

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), MemoryContextStrdup(), TransactionStateData::name, name, PushTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and TopTransactionContext.

Referenced by CommitTransactionCommand(), and standard_ProcessUtility().

◆ EndImplicitTransactionBlock()

void EndImplicitTransactionBlock ( void  )

Definition at line 4147 of file xact.c.

4148 {
4150 
4151  /*
4152  * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4153  * allowing CommitTransactionCommand to commit whatever happened during
4154  * the implicit transaction block as though it were a single statement.
4155  *
4156  * For caller convenience, we consider all other transaction states as
4157  * legal here; otherwise the caller would need its own state check, which
4158  * seems rather pointless.
4159  */
4162 }

References TransactionStateData::blockState, CurrentTransactionState, TBLOCK_IMPLICIT_INPROGRESS, and TBLOCK_STARTED.

Referenced by exec_simple_query().

◆ EndParallelWorkerTransaction()

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)

Definition at line 3840 of file xact.c.

3841 {
3843  bool result = false;
3844 
3845  switch (s->blockState)
3846  {
3847  /*
3848  * We are in a transaction block, so tell CommitTransactionCommand
3849  * to COMMIT.
3850  */
3851  case TBLOCK_INPROGRESS:
3852  s->blockState = TBLOCK_END;
3853  result = true;
3854  break;
3855 
3856  /*
3857  * We are in an implicit transaction block. If AND CHAIN was
3858  * specified, error. Otherwise commit, but issue a warning
3859  * because there was no explicit BEGIN before this.
3860  */
3862  if (chain)
3863  ereport(ERROR,
3864  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3865  /* translator: %s represents an SQL statement name */
3866  errmsg("%s can only be used in transaction blocks",
3867  "COMMIT AND CHAIN")));
3868  else
3869  ereport(WARNING,
3870  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3871  errmsg("there is no transaction in progress")));
3872  s->blockState = TBLOCK_END;
3873  result = true;
3874  break;
3875 
3876  /*
3877  * We are in a failed transaction block. Tell
3878  * CommitTransactionCommand it's time to exit the block.
3879  */
3880  case TBLOCK_ABORT:
3882  break;
3883 
3884  /*
3885  * We are in a live subtransaction block. Set up to subcommit all
3886  * open subtransactions and then commit the main transaction.
3887  */
3888  case TBLOCK_SUBINPROGRESS:
3889  while (s->parent != NULL)
3890  {
3891  if (s->blockState == TBLOCK_SUBINPROGRESS)
3893  else
3894  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3896  s = s->parent;
3897  }
3898  if (s->blockState == TBLOCK_INPROGRESS)
3899  s->blockState = TBLOCK_END;
3900  else
3901  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3903  result = true;
3904  break;
3905 
3906  /*
3907  * Here we are inside an aborted subtransaction. Treat the COMMIT
3908  * as ROLLBACK: set up to abort everything and exit the main
3909  * transaction.
3910  */
3911  case TBLOCK_SUBABORT:
3912  while (s->parent != NULL)
3913  {
3914  if (s->blockState == TBLOCK_SUBINPROGRESS)
3916  else if (s->blockState == TBLOCK_SUBABORT)
3918  else
3919  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3921  s = s->parent;
3922  }
3923  if (s->blockState == TBLOCK_INPROGRESS)
3925  else if (s->blockState == TBLOCK_ABORT)
3927  else
3928  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3930  break;
3931 
3932  /*
3933  * The user issued COMMIT when not inside a transaction. For
3934  * COMMIT without CHAIN, issue a WARNING, staying in
3935  * TBLOCK_STARTED state. The upcoming call to
3936  * CommitTransactionCommand() will then close the transaction and
3937  * put us back into the default state. For COMMIT AND CHAIN,
3938  * error.
3939  */
3940  case TBLOCK_STARTED:
3941  if (chain)
3942  ereport(ERROR,
3943  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3944  /* translator: %s represents an SQL statement name */
3945  errmsg("%s can only be used in transaction blocks",
3946  "COMMIT AND CHAIN")));
3947  else
3948  ereport(WARNING,
3949  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3950  errmsg("there is no transaction in progress")));
3951  result = true;
3952  break;
3953 
3954  /*
3955  * The user issued a COMMIT that somehow ran inside a parallel
3956  * worker. We can't cope with that.
3957  */
3959  ereport(FATAL,
3960  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3961  errmsg("cannot commit during a parallel operation")));
3962  break;
3963 
3964  /* These cases are invalid. */
3965  case TBLOCK_DEFAULT:
3966  case TBLOCK_BEGIN:
3967  case TBLOCK_SUBBEGIN:
3968  case TBLOCK_END:
3969  case TBLOCK_SUBRELEASE:
3970  case TBLOCK_SUBCOMMIT:
3971  case TBLOCK_ABORT_END:
3972  case TBLOCK_SUBABORT_END:
3973  case TBLOCK_ABORT_PENDING:
3975  case TBLOCK_SUBRESTART:
3977  case TBLOCK_PREPARE:
3978  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3980  break;
3981  }
3982 
3984  s->blockState == TBLOCK_END ||
3985  s->blockState == TBLOCK_ABORT_END ||
3987 
3988  s->chain = chain;
3989 
3990  return result;
3991 }

References Assert(), TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, TransactionStateData::parent, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and WARNING.

Referenced by PrepareTransactionBlock(), and standard_ProcessUtility().

◆ EnterParallelMode()

void EnterParallelMode ( void  )

◆ EstimateTransactionStateSpace()

Size EstimateTransactionStateSpace ( void  )

Definition at line 5294 of file xact.c.

5295 {
5296  TransactionState s;
5297  Size nxids = 0;
5299 
5300  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5301  {
5303  nxids = add_size(nxids, 1);
5304  nxids = add_size(nxids, s->nChildXids);
5305  }
5306 
5307  return add_size(size, mul_size(sizeof(TransactionId), nxids));
5308 }
uint32 TransactionId
Definition: c.h:587
size_t Size
Definition: c.h:540
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
Size mul_size(Size s1, Size s2)
Definition: shmem.c:519
FullTransactionId fullTransactionId
Definition: xact.c:190
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:232

References add_size(), CurrentTransactionState, TransactionStateData::fullTransactionId, FullTransactionIdIsValid, mul_size(), TransactionStateData::nChildXids, TransactionStateData::parent, and SerializedTransactionStateHeaderSize.

Referenced by InitializeParallelDSM().

◆ ExitParallelMode()

void ExitParallelMode ( void  )

◆ ForceSyncCommit()

void ForceSyncCommit ( void  )

Definition at line 1124 of file xact.c.

1125 {
1126  forceSyncCommit = true;
1127 }
static bool forceSyncCommit
Definition: xact.c:283

References forceSyncCommit.

Referenced by createdb(), CreateTableSpace(), dropdb(), DropTableSpace(), and movedb().

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 814 of file xact.c.

815 {
816  /* this is global to a transaction, not subtransaction-local */
817  if (used)
818  {
819  /*
820  * Forbid setting currentCommandIdUsed in a parallel worker, because
821  * we have no provision for communicating this back to the leader. We
822  * could relax this restriction when currentCommandIdUsed was already
823  * true at the start of the parallel operation.
824  */
826  currentCommandIdUsed = true;
827  }
828  return currentCommandId;
829 }

References Assert(), currentCommandId, currentCommandIdUsed, and IsParallelWorker.

Referenced by ATRewriteTable(), CatalogTuplesMultiInsertWithInfo(), CopyFrom(), create_edata_for_relation(), create_estate_for_relation(), GetSnapshotData(), GetSnapshotDataReuse(), intorel_startup(), pgrowlocks(), RegisterRelcacheInvalidation(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), simple_heap_delete(), simple_heap_insert(), simple_heap_update(), simple_table_tuple_delete(), simple_table_tuple_insert(), simple_table_tuple_update(), standard_ExecutorStart(), toast_save_datum(), transientrel_startup(), and UpdateActiveSnapshotCommandId().

◆ GetCurrentFullTransactionId()

FullTransactionId GetCurrentFullTransactionId ( void  )

Definition at line 499 of file xact.c.

500 {
502 
505  return s->fullTransactionId;
506 }
static void AssignTransactionId(TransactionState s)
Definition: xact.c:622

References AssignTransactionId(), CurrentTransactionState, TransactionStateData::fullTransactionId, and FullTransactionIdIsValid.

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 517 of file xact.c.

518 {
520 }

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 860 of file xact.c.

861 {
862  return stmtStartTimestamp;
863 }
static TimestampTz stmtStartTimestamp
Definition: xact.c:271

References stmtStartTimestamp.

Referenced by check_log_duration(), CreatePortal(), InitializeParallelDSM(), pgstat_report_activity(), statement_timestamp(), and StorePreparedStatement().

◆ GetCurrentSubTransactionId()

◆ GetCurrentTransactionId()

◆ GetCurrentTransactionIdIfAny()

◆ GetCurrentTransactionNestLevel()

◆ GetCurrentTransactionStartTimestamp()

TimestampTz GetCurrentTransactionStartTimestamp ( void  )

Definition at line 851 of file xact.c.

852 {
853  return xactStartTimestamp;
854 }
static TimestampTz xactStartTimestamp
Definition: xact.c:270

References xactStartTimestamp.

Referenced by GetCurrentTimeUsec(), GetSQLCurrentTimestamp(), GetSQLLocalTimestamp(), InitializeParallelDSM(), now(), pg_timezone_abbrevs(), pg_timezone_names(), and timetz_zone().

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 872 of file xact.c.

873 {
874  if (xactStopTimestamp != 0)
875  return xactStopTimestamp;
876  return GetCurrentTimestamp();
877 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1574
static TimestampTz xactStopTimestamp
Definition: xact.c:272

References GetCurrentTimestamp(), and xactStopTimestamp.

Referenced by pgstat_report_stat().

◆ GetStableLatestTransactionId()

TransactionId GetStableLatestTransactionId ( void  )

Definition at line 594 of file xact.c.

595 {
597  static TransactionId stablexid = InvalidTransactionId;
598 
599  if (lxid != MyProc->lxid)
600  {
601  lxid = MyProc->lxid;
602  stablexid = GetTopTransactionIdIfAny();
603  if (!TransactionIdIsValid(stablexid))
604  stablexid = ReadNextTransactionId();
605  }
606 
607  Assert(TransactionIdIsValid(stablexid));
608 
609  return stablexid;
610 }
uint32 LocalTransactionId
Definition: c.h:589
#define InvalidLocalTransactionId
Definition: lock.h:70
PGPROC * MyProc
Definition: proc.c:68
LocalTransactionId lxid
Definition: proc.h:181
static TransactionId ReadNextTransactionId(void)
Definition: transam.h:316
#define InvalidTransactionId
Definition: transam.h:31
#define TransactionIdIsValid(xid)
Definition: transam.h:41
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:428

References Assert(), GetTopTransactionIdIfAny(), InvalidLocalTransactionId, InvalidTransactionId, PGPROC::lxid, MyProc, ReadNextTransactionId(), and TransactionIdIsValid.

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 470 of file xact.c.

471 {
475 }
static TransactionStateData TopTransactionStateData
Definition: xact.c:240
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:124

References AssignTransactionId(), FullTransactionIdIsValid, TopTransactionStateData, and XactTopFullTransactionId.

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 486 of file xact.c.

487 {
489 }

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3575 of file xact.c.

3576 {
3577  /*
3578  * Return true on same conditions that would make
3579  * PreventInTransactionBlock error out
3580  */
3581  if (IsTransactionBlock())
3582  return true;
3583 
3584  if (IsSubTransaction())
3585  return true;
3586 
3587  if (!isTopLevel)
3588  return true;
3589 
3592  return true;
3593 
3594  return false;
3595 }
bool IsSubTransaction(void)
Definition: xact.c:4839
bool IsTransactionBlock(void)
Definition: xact.c:4766

References TransactionStateData::blockState, CurrentTransactionState, IsSubTransaction(), IsTransactionBlock(), TBLOCK_DEFAULT, and TBLOCK_STARTED.

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 546 of file xact.c.

547 {
548  /* check whether it is already logged */
550  return false;
551 
552  /* wal_level has to be logical */
553  if (!XLogLogicalInfoActive())
554  return false;
555 
556  /* we need to be in a transaction state */
557  if (!IsTransactionState())
558  return false;
559 
560  /* it has to be a subtransaction */
561  if (!IsSubTransaction())
562  return false;
563 
564  /* the subtransaction has to have a XID assigned */
566  return false;
567 
568  return true;
569 }
bool IsTransactionState(void)
Definition: xact.c:374
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:458
#define XLogLogicalInfoActive()
Definition: xlog.h:121

References CurrentTransactionState, GetCurrentTransactionIdIfAny(), IsSubTransaction(), IsTransactionState(), TransactionStateData::topXidLogged, TransactionIdIsValid, and XLogLogicalInfoActive.

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

bool IsTransactionBlock ( void  )

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 374 of file xact.c.

375 {
377 
378  /*
379  * TRANS_DEFAULT and TRANS_ABORT are obviously unsafe states. However, we
380  * also reject the startup/shutdown states TRANS_START, TRANS_COMMIT,
381  * TRANS_PREPARE since it might be too soon or too late within those
382  * transition states to do anything interesting. Hence, the only "valid"
383  * state is TRANS_INPROGRESS.
384  */
385  return (s->state == TRANS_INPROGRESS);
386 }

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by apply_handle_commit_internal(), apply_handle_origin(), apply_handle_stream_stop(), begin_replication_step(), check_client_encoding(), check_default_table_access_method(), check_default_tablespace(), check_role(), check_session_authorization(), check_temp_tablespaces(), check_transaction_read_only(), check_TSCurrentConfig(), check_XactIsoLevel(), clear_subscription_skip_lsn(), CreateInitDecodingContext(), FetchTableStates(), InitializeClientEncoding(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pg_attribute_noreturn(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), RelationClearRelation(), RelationIdGetRelation(), RelationInitPhysicalAddr(), RelationReloadNailed(), replorigin_create(), replorigin_drop_by_name(), SearchCatCacheInternal(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), and SocketBackend().

◆ MarkCurrentTransactionIdLoggedIfAny()

void MarkCurrentTransactionIdLoggedIfAny ( void  )

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )

Definition at line 578 of file xact.c.

579 {
581 
583 }
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:546

References Assert(), CurrentTransactionState, IsSubxactTopXidLogPending(), and TransactionStateData::topXidLogged.

Referenced by XLogInsertRecord().

◆ ParseAbortRecord()

void ParseAbortRecord ( uint8  info,
xl_xact_abort xlrec,
xl_xact_parsed_abort parsed 
)

Definition at line 141 of file xactdesc.c.

142 {
143  char *data = ((char *) xlrec) + MinSizeOfXactAbort;
144 
145  memset(parsed, 0, sizeof(*parsed));
146 
147  parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
148  * present */
149 
150  parsed->xact_time = xlrec->xact_time;
151 
152  if (info & XLOG_XACT_HAS_INFO)
153  {
154  xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
155 
156  parsed->xinfo = xl_xinfo->xinfo;
157 
158  data += sizeof(xl_xact_xinfo);
159  }
160 
161  if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
162  {
163  xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
164 
165  parsed->dbId = xl_dbinfo->dbId;
166  parsed->tsId = xl_dbinfo->tsId;
167 
168  data += sizeof(xl_xact_dbinfo);
169  }
170 
171  if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
172  {
173  xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
174 
175  parsed->nsubxacts = xl_subxacts->nsubxacts;
176  parsed->subxacts = xl_subxacts->subxacts;
177 
179  data += parsed->nsubxacts * sizeof(TransactionId);
180  }
181 
182  if (parsed->xinfo & XACT_XINFO_HAS_RELFILENODES)
183  {
184  xl_xact_relfilenodes *xl_relfilenodes = (xl_xact_relfilenodes *) data;
185 
186  parsed->nrels = xl_relfilenodes->nrels;
187  parsed->xnodes = xl_relfilenodes->xnodes;
188 
190  data += xl_relfilenodes->nrels * sizeof(RelFileNode);
191  }
192 
193  if (parsed->xinfo & XACT_XINFO_HAS_DROPPED_STATS)
194  {
196 
197  parsed->nstats = xl_drops->nitems;
198  parsed->stats = xl_drops->items;
199 
201  data += xl_drops->nitems * sizeof(xl_xact_stats_item);
202  }
203 
204  if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
205  {
206  xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
207 
208  parsed->twophase_xid = xl_twophase->xid;
209 
210  data += sizeof(xl_xact_twophase);
211 
212  if (parsed->xinfo & XACT_XINFO_HAS_GID)
213  {
214  strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
215  data += strlen(data) + 1;
216  }
217  }
218 
219  /* Note: no alignment is guaranteed after this point */
220 
221  if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
222  {
223  xl_xact_origin xl_origin;
224 
225  /* no alignment is guaranteed, so copy onto stack */
226  memcpy(&xl_origin, data, sizeof(xl_origin));
227 
228  parsed->origin_lsn = xl_origin.origin_lsn;
229  parsed->origin_timestamp = xl_origin.origin_timestamp;
230 
231  data += sizeof(xl_xact_origin);
232  }
233 }
const void * data
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
struct RelFileNode RelFileNode
TimestampTz xact_time
Definition: xact.h:319
Oid tsId
Definition: xact.h:245
Oid dbId
Definition: xact.h:244
TimestampTz origin_timestamp
Definition: xact.h:298
XLogRecPtr origin_lsn
Definition: xact.h:297
xl_xact_stats_item * stats
Definition: xact.h:406
TransactionId twophase_xid
Definition: xact.h:408
TimestampTz xact_time
Definition: xact.h:393
RelFileNode * xnodes
Definition: xact.h:403
TransactionId * subxacts
Definition: xact.h:400
XLogRecPtr origin_lsn
Definition: xact.h:411
char twophase_gid[GIDSIZE]
Definition: xact.h:409
TimestampTz origin_timestamp
Definition: xact.h:412
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:258
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:279
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:251
int nsubxacts
Definition: xact.h:250
TransactionId xid
Definition: xact.h:292
uint32 xinfo
Definition: xact.h:239
struct xl_xact_stats_item xl_xact_stats_item
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:177
#define MinSizeOfXactSubxacts
Definition: xact.h:253
struct xl_xact_dbinfo xl_xact_dbinfo
#define XACT_XINFO_HAS_GID
Definition: xact.h:182
struct xl_xact_origin xl_xact_origin
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:180
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:179
#define MinSizeOfXactStatsItems
Definition: xact.h:281
#define MinSizeOfXactRelfilenodes
Definition: xact.h:260
#define MinSizeOfXactAbort
Definition: xact.h:331
struct xl_xact_xinfo xl_xact_xinfo
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:175
struct xl_xact_twophase xl_xact_twophase
#define XLOG_XACT_HAS_INFO
Definition: xact.h:169
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:176
#define XACT_XINFO_HAS_DROPPED_STATS
Definition: xact.h:183

References data, xl_xact_dbinfo::dbId, xl_xact_parsed_abort::dbId, xl_xact_stats_items::items, MinSizeOfXactAbort, MinSizeOfXactRelfilenodes, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, xl_xact_stats_items::nitems, xl_xact_relfilenodes::nrels, xl_xact_parsed_abort::nrels, xl_xact_parsed_abort::nstats, xl_xact_subxacts::nsubxacts, xl_xact_parsed_abort::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_parsed_abort::origin_lsn, xl_xact_origin::origin_timestamp, xl_xact_parsed_abort::origin_timestamp, xl_xact_parsed_abort::stats, strlcpy(), xl_xact_subxacts::subxacts, xl_xact_parsed_abort::subxacts, xl_xact_dbinfo::tsId, xl_xact_parsed_abort::tsId, xl_xact_parsed_abort::twophase_gid, xl_xact_parsed_abort::twophase_xid, xl_xact_abort::xact_time, xl_xact_parsed_abort::xact_time, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, xl_xact_parsed_abort::xinfo, XLOG_XACT_HAS_INFO, xl_xact_relfilenodes::xnodes, and xl_xact_parsed_abort::xnodes.

Referenced by recoveryStopsAfter(), recoveryStopsBefore(), xact_decode(), xact_desc_abort(), and xact_redo().

◆ ParseCommitRecord()

void ParseCommitRecord ( uint8  info,
xl_xact_commit xlrec,
xl_xact_parsed_commit parsed 
)

Definition at line 35 of file xactdesc.c.

36 {
37  char *data = ((char *) xlrec) + MinSizeOfXactCommit;
38 
39  memset(parsed, 0, sizeof(*parsed));
40 
41  parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
42  * present */
43 
44  parsed->xact_time = xlrec->xact_time;
45 
46  if (info & XLOG_XACT_HAS_INFO)
47  {
48  xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
49 
50  parsed->xinfo = xl_xinfo->xinfo;
51 
52  data += sizeof(xl_xact_xinfo);
53  }
54 
55  if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
56  {
57  xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
58 
59  parsed->dbId = xl_dbinfo->dbId;
60  parsed->tsId = xl_dbinfo->tsId;
61 
62  data += sizeof(xl_xact_dbinfo);
63  }
64 
65  if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
66  {
67  xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
68 
69  parsed->nsubxacts = xl_subxacts->nsubxacts;
70  parsed->subxacts = xl_subxacts->subxacts;
71 
73  data += parsed->nsubxacts * sizeof(TransactionId);
74  }
75 
76  if (parsed->xinfo & XACT_XINFO_HAS_RELFILENODES)
77  {
78  xl_xact_relfilenodes *xl_relfilenodes = (xl_xact_relfilenodes *) data;
79 
80  parsed->nrels = xl_relfilenodes->nrels;
81  parsed->xnodes = xl_relfilenodes->xnodes;
82 
84  data += xl_relfilenodes->nrels * sizeof(RelFileNode);
85  }
86 
87  if (parsed->xinfo & XACT_XINFO_HAS_DROPPED_STATS)
88  {
90 
91  parsed->nstats = xl_drops->nitems;
92  parsed->stats = xl_drops->items;
93 
95  data += xl_drops->nitems * sizeof(xl_xact_stats_item);
96  }
97 
98  if (parsed->xinfo & XACT_XINFO_HAS_INVALS)
99  {
100  xl_xact_invals *xl_invals = (xl_xact_invals *) data;
101 
102  parsed->nmsgs = xl_invals->nmsgs;
103  parsed->msgs = xl_invals->msgs;
104 
106  data += xl_invals->nmsgs * sizeof(SharedInvalidationMessage);
107  }
108 
109  if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
110  {
111  xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
112 
113  parsed->twophase_xid = xl_twophase->xid;
114 
115  data += sizeof(xl_xact_twophase);
116 
117  if (parsed->xinfo & XACT_XINFO_HAS_GID)
118  {
119  strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
120  data += strlen(data) + 1;
121  }
122  }
123 
124  /* Note: no alignment is guaranteed after this point */
125 
126  if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
127  {
128  xl_xact_origin xl_origin;
129 
130  /* no alignment is guaranteed, so copy onto stack */
131  memcpy(&xl_origin, data, sizeof(xl_origin));
132 
133  parsed->origin_lsn = xl_origin.origin_lsn;
134  parsed->origin_timestamp = xl_origin.origin_timestamp;
135 
136  data += sizeof(xl_xact_origin);
137  }
138 }
TimestampTz xact_time
Definition: xact.h:303
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:286
int nmsgs
Definition: xact.h:285
xl_xact_stats_item * stats
Definition: xact.h:373
TimestampTz xact_time
Definition: xact.h:360
TransactionId twophase_xid
Definition: xact.h:378
RelFileNode * xnodes
Definition: xact.h:370
TimestampTz origin_timestamp
Definition: xact.h:386
TransactionId * subxacts
Definition: xact.h:367
char twophase_gid[GIDSIZE]
Definition: xact.h:379
XLogRecPtr origin_lsn
Definition: xact.h:385
SharedInvalidationMessage * msgs
Definition: xact.h:376
#define MinSizeOfXactInvals
Definition: xact.h:288
#define MinSizeOfXactCommit
Definition: xact.h:315
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:178

References data, xl_xact_dbinfo::dbId, xl_xact_parsed_commit::dbId, xl_xact_stats_items::items, MinSizeOfXactCommit, MinSizeOfXactInvals, MinSizeOfXactRelfilenodes, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, xl_xact_invals::msgs, xl_xact_parsed_commit::msgs, xl_xact_stats_items::nitems, xl_xact_invals::nmsgs, xl_xact_parsed_commit::nmsgs, xl_xact_relfilenodes::nrels, xl_xact_parsed_commit::nrels, xl_xact_parsed_commit::nstats, xl_xact_subxacts::nsubxacts, xl_xact_parsed_commit::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_parsed_commit::origin_lsn, xl_xact_origin::origin_timestamp, xl_xact_parsed_commit::origin_timestamp, xl_xact_parsed_commit::stats, strlcpy(), xl_xact_subxacts::subxacts, xl_xact_parsed_commit::subxacts, xl_xact_dbinfo::tsId, xl_xact_parsed_commit::tsId, xl_xact_parsed_commit::twophase_gid, xl_xact_parsed_commit::twophase_xid, xl_xact_commit::xact_time, xl_xact_parsed_commit::xact_time, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, xl_xact_parsed_commit::xinfo, XLOG_XACT_HAS_INFO, xl_xact_relfilenodes::xnodes, and xl_xact_parsed_commit::xnodes.

Referenced by recoveryStopsAfter(), recoveryStopsBefore(), xact_decode(), xact_desc_commit(), and xact_redo().

◆ ParsePrepareRecord()

void ParsePrepareRecord ( uint8  info,
xl_xact_prepare xlrec,
xl_xact_parsed_prepare parsed 
)

Definition at line 239 of file xactdesc.c.

240 {
241  char *bufptr;
242 
243  bufptr = ((char *) xlrec) + MAXALIGN(sizeof(xl_xact_prepare));
244 
245  memset(parsed, 0, sizeof(*parsed));
246 
247  parsed->xact_time = xlrec->prepared_at;
248  parsed->origin_lsn = xlrec->origin_lsn;
249  parsed->origin_timestamp = xlrec->origin_timestamp;
250  parsed->twophase_xid = xlrec->xid;
251  parsed->dbId = xlrec->database;
252  parsed->nsubxacts = xlrec->nsubxacts;
253  parsed->nrels = xlrec->ncommitrels;
254  parsed->nabortrels = xlrec->nabortrels;
255  parsed->nmsgs = xlrec->ninvalmsgs;
256 
257  strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen);
258  bufptr += MAXALIGN(xlrec->gidlen);
259 
260  parsed->subxacts = (TransactionId *) bufptr;
261  bufptr += MAXALIGN(xlrec->nsubxacts * sizeof(TransactionId));
262 
263  parsed->xnodes = (RelFileNode *) bufptr;
264  bufptr += MAXALIGN(xlrec->ncommitrels * sizeof(RelFileNode));
265 
266  parsed->abortnodes = (RelFileNode *) bufptr;
267  bufptr += MAXALIGN(xlrec->nabortrels * sizeof(RelFileNode));
268 
269  parsed->stats = (xl_xact_stats_item *) bufptr;
270  bufptr += MAXALIGN(xlrec->ncommitstats * sizeof(xl_xact_stats_item));
271 
272  parsed->abortstats = (xl_xact_stats_item *) bufptr;
273  bufptr += MAXALIGN(xlrec->nabortstats * sizeof(xl_xact_stats_item));
274 
275  parsed->msgs = (SharedInvalidationMessage *) bufptr;
276  bufptr += MAXALIGN(xlrec->ninvalmsgs * sizeof(SharedInvalidationMessage));
277 }
#define MAXALIGN(LEN)
Definition: c.h:757
RelFileNode * abortnodes
Definition: xact.h:381
xl_xact_stats_item * abortstats
Definition: xact.h:383
TimestampTz prepared_at
Definition: xact.h:339
int32 nabortrels
Definition: xact.h:343
int32 ninvalmsgs
Definition: xact.h:346
int32 ncommitstats
Definition: xact.h:344
TimestampTz origin_timestamp
Definition: xact.h:350
uint16 gidlen
Definition: xact.h:348
int32 nabortstats
Definition: xact.h:345
Oid database
Definition: xact.h:338
XLogRecPtr origin_lsn
Definition: xact.h:349
int32 ncommitrels
Definition: xact.h:342
TransactionId xid
Definition: xact.h:337
int32 nsubxacts
Definition: xact.h:341

References xl_xact_parsed_commit::abortnodes, xl_xact_parsed_commit::abortstats, xl_xact_prepare::database, xl_xact_parsed_commit::dbId, xl_xact_prepare::gidlen, MAXALIGN, xl_xact_parsed_commit::msgs, xl_xact_prepare::nabortrels, xl_xact_parsed_commit::nabortrels, xl_xact_prepare::nabortstats, xl_xact_prepare::ncommitrels, xl_xact_prepare::ncommitstats, xl_xact_prepare::ninvalmsgs, xl_xact_parsed_commit::nmsgs, xl_xact_parsed_commit::nrels, xl_xact_prepare::nsubxacts, xl_xact_parsed_commit::nsubxacts, xl_xact_prepare::origin_lsn, xl_xact_parsed_commit::origin_lsn, xl_xact_prepare::origin_timestamp, xl_xact_parsed_commit::origin_timestamp, xl_xact_prepare::prepared_at, xl_xact_parsed_commit::stats, xl_xact_parsed_commit::subxacts, xl_xact_parsed_commit::twophase_gid, xl_xact_parsed_commit::twophase_xid, xl_xact_parsed_commit::xact_time, xl_xact_prepare::xid, and xl_xact_parsed_commit::xnodes.

Referenced by xact_decode(), and xact_desc_prepare().

◆ PrepareTransactionBlock()

bool PrepareTransactionBlock ( const char *  gid)

Definition at line 3788 of file xact.c.

3789 {
3790  TransactionState s;
3791  bool result;
3792 
3793  /* Set up to commit the current transaction */
3794  result = EndTransactionBlock(false);
3795 
3796  /* If successful, change outer tblock state to PREPARE */
3797  if (result)
3798  {
3800 
3801  while (s->parent != NULL)
3802  s = s->parent;
3803 
3804  if (s->blockState == TBLOCK_END)
3805  {
3806  /* Save GID where PrepareTransaction can find it again */
3808 
3810  }
3811  else
3812  {
3813  /*
3814  * ignore case where we are not in a transaction;
3815  * EndTransactionBlock already issued a warning.
3816  */
3819  /* Don't send back a PREPARE result tag... */
3820  result = false;
3821  }
3822  }
3823 
3824  return result;
3825 }
static char * prepareGID
Definition: xact.c:278
bool EndTransactionBlock(bool chain)
Definition: xact.c:3840

References Assert(), TransactionStateData::blockState, CurrentTransactionState, EndTransactionBlock(), MemoryContextStrdup(), TransactionStateData::parent, prepareGID, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, and TopTransactionContext.

Referenced by apply_handle_prepare_internal(), and standard_ProcessUtility().

◆ PreventInTransactionBlock()

void PreventInTransactionBlock ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3462 of file xact.c.

3463 {
3464  /*
3465  * xact block already started?
3466  */
3467  if (IsTransactionBlock())
3468  ereport(ERROR,
3469  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3470  /* translator: %s represents an SQL statement name */
3471  errmsg("%s cannot run inside a transaction block",
3472  stmtType)));
3473 
3474  /*
3475  * subtransaction?
3476  */
3477  if (IsSubTransaction())
3478  ereport(ERROR,
3479  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3480  /* translator: %s represents an SQL statement name */
3481  errmsg("%s cannot run inside a subtransaction",
3482  stmtType)));
3483 
3484  /*
3485  * inside a function call?
3486  */
3487  if (!isTopLevel)
3488  ereport(ERROR,
3489  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3490  /* translator: %s represents an SQL statement name */
3491  errmsg("%s cannot be executed from a function", stmtType)));
3492 
3493  /* If we got past IsTransactionBlock test, should be in default state */
3496  elog(FATAL, "cannot prevent transaction chain");
3497  /* all okay */
3498 }

References TransactionStateData::blockState, CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsSubTransaction(), IsTransactionBlock(), TBLOCK_DEFAULT, and TBLOCK_STARTED.

Referenced by AlterDatabase(), AlterSubscription(), cluster(), CreateSubscription(), DiscardAll(), DropSubscription(), exec_replication_command(), ExecDropStmt(), ExecReindex(), ProcessUtilitySlow(), ReindexPartitions(), standard_ProcessUtility(), and vacuum().

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3665 of file xact.c.

3666 {
3667  SubXactCallbackItem *item;
3668 
3669  item = (SubXactCallbackItem *)
3671  item->callback = callback;
3672  item->arg = arg;
3673  item->next = SubXact_callbacks;
3674  SubXact_callbacks = item;
3675 }
MemoryContext TopMemoryContext
Definition: mcxt.c:48
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:312
SubXactCallback callback
Definition: xact.c:313
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:317

References SubXactCallbackItem::arg, arg, SubXactCallbackItem::callback, callback(), MemoryContextAlloc(), SubXactCallbackItem::next, SubXact_callbacks, and TopMemoryContext.

Referenced by _PG_init(), GetConnection(), and sepgsql_init_client_label().

◆ RegisterXactCallback()

void RegisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3610 of file xact.c.

3611 {
3612  XactCallbackItem *item;
3613 
3614  item = (XactCallbackItem *)
3616  item->callback = callback;
3617  item->arg = arg;
3618  item->next = Xact_callbacks;
3619  Xact_callbacks = item;
3620 }
struct XactCallbackItem * next
Definition: xact.c:300
void * arg
Definition: xact.c:302
XactCallback callback
Definition: xact.c:301
static XactCallbackItem * Xact_callbacks
Definition: xact.c:305

References XactCallbackItem::arg, arg, XactCallbackItem::callback, callback(), MemoryContextAlloc(), XactCallbackItem::next, TopMemoryContext, and Xact_callbacks.

Referenced by _PG_init(), GetConnection(), and sepgsql_init_client_label().

◆ ReleaseCurrentSubTransaction()

void ReleaseCurrentSubTransaction ( void  )

Definition at line 4561 of file xact.c.

4562 {
4564 
4565  /*
4566  * Workers synchronize transaction state at the beginning of each parallel
4567  * operation, so we can't account for commit of subtransactions after that
4568  * point. This should not happen anyway. Code calling this would
4569  * typically have called BeginInternalSubTransaction() first, failing
4570  * there.
4571  */
4572  if (IsInParallelMode())
4573  ereport(ERROR,
4574  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4575  errmsg("cannot commit subtransactions during a parallel operation")));
4576 
4577  if (s->blockState != TBLOCK_SUBINPROGRESS)
4578  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4580  Assert(s->state == TRANS_INPROGRESS);
4583  s = CurrentTransactionState; /* changed by pop */
4584  Assert(s->state == TRANS_INPROGRESS);
4585 }
MemoryContext CurTransactionContext
Definition: mcxt.c:54
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CommitSubTransaction(), CurrentTransactionState, CurTransactionContext, elog, ereport, errcode(), errmsg(), ERROR, IsInParallelMode(), MemoryContextSwitchTo(), TransactionStateData::state, TBLOCK_SUBINPROGRESS, and TRANS_INPROGRESS.

Referenced by exec_stmt_block(), ExecEvalJsonExprSubtrans(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), pltcl_subtrans_commit(), pltcl_subtransaction(), PLy_spi_subtransaction_commit(), and PLy_subtransaction_exit().

◆ ReleaseSavepoint()

void ReleaseSavepoint ( const char *  name)

Definition at line 4254 of file xact.c.

4255 {
4257  TransactionState target,
4258  xact;
4259 
4260  /*
4261  * Workers synchronize transaction state at the beginning of each parallel
4262  * operation, so we can't account for transaction state change after that
4263  * point. (Note that this check will certainly error out if s->blockState
4264  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4265  * below.)
4266  */
4267  if (IsInParallelMode())
4268  ereport(ERROR,
4269  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4270  errmsg("cannot release savepoints during a parallel operation")));
4271 
4272  switch (s->blockState)
4273  {
4274  /*
4275  * We can't release a savepoint if there is no savepoint defined.
4276  */
4277  case TBLOCK_INPROGRESS:
4278  ereport(ERROR,
4279  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4280  errmsg("savepoint \"%s\" does not exist", name)));
4281  break;
4282 
4284  /* See comment about implicit transactions in DefineSavepoint */
4285  ereport(ERROR,
4286  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4287  /* translator: %s represents an SQL statement name */
4288  errmsg("%s can only be used in transaction blocks",
4289  "RELEASE SAVEPOINT")));
4290  break;
4291 
4292  /*
4293  * We are in a non-aborted subtransaction. This is the only valid
4294  * case.
4295  */
4296  case TBLOCK_SUBINPROGRESS:
4297  break;
4298 
4299  /* These cases are invalid. */
4300  case TBLOCK_DEFAULT:
4301  case TBLOCK_STARTED:
4302  case TBLOCK_BEGIN:
4304  case TBLOCK_SUBBEGIN:
4305  case TBLOCK_END:
4306  case TBLOCK_SUBRELEASE:
4307  case TBLOCK_SUBCOMMIT:
4308  case TBLOCK_ABORT:
4309  case TBLOCK_SUBABORT:
4310  case TBLOCK_ABORT_END:
4311  case TBLOCK_SUBABORT_END:
4312  case TBLOCK_ABORT_PENDING:
4314  case TBLOCK_SUBRESTART:
4316  case TBLOCK_PREPARE:
4317  elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4319  break;
4320  }
4321 
4322  for (target = s; PointerIsValid(target); target = target->parent)
4323  {
4324  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4325  break;
4326  }
4327 
4328  if (!PointerIsValid(target))
4329  ereport(ERROR,
4330  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4331  errmsg("savepoint \"%s\" does not exist", name)));
4332 
4333  /* disallow crossing savepoint level boundaries */
4334  if (target->savepointLevel != s->savepointLevel)
4335  ereport(ERROR,
4336  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4337  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4338 
4339  /*
4340  * Mark "commit pending" all subtransactions up to the target
4341  * subtransaction. The actual commits will happen when control gets to
4342  * CommitTransactionCommand.
4343  */
4344  xact = CurrentTransactionState;
4345  for (;;)
4346  {
4348  xact->blockState = TBLOCK_SUBRELEASE;
4349  if (xact == target)
4350  break;
4351  xact = xact->parent;
4352  Assert(PointerIsValid(xact));
4353  }
4354 }
#define PointerIsValid(pointer)
Definition: c.h:698

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), TransactionStateData::name, name, TransactionStateData::parent, PointerIsValid, TransactionStateData::savepointLevel, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by standard_ProcessUtility().

◆ RequireTransactionBlock()

void RequireTransactionBlock ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3528 of file xact.c.

3529 {
3530  CheckTransactionBlock(isTopLevel, true, stmtType);
3531 }
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3537

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4595 of file xact.c.

4596 {
4598 
4599  /*
4600  * Unlike ReleaseCurrentSubTransaction(), this is nominally permitted
4601  * during parallel operations. That's because we may be in the leader,
4602  * recovering from an error thrown while we were in parallel mode. We
4603  * won't reach here in a worker, because BeginInternalSubTransaction()
4604  * will have failed.
4605  */
4606 
4607  switch (s->blockState)
4608  {
4609  /* Must be in a subtransaction */
4610  case TBLOCK_SUBINPROGRESS:
4611  case TBLOCK_SUBABORT:
4612  break;
4613 
4614  /* These cases are invalid. */
4615  case TBLOCK_DEFAULT:
4616  case TBLOCK_STARTED:
4617  case TBLOCK_BEGIN:
4620  case TBLOCK_SUBBEGIN:
4621  case TBLOCK_INPROGRESS:
4622  case TBLOCK_END:
4623  case TBLOCK_SUBRELEASE:
4624  case TBLOCK_SUBCOMMIT:
4625  case TBLOCK_ABORT:
4626  case TBLOCK_ABORT_END:
4627  case TBLOCK_SUBABORT_END:
4628  case TBLOCK_ABORT_PENDING:
4630  case TBLOCK_SUBRESTART:
4632  case TBLOCK_PREPARE:
4633  elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4635  break;
4636  }
4637 
4638  /*
4639  * Abort the current subtransaction, if needed.
4640  */
4641  if (s->blockState == TBLOCK_SUBINPROGRESS)
4643 
4644  /* And clean it up, too */
4646 
4647  s = CurrentTransactionState; /* changed by pop */
4649  s->blockState == TBLOCK_INPROGRESS ||
4651  s->blockState == TBLOCK_STARTED);
4652 }

References AbortSubTransaction(), AssertState, TransactionStateData::blockState, BlockStateAsString(), CleanupSubTransaction(), CurrentTransactionState, elog, FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by exec_stmt_block(), ExecEvalJsonExprSubtrans(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), pltcl_subtrans_abort(), pltcl_subtransaction(), PLy_abort_open_subtransactions(), PLy_spi_subtransaction_abort(), PLy_subtransaction_exit(), ReorderBufferImmediateInvalidation(), and ReorderBufferProcessTXN().

◆ RollbackToSavepoint()

void RollbackToSavepoint ( const char *  name)

Definition at line 4363 of file xact.c.

4364 {
4366  TransactionState target,
4367  xact;
4368 
4369  /*
4370  * Workers synchronize transaction state at the beginning of each parallel
4371  * operation, so we can't account for transaction state change after that
4372  * point. (Note that this check will certainly error out if s->blockState
4373  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4374  * below.)
4375  */
4376  if (IsInParallelMode())
4377  ereport(ERROR,
4378  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4379  errmsg("cannot rollback to savepoints during a parallel operation")));
4380 
4381  switch (s->blockState)
4382  {
4383  /*
4384  * We can't rollback to a savepoint if there is no savepoint
4385  * defined.
4386  */
4387  case TBLOCK_INPROGRESS:
4388  case TBLOCK_ABORT:
4389  ereport(ERROR,
4390  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4391  errmsg("savepoint \"%s\" does not exist", name)));
4392  break;
4393 
4395  /* See comment about implicit transactions in DefineSavepoint */
4396  ereport(ERROR,
4397  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4398  /* translator: %s represents an SQL statement name */
4399  errmsg("%s can only be used in transaction blocks",
4400  "ROLLBACK TO SAVEPOINT")));
4401  break;
4402 
4403  /*
4404  * There is at least one savepoint, so proceed.
4405  */
4406  case TBLOCK_SUBINPROGRESS:
4407  case TBLOCK_SUBABORT:
4408  break;
4409 
4410  /* These cases are invalid. */
4411  case TBLOCK_DEFAULT:
4412  case TBLOCK_STARTED:
4413  case TBLOCK_BEGIN:
4415  case TBLOCK_SUBBEGIN:
4416  case TBLOCK_END:
4417  case TBLOCK_SUBRELEASE:
4418  case TBLOCK_SUBCOMMIT:
4419  case TBLOCK_ABORT_END:
4420  case TBLOCK_SUBABORT_END:
4421  case TBLOCK_ABORT_PENDING:
4423  case TBLOCK_SUBRESTART:
4425  case TBLOCK_PREPARE:
4426  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4428  break;
4429  }
4430 
4431  for (target = s; PointerIsValid(target); target = target->parent)
4432  {
4433  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4434  break;
4435  }
4436 
4437  if (!PointerIsValid(target))
4438  ereport(ERROR,
4439  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4440  errmsg("savepoint \"%s\" does not exist", name)));
4441 
4442  /* disallow crossing savepoint level boundaries */
4443  if (target->savepointLevel != s->savepointLevel)
4444  ereport(ERROR,
4445  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4446  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4447 
4448  /*
4449  * Mark "abort pending" all subtransactions up to the target
4450  * subtransaction. The actual aborts will happen when control gets to
4451  * CommitTransactionCommand.
4452  */
4453  xact = CurrentTransactionState;
4454  for (;;)
4455  {
4456  if (xact == target)
4457  break;
4458  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4460  else if (xact->blockState == TBLOCK_SUBABORT)
4462  else
4463  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4465  xact = xact->parent;
4466  Assert(PointerIsValid(xact));
4467  }
4468 
4469  /* And mark the target as "restart pending" */
4470  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4471  xact->blockState = TBLOCK_SUBRESTART;
4472  else if (xact->blockState == TBLOCK_SUBABORT)
4474  else
4475  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4477 }

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), TransactionStateData::name, name, TransactionStateData::parent, PointerIsValid, TransactionStateData::savepointLevel, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by standard_ProcessUtility().

◆ SaveTransactionCharacteristics()

◆ SerializeTransactionState()

void SerializeTransactionState ( Size  maxsize,
char *  start_address 
)

Definition at line 5322 of file xact.c.

5323 {
5324  TransactionState s;
5325  Size nxids = 0;
5326  Size i = 0;
5327  TransactionId *workspace;
5329 
5330  result = (SerializedTransactionState *) start_address;
5331 
5332  result->xactIsoLevel = XactIsoLevel;
5333  result->xactDeferrable = XactDeferrable;
5335  result->currentFullTransactionId =
5338 
5339  /*
5340  * If we're running in a parallel worker and launching a parallel worker
5341  * of our own, we can just pass along the information that was passed to
5342  * us.
5343  */
5344  if (nParallelCurrentXids > 0)
5345  {
5347  memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5349  return;
5350  }
5351 
5352  /*
5353  * OK, we need to generate a sorted list of XIDs that our workers should
5354  * view as current. First, figure out how many there are.
5355  */
5356  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5357  {
5359  nxids = add_size(nxids, 1);
5360  nxids = add_size(nxids, s->nChildXids);
5361  }
5363  <= maxsize);
5364 
5365  /* Copy them to our scratch space. */
5366  workspace = palloc(nxids * sizeof(TransactionId));
5367  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5368  {
5370  workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5371  if (s->nChildXids > 0)
5372  memcpy(&workspace[i], s->childXids,
5373  s->nChildXids * sizeof(TransactionId));
5374  i += s->nChildXids;
5375  }
5376  Assert(i == nxids);
5377 
5378  /* Sort them. */
5379  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5380 
5381  /* Copy data into output area. */
5382  result->nParallelCurrentXids = nxids;
5383  memcpy(&result->parallelCurrentXids[0], workspace,
5384  nxids * sizeof(TransactionId));
5385 }
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1068
#define qsort(a, b, c, d)
Definition: port.h:495
FullTransactionId currentFullTransactionId
Definition: xact.c:225
FullTransactionId topFullTransactionId
Definition: xact.c:224
CommandId currentCommandId
Definition: xact.c:226
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:228
TransactionId * childXids
Definition: xact.c:200
static int nParallelCurrentXids
Definition: xact.c:125
static TransactionId * ParallelCurrentXids
Definition: xact.c:126
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:136

References add_size(), Assert(), TransactionStateData::childXids, SerializedTransactionState::currentCommandId, currentCommandId, SerializedTransactionState::currentFullTransactionId, CurrentTransactionState, TransactionStateData::fullTransactionId, FullTransactionIdIsValid, i, TransactionStateData::nChildXids, nParallelCurrentXids, SerializedTransactionState::nParallelCurrentXids, palloc(), ParallelCurrentXids, SerializedTransactionState::parallelCurrentXids, TransactionStateData::parent, qsort, SerializedTransactionStateHeaderSize, SerializedTransactionState::topFullTransactionId, XactDeferrable, SerializedTransactionState::xactDeferrable, XactIsoLevel, SerializedTransactionState::xactIsoLevel, XactTopFullTransactionId, xidComparator(), and XidFromFullTransactionId.

Referenced by InitializeParallelDSM().

◆ SetCurrentStatementStartTimestamp()

void SetCurrentStatementStartTimestamp ( void  )

◆ SetParallelStartTimestamps()

void SetParallelStartTimestamps ( TimestampTz  xact_ts,
TimestampTz  stmt_ts 
)

Definition at line 840 of file xact.c.

841 {
843  xactStartTimestamp = xact_ts;
844  stmtStartTimestamp = stmt_ts;
845 }

References Assert(), IsParallelWorker, stmtStartTimestamp, and xactStartTimestamp.

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 2925 of file xact.c.

2926 {
2928 
2929  switch (s->blockState)
2930  {
2931  /*
2932  * if we aren't in a transaction block, we just do our usual start
2933  * transaction.
2934  */
2935  case TBLOCK_DEFAULT:
2936  StartTransaction();
2938  break;
2939 
2940  /*
2941  * We are somewhere in a transaction block or subtransaction and
2942  * about to start a new command. For now we do nothing, but
2943  * someday we may do command-local resource initialization. (Note
2944  * that any needed CommandCounterIncrement was done by the
2945  * previous CommitTransactionCommand.)
2946  */
2947  case TBLOCK_INPROGRESS:
2949  case TBLOCK_SUBINPROGRESS:
2950  break;
2951 
2952  /*
2953  * Here we are in a failed transaction block (one of the commands
2954  * caused an abort) so we do nothing but remain in the abort
2955  * state. Eventually we will get a ROLLBACK command which will
2956  * get us out of this state. (It is up to other code to ensure
2957  * that no commands other than ROLLBACK will be processed in these
2958  * states.)
2959  */
2960  case TBLOCK_ABORT:
2961  case TBLOCK_SUBABORT:
2962  break;
2963 
2964  /* These cases are invalid. */
2965  case TBLOCK_STARTED:
2966  case TBLOCK_BEGIN:
2968  case TBLOCK_SUBBEGIN:
2969  case TBLOCK_END:
2970  case TBLOCK_SUBRELEASE:
2971  case TBLOCK_SUBCOMMIT:
2972  case TBLOCK_ABORT_END:
2973  case TBLOCK_SUBABORT_END:
2974  case TBLOCK_ABORT_PENDING:
2976  case TBLOCK_SUBRESTART:
2978  case TBLOCK_PREPARE:
2979  elog(ERROR, "StartTransactionCommand: unexpected state %s",
2981  break;
2982  }
2983 
2984  /*
2985  * We must switch to CurTransactionContext before returning. This is
2986  * already done if we called StartTransaction, otherwise not.
2987  */
2988  Assert(CurTransactionContext != NULL);
2990 }

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, CurTransactionContext, elog, ERROR, MemoryContextSwitchTo(), StartTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by _SPI_commit(), _SPI_rollback(), apply_handle_commit_internal(), ApplyWorkerMain(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), begin_replication_step(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), exec_replication_command(), FetchTableStates(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), ParallelWorkerMain(), perform_work_item(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReorderBufferProcessTXN(), shell_check_detail(), SnapBuildExportSnapshot(), start_xact_command(), vacuum(), and vacuum_rel().

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 790 of file xact.c.

791 {
793 
794  for (s = CurrentTransactionState; s != NULL; s = s->parent)
795  {
796  if (s->state == TRANS_ABORT)
797  continue;
798  if (s->subTransactionId == subxid)
799  return true;
800  }
801  return false;
802 }
@ TRANS_ABORT
Definition: xact.c:146

References CurrentTransactionState, TransactionStateData::parent, TransactionStateData::state, TransactionStateData::subTransactionId, and TRANS_ABORT.

Referenced by fmgr_sql().

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 4798 of file xact.c.

4799 {
4801 
4802  switch (s->blockState)
4803  {
4804  case TBLOCK_DEFAULT:
4805  case TBLOCK_STARTED:
4806  return 'I'; /* idle --- not in transaction */
4807  case TBLOCK_BEGIN:
4808  case TBLOCK_SUBBEGIN:
4809  case TBLOCK_INPROGRESS:
4812  case TBLOCK_SUBINPROGRESS:
4813  case TBLOCK_END:
4814  case TBLOCK_SUBRELEASE:
4815  case TBLOCK_SUBCOMMIT:
4816  case TBLOCK_PREPARE:
4817  return 'T'; /* in transaction */
4818  case TBLOCK_ABORT:
4819  case TBLOCK_SUBABORT:
4820  case TBLOCK_ABORT_END:
4821  case TBLOCK_SUBABORT_END:
4822  case TBLOCK_ABORT_PENDING:
4824  case TBLOCK_SUBRESTART:
4826  return 'E'; /* in failed transaction */
4827  }
4828 
4829  /* should never get here */
4830  elog(FATAL, "invalid transaction block state: %s",
4832  return 0; /* keep compiler quiet */
4833 }

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by ReadyForQuery().

◆ TransactionIdIsCurrentTransactionId()

bool TransactionIdIsCurrentTransactionId ( TransactionId  xid)

Definition at line 922 of file xact.c.

923 {
925 
926  /*
927  * We always say that BootstrapTransactionId is "not my transaction ID"
928  * even when it is (ie, during bootstrap). Along with the fact that
929  * transam.c always treats BootstrapTransactionId as already committed,
930  * this causes the heapam_visibility.c routines to see all tuples as
931  * committed, which is what we need during bootstrap. (Bootstrap mode
932  * only inserts tuples, it never updates or deletes them, so all tuples
933  * can be presumed good immediately.)
934  *
935  * Likewise, InvalidTransactionId and FrozenTransactionId are certainly
936  * not my transaction ID, so we can just return "false" immediately for
937  * any non-normal XID.
938  */
939  if (!TransactionIdIsNormal(xid))
940  return false;
941 
943  return true;
944 
945  /*
946  * In parallel workers, the XIDs we must consider as current are stored in
947  * ParallelCurrentXids rather than the transaction-state stack. Note that
948  * the XIDs in this array are sorted numerically rather than according to
949  * transactionIdPrecedes order.
950  */
951  if (nParallelCurrentXids > 0)
952  {
953  int low,
954  high;
955 
956  low = 0;
957  high = nParallelCurrentXids - 1;
958  while (low <= high)
959  {
960  int middle;
961  TransactionId probe;
962 
963  middle = low + (high - low) / 2;
964  probe = ParallelCurrentXids[middle];
965  if (probe == xid)
966  return true;
967  else if (probe < xid)
968  low = middle + 1;
969  else
970  high = middle - 1;
971  }
972  return false;
973  }
974 
975  /*
976  * We will return true for the Xid of the current subtransaction, any of
977  * its subcommitted children, any of its parents, or any of their
978  * previously subcommitted children. However, a transaction being aborted
979  * is no longer "current", even though it may still have an entry on the
980  * state stack.
981  */
982  for (s = CurrentTransactionState; s != NULL; s = s->parent)
983  {
984  int low,
985  high;
986 
987  if (s->state == TRANS_ABORT)
988  continue;
990  continue; /* it can't have any child XIDs either */
992  return true;
993  /* As the childXids array is ordered, we can use binary search */
994  low = 0;
995  high = s->nChildXids - 1;
996  while (low <= high)
997  {
998  int middle;
999  TransactionId probe;
1000 
1001  middle = low + (high - low) / 2;
1002  probe = s->childXids[middle];
1003  if (TransactionIdEquals(probe, xid))
1004  return true;
1005  else if (TransactionIdPrecedes(probe, xid))
1006  low = middle + 1;
1007  else
1008  high = middle - 1;
1009  }
1010  }
1011 
1012  return false;
1013 }
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define TransactionIdIsNormal(xid)
Definition: transam.h:42

References TransactionStateData::childXids, CurrentTransactionState, TransactionStateData::fullTransactionId, FullTransactionIdIsValid, GetTopTransactionIdIfAny(), TransactionStateData::nChildXids, nParallelCurrentXids, ParallelCurrentXids, TransactionStateData::parent, TransactionStateData::state, TRANS_ABORT, TransactionIdEquals, TransactionIdIsNormal, TransactionIdPrecedes(), and XidFromFullTransactionId.

Referenced by compute_new_xmax_infomask(), Do_MultiXactIdWait(), DoesMultiXactIdConflict(), ExecCheckTupleVisible(), ExecMergeMatched(), ExecOnConflictUpdate(), FreezeMultiXactId(), heap_delete(), heap_lock_tuple(), heap_update(), heapam_index_build_range_scan(), heapam_relation_copy_for_cluster(), heapam_scan_analyze_next_tuple(), heapam_tuple_lock(), HeapTupleHeaderAdjustCmax(), HeapTupleHeaderGetCmax(), HeapTupleHeaderGetCmin(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuumHorizon(), MultiXactIdIsRunning(), pg_xact_status(), PredicateLockTID(), RI_FKey_fk_upd_check_required(), SnapBuildWaitSnapshot(), test_lockmode_for_conflict(), and TransactionIdIsInProgress().

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3678 of file xact.c.

3679 {
3680  SubXactCallbackItem *item;
3681  SubXactCallbackItem *prev;
3682 
3683  prev = NULL;
3684  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3685  {
3686  if (item->callback == callback && item->arg == arg)
3687  {
3688  if (prev)
3689  prev->next = item->next;
3690  else
3691  SubXact_callbacks = item->next;
3692  pfree(item);
3693  break;
3694  }
3695  }
3696 }
void pfree(void *pointer)
Definition: mcxt.c:1175

References SubXactCallbackItem::arg, arg, SubXactCallbackItem::callback, callback(), SubXactCallbackItem::next, pfree(), and SubXact_callbacks.

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3623 of file xact.c.

3624 {
3625  XactCallbackItem *item;
3626  XactCallbackItem *prev;
3627 
3628  prev = NULL;
3629  for (item = Xact_callbacks; item; prev = item, item = item->next)
3630  {
3631  if (item->callback == callback && item->arg == arg)
3632  {
3633  if (prev)
3634  prev->next = item->next;
3635  else
3636  Xact_callbacks = item->next;
3637  pfree(item);
3638  break;
3639  }
3640  }
3641 }

References XactCallbackItem::arg, arg, XactCallbackItem::callback, callback(), XactCallbackItem::next, pfree(), and Xact_callbacks.

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4000 of file xact.c.

4001 {
4003 
4004  switch (s->blockState)
4005  {
4006  /*
4007  * We are inside a transaction block and we got a ROLLBACK command
4008  * from the user, so tell CommitTransactionCommand to abort and
4009  * exit the transaction block.
4010  */
4011  case TBLOCK_INPROGRESS:
4013  break;
4014 
4015  /*
4016  * We are inside a failed transaction block and we got a ROLLBACK
4017  * command from the user. Abort processing is already done, so
4018  * CommitTransactionCommand just has to cleanup and go back to
4019  * idle state.
4020  */
4021  case TBLOCK_ABORT:
4023  break;
4024 
4025  /*
4026  * We are inside a subtransaction. Mark everything up to top
4027  * level as exitable.
4028  */
4029  case TBLOCK_SUBINPROGRESS:
4030  case TBLOCK_SUBABORT:
4031  while (s->parent != NULL)
4032  {
4033  if (s->blockState == TBLOCK_SUBINPROGRESS)
4035  else if (s->blockState == TBLOCK_SUBABORT)
4037  else
4038  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4040  s = s->parent;
4041  }
4042  if (s->blockState == TBLOCK_INPROGRESS)
4044  else if (s->blockState == TBLOCK_ABORT)
4046  else
4047  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4049  break;
4050 
4051  /*
4052  * The user issued ABORT when not inside a transaction. For
4053  * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4054  * The upcoming call to CommitTransactionCommand() will then put
4055  * us back into the default state. For ROLLBACK AND CHAIN, error.
4056  *
4057  * We do the same thing with ABORT inside an implicit transaction,
4058  * although in this case we might be rolling back actual database
4059  * state changes. (It's debatable whether we should issue a
4060  * WARNING in this case, but we have done so historically.)
4061  */
4062  case TBLOCK_STARTED:
4064  if (chain)
4065  ereport(ERROR,
4066  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4067  /* translator: %s represents an SQL statement name */
4068  errmsg("%s can only be used in transaction blocks",
4069  "ROLLBACK AND CHAIN")));
4070  else
4071  ereport(WARNING,
4072  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4073  errmsg("there is no transaction in progress")));
4075  break;
4076 
4077  /*
4078  * The user issued an ABORT that somehow ran inside a parallel
4079  * worker. We can't cope with that.
4080  */
4082  ereport(FATAL,
4083  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4084  errmsg("cannot abort during a parallel operation")));
4085  break;
4086 
4087  /* These cases are invalid. */
4088  case TBLOCK_DEFAULT:
4089  case TBLOCK_BEGIN:
4090  case TBLOCK_SUBBEGIN:
4091  case TBLOCK_END:
4092  case TBLOCK_SUBRELEASE:
4093  case TBLOCK_SUBCOMMIT:
4094  case TBLOCK_ABORT_END:
4095  case TBLOCK_SUBABORT_END:
4096  case TBLOCK_ABORT_PENDING:
4098  case TBLOCK_SUBRESTART:
4100  case TBLOCK_PREPARE:
4101  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4103  break;
4104  }
4105 
4108 
4109  s->chain = chain;
4110 }

References Assert(), TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, TransactionStateData::parent, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and WARNING.

Referenced by standard_ProcessUtility().

◆ WarnNoTransactionBlock()

void WarnNoTransactionBlock ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3522 of file xact.c.

3523 {
3524  CheckTransactionBlock(isTopLevel, false, stmtType);
3525 }

References CheckTransactionBlock().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 436 of file xactdesc.c.

437 {
438  char *rec = XLogRecGetData(record);
439  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
440 
441  if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
442  {
443  xl_xact_commit *xlrec = (xl_xact_commit *) rec;
444 
445  xact_desc_commit(buf, XLogRecGetInfo(record), xlrec,
446  XLogRecGetOrigin(record));
447  }
448  else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
449  {
450  xl_xact_abort *xlrec = (xl_xact_abort *) rec;
451 
452  xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
453  XLogRecGetOrigin(record));
454  }
455  else if (info == XLOG_XACT_PREPARE)
456  {
457  xl_xact_prepare *xlrec = (xl_xact_prepare *) rec;
458 
459  xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec,
460  XLogRecGetOrigin(record));
461  }
462  else if (info == XLOG_XACT_ASSIGNMENT)
463  {
464  xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
465 
466  /*
467  * Note that we ignore the WAL record's xid, since we're more
468  * interested in the top-level xid that issued the record and which
469  * xids are being reported here.
470  */
471  appendStringInfo(buf, "xtop %u: ", xlrec->xtop);
472  xact_desc_assignment(buf, xlrec);
473  }
474  else if (info == XLOG_XACT_INVALIDATIONS)
475  {
476  xl_xact_invals *xlrec = (xl_xact_invals *) rec;
477 
479  InvalidOid, false);
480  }
481 }
unsigned char uint8
Definition: c.h:439
static char * buf
Definition: pg_test_fsync.c:67
#define InvalidOid
Definition: postgres_ext.h:36
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
Definition: standbydesc.c:98
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
TransactionId xtop
Definition: xact.h:207
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:159
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:162
#define XLOG_XACT_PREPARE
Definition: xact.h:157
#define XLOG_XACT_COMMIT
Definition: xact.h:156
#define XLOG_XACT_OPMASK
Definition: xact.h:166
#define XLOG_XACT_ABORT
Definition: xact.h:158
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:161
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:160
static void xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:331
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:367
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:425
static void xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:394
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:411
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:408
#define XLogRecGetData(decoder)
Definition: xlogreader.h:413

References appendStringInfo(), buf, InvalidOid, xl_xact_invals::msgs, xl_xact_invals::nmsgs, standby_desc_invalidations(), xact_desc_abort(), xact_desc_assignment(), xact_desc_commit(), xact_desc_prepare(), XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, XLOG_XACT_PREPARE, XLogRecGetData, XLogRecGetInfo, XLogRecGetOrigin, and xl_xact_assignment::xtop.

◆ xact_identify()

const char* xact_identify ( uint8  info)

Definition at line 484 of file xactdesc.c.

485 {
486  const char *id = NULL;
487 
488  switch (info & XLOG_XACT_OPMASK)
489  {
490  case XLOG_XACT_COMMIT:
491  id = "COMMIT";
492  break;
493  case XLOG_XACT_PREPARE:
494  id = "PREPARE";
495  break;
496  case XLOG_XACT_ABORT:
497  id = "ABORT";
498  break;
500  id = "COMMIT_PREPARED";
501  break;
503  id = "ABORT_PREPARED";
504  break;
506  id = "ASSIGNMENT";
507  break;
509  id = "INVALIDATION";
510  break;
511  }
512 
513  return id;
514 }

References XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, and XLOG_XACT_PREPARE.

◆ xact_redo()

void xact_redo ( XLogReaderState record)

Definition at line 6137 of file xact.c.

6138 {
6139  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6140 
6141  /* Backup blocks are not used in xact records */
6142  Assert(!XLogRecHasAnyBlockRefs(record));
6143 
6144  if (info == XLOG_XACT_COMMIT)
6145  {
6146  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6147  xl_xact_parsed_commit parsed;
6148 
6149  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6150  xact_redo_commit(&parsed, XLogRecGetXid(record),
6151  record->EndRecPtr, XLogRecGetOrigin(record));
6152  }
6153  else if (info == XLOG_XACT_COMMIT_PREPARED)
6154  {
6155  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6156  xl_xact_parsed_commit parsed;
6157 
6158  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6159  xact_redo_commit(&parsed, parsed.twophase_xid,
6160  record->EndRecPtr, XLogRecGetOrigin(record));
6161 
6162  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6163  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6164  PrepareRedoRemove(parsed.twophase_xid, false);
6165  LWLockRelease(TwoPhaseStateLock);
6166  }
6167  else if (info == XLOG_XACT_ABORT)
6168  {
6169  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6170  xl_xact_parsed_abort parsed;
6171 
6172  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6173  xact_redo_abort(&parsed, XLogRecGetXid(record),
6174  record->EndRecPtr, XLogRecGetOrigin(record));
6175  }
6176  else if (info == XLOG_XACT_ABORT_PREPARED)
6177  {
6178  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6179  xl_xact_parsed_abort parsed;
6180 
6181  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6182  xact_redo_abort(&parsed, parsed.twophase_xid,
6183  record->EndRecPtr, XLogRecGetOrigin(record));
6184 
6185  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6186  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6187  PrepareRedoRemove(parsed.twophase_xid, false);
6188  LWLockRelease(TwoPhaseStateLock);
6189  }
6190  else if (info == XLOG_XACT_PREPARE)
6191  {
6192  /*
6193  * Store xid and start/end pointers of the WAL record in TwoPhaseState
6194  * gxact entry.
6195  */
6196  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6198  record->ReadRecPtr,
6199  record->EndRecPtr,
6200  XLogRecGetOrigin(record));
6201  LWLockRelease(TwoPhaseStateLock);
6202  }
6203  else if (info == XLOG_XACT_ASSIGNMENT)
6204  {
6206 
6209  xlrec->nsubxacts, xlrec->xsub);
6210  }
6211  else if (info == XLOG_XACT_INVALIDATIONS)
6212  {
6213  /*
6214  * XXX we do ignore this for now, what matters are invalidations
6215  * written into the commit record.
6216  */
6217  }
6218  else
6219  elog(PANIC, "xact_redo: unknown op code %u", info);
6220 }
#define PANIC
Definition: elog.h:36
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_EXCLUSIVE
Definition: lwlock.h:104
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1285
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:206
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:209
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2527
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2457
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:5904
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6058
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:141
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:410
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:415
HotStandbyState standbyState
Definition: xlogutils.c:56
@ STANDBY_INITIALIZED
Definition: xlogutils.h:50

References Assert(), elog, XLogReaderState::EndRecPtr, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), xl_xact_assignment::nsubxacts, PANIC, ParseAbortRecord(), ParseCommitRecord(), PrepareRedoAdd(), PrepareRedoRemove(), ProcArrayApplyXidAssignment(), XLogReaderState::ReadRecPtr, STANDBY_INITIALIZED, standbyState, xl_xact_parsed_commit::twophase_xid, xl_xact_parsed_abort::twophase_xid, xact_redo_abort(), xact_redo_commit(), XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, XLOG_XACT_PREPARE, XLogRecGetData, XLogRecGetInfo, XLogRecGetOrigin, XLogRecGetXid, XLogRecHasAnyBlockRefs, xl_xact_assignment::xsub, and xl_xact_assignment::xtop.

◆ xactGetCommittedChildren()

int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5563 of file xact.c.

5564 {
5566 
5567  if (s->nChildXids == 0)
5568  *ptr = NULL;
5569  else
5570  *ptr = s->childXids;
5571 
5572  return s->nChildXids;
5573 }

References TransactionStateData::childXids, CurrentTransactionState, and TransactionStateData::nChildXids.

Referenced by ExportSnapshot(), RecordTransactionAbort(), RecordTransactionCommit(), and StartPrepare().

◆ XactLogAbortRecord()

XLogRecPtr XactLogAbortRecord ( TimestampTz  abort_time,
int  nsubxacts,
TransactionId subxacts,
int  nrels,
RelFileNode rels,
int  nstats,
xl_xact_stats_item stats,
int  xactflags,
TransactionId  twophase_xid,
const char *  twophase_gid 
)

Definition at line 5759 of file xact.c.

5765 {
5766  xl_xact_abort xlrec;
5767  xl_xact_xinfo xl_xinfo;
5768  xl_xact_subxacts xl_subxacts;
5769  xl_xact_relfilenodes xl_relfilenodes;
5770  xl_xact_stats_items xl_dropped_stats;
5771  xl_xact_twophase xl_twophase;
5772  xl_xact_dbinfo xl_dbinfo;
5773  xl_xact_origin xl_origin;
5774 
5775  uint8 info;
5776 
5777  Assert(CritSectionCount > 0);
5778 
5779  xl_xinfo.xinfo = 0;
5780 
5781  /* decide between a plain and 2pc abort */
5782  if (!TransactionIdIsValid(twophase_xid))
5783  info = XLOG_XACT_ABORT;
5784  else
5785  info = XLOG_XACT_ABORT_PREPARED;
5786 
5787 
5788  /* First figure out and collect all the information needed */
5789 
5790  xlrec.xact_time = abort_time;
5791 
5792  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5793  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5794 
5795  if (nsubxacts > 0)
5796  {
5797  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5798  xl_subxacts.nsubxacts = nsubxacts;
5799  }
5800 
5801  if (nrels > 0)
5802  {
5803  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5804  xl_relfilenodes.nrels = nrels;
5805  info |= XLR_SPECIAL_REL_UPDATE;
5806  }
5807 
5808  if (ndroppedstats > 0)
5809  {
5810  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5811  xl_dropped_stats.nitems = ndroppedstats;
5812  }
5813 
5814  if (TransactionIdIsValid(twophase_xid))
5815  {
5816  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5817  xl_twophase.xid = twophase_xid;
5818  Assert(twophase_gid != NULL);
5819 
5820  if (XLogLogicalInfoActive())
5821  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5822  }
5823 
5824  if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
5825  {
5826  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5827  xl_dbinfo.dbId = MyDatabaseId;
5828  xl_dbinfo.tsId = MyDatabaseTableSpace;
5829  }
5830 
5831  /*
5832  * Dump transaction origin information only for abort prepared. We need
5833  * this during recovery to update the replication origin progress.
5834  */
5836  TransactionIdIsValid(twophase_xid))
5837  {
5838  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5839 
5842  }
5843 
5844  if (xl_xinfo.xinfo != 0)
5845  info |= XLOG_XACT_HAS_INFO;
5846 
5847  /* Then include all the collected data into the abort record. */
5848 
5849  XLogBeginInsert();
5850 
5851  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
5852 
5853  if (xl_xinfo.xinfo != 0)
5854  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
5855 
5856  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5857  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5858 
5859  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5860  {
5861  XLogRegisterData((char *) (&xl_subxacts),
5863  XLogRegisterData((char *) subxacts,
5864  nsubxacts * sizeof(TransactionId));
5865  }
5866 
5867  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5868  {
5869  XLogRegisterData((char *) (&xl_relfilenodes),
5871  XLogRegisterData((char *) rels,
5872  nrels * sizeof(RelFileNode));
5873  }
5874 
5875  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5876  {
5877  XLogRegisterData((char *) (&xl_dropped_stats),
5879  XLogRegisterData((char *) droppedstats,
5880  ndroppedstats * sizeof(xl_xact_stats_item));
5881  }
5882 
5883  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5884  {
5885  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5886  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5887  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5888  }
5889 
5890  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5891  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5892 
5893  if (TransactionIdIsValid(twophase_xid))
5895 
5896  return XLogInsert(RM_XACT_ID, info);
5897 }
#define unconstify(underlying_type, expr)
Definition: c.h:1240
Oid MyDatabaseTableSpace
Definition: globals.c:91
volatile uint32 CritSectionCount
Definition: globals.c:42
Oid MyDatabaseId
Definition: globals.c:89
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:157
RepOriginId replorigin_session_origin
Definition: origin.c:155
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:156
#define InvalidRepOriginId
Definition: origin.h:33
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:108
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:181
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:149
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:443
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:425
void XLogBeginInsert(void)
Definition: xloginsert.c:150
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:351
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:71

References Assert(), CritSectionCount, xl_xact_dbinfo::dbId, InvalidRepOriginId, MinSizeOfXactAbort, MinSizeOfXactRelfilenodes, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_stats_items::nitems, xl_xact_relfilenodes::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, TransactionIdIsValid, xl_xact_dbinfo::tsId, unconstify, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_abort::xact_time, XACT_XINFO_HAS_AE_LOCKS, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_INCLUDE_ORIGIN, XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), XLogLogicalInfoActive, XLogRegisterData(), XLogSetRecordFlags(), and XLR_SPECIAL_REL_UPDATE.

Referenced by RecordTransactionAbort(), and RecordTransactionAbortPrepared().

◆ XactLogCommitRecord()

XLogRecPtr XactLogCommitRecord ( TimestampTz  commit_time,
int  nsubxacts,
TransactionId subxacts,
int  nrels,
RelFileNode rels,
int  nstats,
xl_xact_stats_item stats,
int  nmsgs,
SharedInvalidationMessage msgs,
bool  relcacheInval,
int  xactflags,
TransactionId  twophase_xid,
const char *  twophase_gid 
)

Definition at line 5587 of file xact.c.

5595 {
5596  xl_xact_commit xlrec;
5597  xl_xact_xinfo xl_xinfo;
5598  xl_xact_dbinfo xl_dbinfo;
5599  xl_xact_subxacts xl_subxacts;
5600  xl_xact_relfilenodes xl_relfilenodes;
5601  xl_xact_stats_items xl_dropped_stats;
5602  xl_xact_invals xl_invals;
5603  xl_xact_twophase xl_twophase;
5604  xl_xact_origin xl_origin;
5605  uint8 info;
5606 
5607  Assert(CritSectionCount > 0);
5608 
5609  xl_xinfo.xinfo = 0;
5610 
5611  /* decide between a plain and 2pc commit */
5612  if (!TransactionIdIsValid(twophase_xid))
5613  info = XLOG_XACT_COMMIT;
5614  else
5616 
5617  /* First figure out and collect all the information needed */
5618 
5619  xlrec.xact_time = commit_time;
5620 
5621  if (relcacheInval)
5623  if (forceSyncCommit)
5625  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5626  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5627 
5628  /*
5629  * Check if the caller would like to ask standbys for immediate feedback
5630  * once this commit is applied.
5631  */
5634 
5635  /*
5636  * Relcache invalidations requires information about the current database
5637  * and so does logical decoding.
5638  */
5639  if (nmsgs > 0 || XLogLogicalInfoActive())
5640  {
5641  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5642  xl_dbinfo.dbId = MyDatabaseId;
5643  xl_dbinfo.tsId = MyDatabaseTableSpace;
5644  }
5645 
5646  if (nsubxacts > 0)
5647  {
5648  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5649  xl_subxacts.nsubxacts = nsubxacts;
5650  }
5651 
5652  if (nrels > 0)
5653  {
5654  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5655  xl_relfilenodes.nrels = nrels;
5656  info |= XLR_SPECIAL_REL_UPDATE;
5657  }
5658 
5659  if (ndroppedstats > 0)
5660  {
5661  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5662  xl_dropped_stats.nitems = ndroppedstats;
5663  }
5664 
5665  if (nmsgs > 0)
5666  {
5667  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5668  xl_invals.nmsgs = nmsgs;
5669  }
5670 
5671  if (TransactionIdIsValid(twophase_xid))
5672  {
5673  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5674  xl_twophase.xid = twophase_xid;
5675  Assert(twophase_gid != NULL);
5676 
5677  if (XLogLogicalInfoActive())
5678  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5679  }
5680 
5681  /* dump transaction origin information */
5683  {
5684  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5685 
5688  }
5689 
5690  if (xl_xinfo.xinfo != 0)
5691  info |= XLOG_XACT_HAS_INFO;
5692 
5693  /* Then include all the collected data into the commit record. */
5694 
5695  XLogBeginInsert();
5696 
5697  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5698 
5699  if (xl_xinfo.xinfo != 0)
5700  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5701 
5702  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5703  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5704 
5705  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5706  {
5707  XLogRegisterData((char *) (&xl_subxacts),
5709  XLogRegisterData((char *) subxacts,
5710  nsubxacts * sizeof(TransactionId));
5711  }
5712 
5713  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5714  {
5715  XLogRegisterData((char *) (&xl_relfilenodes),
5717  XLogRegisterData((char *) rels,
5718  nrels * sizeof(RelFileNode));
5719  }
5720 
5721  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5722  {
5723  XLogRegisterData((char *) (&xl_dropped_stats),
5725  XLogRegisterData((char *) droppedstats,
5726  ndroppedstats * sizeof(xl_xact_stats_item));
5727  }
5728 
5729  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5730  {
5731  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5732  XLogRegisterData((char *) msgs,
5733  nmsgs * sizeof(SharedInvalidationMessage));
5734  }
5735 
5736  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5737  {
5738  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5739  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5740  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5741  }
5742 
5743  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5744  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5745 
5746  /* we allow filtering by xacts */
5748 
5749  return XLogInsert(RM_XACT_ID, info);
5750 }
int synchronous_commit
Definition: xact.c:86
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:194
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:195
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:193

References Assert(), CritSectionCount, xl_xact_dbinfo::dbId, forceSyncCommit, InvalidRepOriginId, MinSizeOfXactInvals, MinSizeOfXactRelfilenodes, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_stats_items::nitems, xl_xact_invals::nmsgs, xl_xact_relfilenodes::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, synchronous_commit, SYNCHRONOUS_COMMIT_REMOTE_APPLY, TransactionIdIsValid, xl_xact_dbinfo::tsId, unconstify, XACT_COMPLETION_APPLY_FEEDBACK, XACT_COMPLETION_FORCE_SYNC_COMMIT, XACT_COMPLETION_UPDATE_RELCACHE_FILE, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_commit::xact_time, XACT_XINFO_HAS_AE_LOCKS, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_INCLUDE_ORIGIN, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), XLogLogicalInfoActive, XLogRegisterData(), XLogSetRecordFlags(), and XLR_SPECIAL_REL_UPDATE.

Referenced by RecordTransactionCommit(), and RecordTransactionCommitPrepared().

Variable Documentation

◆ bsysscan

◆ CheckXidAlive

◆ DefaultXactDeferrable

PGDLLIMPORT bool DefaultXactDeferrable
extern

Definition at line 83 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 77 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 80 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 86 of file xact.c.

Referenced by AutoVacWorkerMain(), RecordTransactionCommit(), and XactLogCommitRecord().

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 286 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly