diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index e066a3f888..60c3d11ec5 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -1469,6 +1469,7 @@ retry:
 	 */
 	if (BUF_STATE_GET_REFCOUNT(buf_state) != 0)
 	{
+pg_usleep(1000000L);
 		UnlockBufHdr(buf, buf_state);
 		LWLockRelease(oldPartitionLock);
 		/* safety check: should definitely not be our *own* pin */
@@ -5080,6 +5081,7 @@ WaitIO(BufferDesc *buf)
 		buf_state = LockBufHdr(buf);
 		UnlockBufHdr(buf, buf_state);
 
+ProcessInterrupts();
 		if (!(buf_state & BM_IO_IN_PROGRESS))
 			break;
 		ConditionVariableSleep(cv, WAIT_EVENT_BUFFER_IO);
diff --git a/src/test/recovery/t/099_stream_vacuum.pl b/src/test/recovery/t/099_stream_vacuum.pl
new file mode 100644
index 0000000000..a0ed58a3a2
--- /dev/null
+++ b/src/test/recovery/t/099_stream_vacuum.pl
@@ -0,0 +1,58 @@
+# Run the standard regression tests with streaming replication
+use strict;
+use warnings;
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+use File::Basename;
+
+# Initialize primary node
+my $node_primary = PostgreSQL::Test::Cluster->new('primary');
+$node_primary->init(allows_streaming => 1);
+$node_primary->append_conf('postgresql.conf', qq{
+fsync = off
+
+max_connections = 200
+
+log_min_messages = INFO
+log_connections = on
+log_disconnections = on
+log_line_prefix = '%m|%u|%d|%c|'
+log_statement = 'all'
+
+shared_buffers = 1MB
+});
+
+# Increase some settings that Cluster->new makes too low by default.
+$node_primary->adjust_conf('postgresql.conf', 'max_connections', '25');
+
+$node_primary->start;
+
+is( $node_primary->psql(
+		'postgres',
+		qq[SELECT pg_create_physical_replication_slot('standby');]),
+	0,
+	'physical slot created on primary');
+my $backup_name = 'my_backup';
+
+# Take backup
+$node_primary->backup($backup_name);
+
+# Create streaming standby linking to primary
+my $node_standby = PostgreSQL::Test::Cluster->new('standby');
+$node_standby->init_from_backup($node_primary, $backup_name,
+	has_streaming => 1);
+$node_standby->append_conf('postgresql.conf', "primary_slot_name = standby");
+$node_standby->append_conf('postgresql.conf', "max_standby_streaming_delay = 600s");
+$node_standby->start;
+
+my $setenv = "PGHOST=" . $node_primary->host . " PGPORT=" . $node_primary->port;
+system(qq(sh -c "$setenv ./vacuum-test.sh"));
+
+# Wait for standby to catch up
+$node_primary->wait_for_replay_catchup($node_standby);
+
+$node_standby->stop;
+$node_primary->stop;
+
+done_testing();
diff --git a/src/test/recovery/vacuum-test.sh b/src/test/recovery/vacuum-test.sh
new file mode 100755
index 0000000000..34061a6745
--- /dev/null
+++ b/src/test/recovery/vacuum-test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+numclients=20
+for ((c=1; c<=numclients;c++)); do createdb db$c; done
+
+for ((i=1;i<=50;i++)); do
+  echo "I $i"
+  for ((c=1; c<=numclients;c++)); do
+    echo "
+DROP TABLE IF EXISTS t;
+
+CREATE TABLE t(i int);
+INSERT INTO t SELECT g FROM generate_series(1, 100000) g;
+
+DELETE FROM t WHERE i > 1000;
+SET statement_timeout = '0.5s';
+VACUUM (VERBOSE, ANALYZE) t;
+RESET statement_timeout;
+VACUUM (VERBOSE) t;
+" | psql db$c >/dev/null &
+  done
+  wait
+done
