diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index cdaa32e..abc41e7 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -87,6 +87,8 @@ typedef struct FixedParallelState PGPROC *parallel_master_pgproc; pid_t parallel_master_pid; BackendId parallel_master_backend_id; + TimestampTz xact_ts; + TimestampTz stmt_ts; /* Mutex protects remaining fields. */ slock_t mutex; @@ -318,6 +320,8 @@ InitializeParallelDSM(ParallelContext *pcxt) fps->parallel_master_pgproc = MyProc; fps->parallel_master_pid = MyProcPid; fps->parallel_master_backend_id = MyBackendId; + fps->xact_ts = GetCurrentTransactionStartTimestamp(); + fps->stmt_ts = GetCurrentStatementStartTimestamp(); SpinLockInit(&fps->mutex); fps->last_xlog_end = 0; shm_toc_insert(pcxt->toc, PARALLEL_KEY_FIXED, fps); @@ -1351,6 +1355,9 @@ ParallelWorkerMain(Datum main_arg) tstatespace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_STATE, false); StartParallelWorkerTransaction(tstatespace); + /* Restore current transaction and statement timestamps */ + SetCurrentStartTimestamps(fps->xact_ts, fps->stmt_ts); + /* Restore combo CID state. */ combocidspace = shm_toc_lookup(toc, PARALLEL_KEY_COMBO_CID, false); RestoreComboCIDState(combocidspace); diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 875be18..c8fc140 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -675,6 +675,16 @@ GetCurrentCommandId(bool used) } /* + * SetCurrentStartTimestamps + */ +void +SetCurrentStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts) +{ + xactStartTimestamp = xact_ts; + stmtStartTimestamp = stmt_ts; +} + +/* * GetCurrentTransactionStartTimestamp */ TimestampTz diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 083e879..05afa36 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -356,6 +356,7 @@ extern TransactionId GetCurrentTransactionId(void); extern TransactionId GetCurrentTransactionIdIfAny(void); extern TransactionId GetStableLatestTransactionId(void); extern SubTransactionId GetCurrentSubTransactionId(void); +extern void SetCurrentStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts); extern void MarkCurrentTransactionIdLoggedIfAny(void); extern bool SubTransactionIsActive(SubTransactionId subxid); extern CommandId GetCurrentCommandId(bool used); diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 8e4145f..dfa8395 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -2595,13 +2595,13 @@ proname => 'timetzdate_pl', prolang => '14', prorettype => 'timestamptz', proargtypes => 'timetz date', prosrc => 'select ($2 + $1)' }, { oid => '1299', descr => 'current transaction time', - proname => 'now', provolatile => 's', proparallel => 'r', + proname => 'now', provolatile => 's', proparallel => 's', prorettype => 'timestamptz', proargtypes => '', prosrc => 'now' }, { oid => '2647', descr => 'current transaction time', proname => 'transaction_timestamp', provolatile => 's', prorettype => 'timestamptz', proargtypes => '', prosrc => 'now' }, { oid => '2648', descr => 'current statement time', - proname => 'statement_timestamp', provolatile => 's', proparallel => 'r', + proname => 'statement_timestamp', provolatile => 's', proparallel => 's', prorettype => 'timestamptz', proargtypes => '', prosrc => 'statement_timestamp' }, { oid => '2649', descr => 'current clock time',