diff --git a/core/lib/Drupal/Core/Database/StatementWrapper.php b/core/lib/Drupal/Core/Database/StatementWrapper.php
index 4381fd1af62..1a84bf78317 100644
--- a/core/lib/Drupal/Core/Database/StatementWrapper.php
+++ b/core/lib/Drupal/Core/Database/StatementWrapper.php
@@ -260,7 +260,9 @@ public function fetchAll($mode = NULL, $column_index = NULL, $constructor_argume
    */
   #[\ReturnTypeWillChange]
   public function getIterator() {
-    return new \ArrayIterator($this->fetchAll());
+    while (($row = $this->fetch()) !== FALSE) {
+      yield $row;
+    }
   }
 
 }
diff --git a/core/tests/Drupal/KernelTests/Core/Database/StatementTest.php b/core/tests/Drupal/KernelTests/Core/Database/StatementTest.php
index eeb23046638..b02dee9c27c 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/StatementTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/StatementTest.php
@@ -43,4 +43,26 @@ public function testRepeatedInsertStatementReuse() {
     $this->assertSame('31', $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Curly'])->fetchField());
   }
 
+  /**
+   * Tests statement rewinding.
+   */
+  public function testStatementRewind() {
+    $statement = $this->connection->query('SELECT * FROM {test}');
+
+    $count = 0;
+    foreach ($statement as $row) {
+      $count++;
+      $this->assertNotNull($row);
+    }
+    $this->assertGreaterThan(0, $count);
+
+    // Try iterating through the same statement again. Should no-op.
+    $count = 0;
+    foreach ($statement as $row) {
+      $count++;
+      $this->assertNotNull($row);
+    }
+    $this->assertSame(0, $count);
+  }
+
 }
