diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 61f2ce4..44ed5a4 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -16,13 +16,13 @@
 
 #include "access/heapam.h"
 #include "access/transam.h"
+#include "catalog/catalog.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/bufmgr.h"
 #include "utils/rel.h"
 #include "utils/tqual.h"
 
-
 /* Working data for heap_page_prune and subroutines */
 typedef struct
 {
@@ -91,6 +91,13 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin)
 		return;
 
 	/*
+	 * RecentGlobalXmin is valid only for non-shared relations, so we cannot
+	 * prune shared relations while reading them with MVCC snapshots.
+	 */
+	if (IsSharedRelation(relation->rd_id))
+		return;
+
+	/*
 	 * We prune when a previous UPDATE failed to find enough space on the page
 	 * for a new tuple version, or when free space falls below the relation's
 	 * fill-factor target (but not less than 10%).
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 1a48485..9b2eede 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -55,6 +55,7 @@
 #include "storage/spin.h"
 #include "utils/builtins.h"
 #include "utils/snapmgr.h"
+#include "utils/tqual.h"
 
 
 /* Our shared memory area */
@@ -1200,6 +1201,7 @@ GetSnapshotData(Snapshot snapshot)
 	int			count = 0;
 	int			subcount = 0;
 	bool		suboverflowed = false;
+	bool		allDbs = !IsMVCCSnapshot(snapshot);
 
 	Assert(snapshot != NULL);
 
@@ -1278,6 +1280,12 @@ GetSnapshotData(Snapshot snapshot)
 			if (proc->vacuumFlags & PROC_IN_VACUUM)
 				continue;
 
+			/* MVCC snapshots ignore other databases */
+			if (!allDbs &&
+				proc->databaseId != MyDatabaseId &&
+				proc->databaseId != 0)		/* always include WalSender */
+				continue;
+
 			/* Update globalxmin to be the smallest valid xmin */
 			xid = proc->xmin;	/* fetch just once */
 			if (TransactionIdIsNormal(xid) &&
