Hi hackers!
I’ve been working on this [
https://www.postgresql.org/message-id/flat/cfcca574-6967-c5ab-7dc3-2c82b6723b99%40mail.ru
] bug. Finally, I’ve come up with the patch you can find attached. Basically
what is does is rises a PROC_IN_VACUUM flag and resets it afterwards. I know
this seems kinda crunchy and I hope you guys will give me some hints on where
to continue. This [
https://www.postgresql.org/message-id/20220218175119.7hwv7ksamfjwijbx%40alap3.anarazel.de
] message contains reproduction script. Thank you very much in advance.
Kind regards,
Daniel Shelepanov
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 53aaf61cb94..700ebeaa018 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -18,6 +18,7 @@
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
+#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/smgr.h"
#include "utils/rel.h"
@@ -562,12 +563,19 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
Buffer vmbuffer = InvalidBuffer;
BufferAccessStrategy bstrategy = GetAccessStrategy(BAS_BULKREAD);
TransactionId OldestXmin = InvalidTransactionId;
+ uint8 oldStatusFlags;
rel = relation_open(relid, AccessShareLock);
/* Only some relkinds have a visibility map */
check_relation_relkind(rel);
+ LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
+ oldStatusFlags = MyProc->statusFlags;
+ MyProc->statusFlags |= PROC_IN_VACUUM;
+ ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;
+ LWLockRelease(ProcArrayLock);
+
if (all_visible)
OldestXmin = GetOldestNonRemovableTransactionId(rel);
@@ -722,6 +730,11 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
items->count = items->next;
items->next = 0;
+ LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
+ MyProc->statusFlags = oldStatusFlags;
+ ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;
+ LWLockRelease(ProcArrayLock);
+
return items;
}