diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 05221cc1d6..5fbeacc0da 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -4147,6 +4147,12 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc) LVRelState vacrel; ErrorContextCallback errcallback; + /* + * A parallel vacuum worker must have only PROC_IN_VACUUM flag since we + * don't support parallel vacuum for autovacuum as of now. + */ + Assert(MyProc->statusFlags == PROC_IN_VACUUM); + lvshared = (LVShared *) shm_toc_lookup(toc, PARALLEL_VACUUM_KEY_SHARED, false); elevel = lvshared->elevel; diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index bb1881f573..6b876dc492 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -34,6 +34,7 @@ #include "pgstat.h" #include "storage/ipc.h" #include "storage/predicate.h" +#include "storage/procarray.h" #include "storage/sinval.h" #include "storage/spin.h" #include "tcop/tcopprot.h" @@ -1482,6 +1483,9 @@ ParallelWorkerMain(Datum main_arg) /* Attach to the leader's serializable transaction, if SERIALIZABLE. */ AttachSerializableXact(fps->serializable_xact_handle); + /* Copy status flags from the leader */ + ProcArrayCopyStatusFlags(fps->parallel_leader_pgproc); + /* * We've initialized all of our state now; nothing should change * hereafter. diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index bd3c7a47fe..58cf339e7d 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -2672,6 +2672,20 @@ ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc) return result; } +/* + * ProcArrayCopyStatusFlags -- copy statusFlags from 'proc' to MyProc->statusFlags + * + * This is used to set status flags in a parallel worker. + */ +void +ProcArrayCopyStatusFlags(PGPROC *proc) +{ + LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); + MyProc->statusFlags = proc->statusFlags; + ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags; + LWLockRelease(ProcArrayLock); +} + /* * GetRunningTransactionData -- returns information about running transactions. * diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index b01fa52139..25debf0c5c 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -49,6 +49,8 @@ extern bool ProcArrayInstallImportedXmin(TransactionId xmin, VirtualTransactionId *sourcevxid); extern bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc); +extern void ProcArrayCopyStatusFlags(PGPROC *proc); + extern RunningTransactions GetRunningTransactionData(void); extern bool TransactionIdIsInProgress(TransactionId xid);