diff --git a/src/bin/pg_verify_checksums/t/002_actions.pl b/src/bin/pg_verify_checksums/t/002_actions.pl
index 12cca604e6..181f58f67c 100644
--- a/src/bin/pg_verify_checksums/t/002_actions.pl
+++ b/src/bin/pg_verify_checksums/t/002_actions.pl
@@ -113,11 +113,10 @@ command_fails(['pg_verify_checksums',  '-D', $pgdata],
 check_relation_corruption($node, 'corrupt1', 'pg_default');
 
 # Create tablespace to check corruptions in a non-default tablespace.
-my $basedir = $node->basedir;
-my $tablespace_dir = "$basedir/ts_corrupt_dir";
-mkdir ($tablespace_dir);
+my $tablespaceDir = TestLib::tempdir;
+my $realTSDir = TestLib::real_dir($tablespaceDir);
 $node->safe_psql('postgres',
-	"CREATE TABLESPACE ts_corrupt LOCATION '$tablespace_dir';");
+	"CREATE TABLESPACE ts_corrupt LOCATION '$realTSDir';");
 check_relation_corruption($node, 'corrupt2', 'ts_corrupt');
 
 # Utility routine to check that pg_verify_checksums is able to detect
