dbent->deadlocks++;
 }
 
+/*
+ * Allow this backend to later report checksum failures for dboid, even if in
+ * a critical section at the time of the report.
+ *
+ * Without this function having been called first, the backend might need to
+ * allocate an EntryRef or might need to map in DSM segments. Neither should
+ * happen in a critical section.
+ */
+void
+pgstat_prepare_report_checksum_failure(Oid dboid)
+{
+   Assert(!CritSectionCount);
+
+   /*
+    * Just need to ensure this backend has an entry ref for the database.
+    * That will allows us to report checksum failures without e.g. needing to
+    * map in DSM segments.
+    */
+   pgstat_get_entry_ref(PGSTAT_KIND_DATABASE, dboid, InvalidOid,
+                        true, NULL);
+}
+
 /*
  * Report one or more checksum failures.
+ *
+ * To be allowed to report checksum failures in critical sections, we require
+ * pgstat_prepare_report_checksum_failure() to have been called before this
+ * function is called.
  */
 void
 pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
 
    /*
     * Update the shared stats directly - checksum failures should never be
-    * common enough for that to be a problem.
+    * common enough for that to be a problem. Note that we pass create=false
+    * here, as we want to be sure to not require memory allocations, so this
+    * can be called in critical sections.
+    */
+   entry_ref = pgstat_get_entry_ref(PGSTAT_KIND_DATABASE, dboid, InvalidOid,
+                                    false, NULL);
+
+   /*
+    * Should always have been created by
+    * pgstat_prepare_report_checksum_failure().
+    *
+    * When not using assertions, we don't want to crash should something have
+    * gone wrong, so just return.
     */
-   entry_ref =
-       pgstat_get_entry_ref_locked(PGSTAT_KIND_DATABASE, dboid, InvalidOid, false);
+   Assert(entry_ref);
+   if (!entry_ref)
+   {
+       elog(WARNING, "could not report %d conflicts for DB %u",
+            failurecount, dboid);
+       return;
+   }
+
+   pgstat_lock_entry(entry_ref, false);
 
    sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
    sharedent->stats.checksum_failures += failurecount;
 
 extern void pgstat_report_autovac(Oid dboid);
 extern void pgstat_report_recovery_conflict(int reason);
 extern void pgstat_report_deadlock(void);
+extern void pgstat_prepare_report_checksum_failure(Oid dboid);
 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
 extern void pgstat_report_connect(Oid dboid);
 extern void pgstat_update_parallel_workers_stats(PgStat_Counter workers_to_launch,