diff --git a/core/lib/Drupal/Core/Command/DbDumpCommand.php b/core/lib/Drupal/Core/Command/DbDumpCommand.php
index 6b2cc7f7029e1547c9f713355ed2d6290eb775b1..4842b0d990bfed2d05738bb32a0fde85bf36a692 100644
--- a/core/lib/Drupal/Core/Command/DbDumpCommand.php
+++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php
@@ -415,13 +415,17 @@ protected function getTemplate() {
 $connection = Database::getConnection();
 // Ensure any tables with a serial column with a value of 0 are created as
 // expected.
-$sql_mode = $connection->query("SELECT @@sql_mode;")->fetchField();
-$connection->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'");
+if ($connection->databaseType() === 'mysql') {
+  $sql_mode = $connection->query("SELECT @@sql_mode;")->fetchField();
+  $connection->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'");
+}
 
 {{TABLES}}
 
 // Reset the SQL mode.
-$connection->query("SET sql_mode = '$sql_mode'");
+if ($connection->databaseType() === 'mysql') {
+  $connection->query("SET sql_mode = '$sql_mode'");
+}
 ENDOFSCRIPT;
     return $script;
   }