Skip to content

Commit b6dc773

Browse files
committed
Support global temp tables at replica
1 parent e525ef8 commit b6dc773

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/backend/access/transam/varsup.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ GetNewTransactionId(bool isSubXact)
6969
return FullTransactionIdFromEpochAndXid(0, BootstrapTransactionId);
7070
}
7171

72-
/* safety check, we should never get this far in a HS standby */
72+
/* Make it possible to access global temporary tables at standby */
7373
if (RecoveryInProgress())
74-
elog(ERROR, "cannot assign TransactionIds during recovery");
74+
return FullTransactionIdFromEpochAndXid(0, FrozenTransactionId);
75+
/* elog(ERROR, "cannot assign TransactionIds during recovery"); */
7576

7677
LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
7778

src/backend/access/transam/xact.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ static TransactionId
12061206
RecordTransactionCommit(void)
12071207
{
12081208
TransactionId xid = GetTopTransactionIdIfAny();
1209-
bool markXidCommitted = TransactionIdIsValid(xid);
1209+
bool markXidCommitted = TransactionIdIsNormal(xid);
12101210
TransactionId latestXid = InvalidTransactionId;
12111211
int nrels;
12121212
RelFileNode *rels;
@@ -1624,7 +1624,7 @@ RecordTransactionAbort(bool isSubXact)
16241624
* rels to delete (note that this routine is not responsible for actually
16251625
* deleting 'em). We cannot have any child XIDs, either.
16261626
*/
1627-
if (!TransactionIdIsValid(xid))
1627+
if (!TransactionIdIsNormal(xid))
16281628
{
16291629
/* Reset XactLastRecEnd until the next transaction writes something */
16301630
if (!isSubXact)
@@ -2991,6 +2991,9 @@ CommitTransactionCommand(void)
29912991
* and then clean up.
29922992
*/
29932993
case TBLOCK_ABORT_PENDING:
2994+
if (GetCurrentTransactionIdIfAny() == FrozenTransactionId)
2995+
elog(FATAL, "Transaction is aborted at standby");
2996+
29942997
AbortTransaction();
29952998
CleanupTransaction();
29962999
s->blockState = TBLOCK_DEFAULT;

src/backend/executor/execMain.c

+3
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ ExecCheckXactReadOnly(PlannedStmt *plannedstmt)
788788
if (isTempNamespace(get_rel_namespace(rte->relid)))
789789
continue;
790790

791+
if (get_rel_persistence(rte->relid) == RELPERSISTENCE_SESSION)
792+
continue;
793+
791794
PreventCommandIfReadOnly(CreateCommandTag((Node *) plannedstmt));
792795
}
793796

src/backend/optimizer/util/plancat.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
124124
relation = table_open(relationObjectId, NoLock);
125125

126126
/* Temporary and unlogged relations are inaccessible during recovery. */
127-
if (!RelationNeedsWAL(relation) && RecoveryInProgress())
127+
if (!RelationNeedsWAL(relation) && RecoveryInProgress() && relation->rd_rel->relpersistence != RELPERSISTENCE_SESSION)
128128
ereport(ERROR,
129129
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
130130
errmsg("cannot access temporary or unlogged relations during recovery")));

0 commit comments

Comments
 (0)