diff --git a/src/test/modules/test_shmem/t/001_late_shmem_alloc.pl b/src/test/modules/test_shmem/t/001_late_shmem_alloc.pl
index 84ec841b542..c154f57682a 100644
--- a/src/test/modules/test_shmem/t/001_late_shmem_alloc.pl
+++ b/src/test/modules/test_shmem/t/001_late_shmem_alloc.pl
@@ -32,12 +32,18 @@ $node->start;
 
 # When loaded via shared_preload_libraries, the attach callback is
 # called or not, depending on whether this is an EXEC_BACKEND build.
+my $exec_backend = $node->safe_psql("postgres", "SHOW debug_exec_backend;") eq 'on';
 $attach_count1 = $node->safe_psql("postgres", "SELECT get_test_shmem_attach_count();");
 $attach_count2 = $node->safe_psql("postgres", "SELECT get_test_shmem_attach_count();");
 
-ok($attach_count1 == 0 && $attach_count2 == 0 ||
-   $attach_count2 >= $attach_count1,
-   "loaded via shared_preload_libraries");
+if ($exec_backend)
+{
+   cmp_ok($attach_count2, '>', $attach_count1, "attach callback is called in each backend when loaded via shared_preload_libraries");
+}
+else
+{
+   ok($attach_count1 == 0 && $attach_count2 == 0, "attach callback is not called when loaded via shared_preload_libraries");
+}
 
 $node->stop;
 done_testing();
diff --git a/src/test/modules/test_shmem/test_shmem.c b/src/test/modules/test_shmem/test_shmem.c
index 1d7f31b37c7..d52cd1877f8 100644
--- a/src/test/modules/test_shmem/test_shmem.c
+++ b/src/test/modules/test_shmem/test_shmem.c
@@ -18,7 +18,6 @@
 
 #include "postgres.h"
 
-#include "access/relation.h"
 #include "fmgr.h"
 #include "miscadmin.h"
 #include "storage/shmem.h"
