diff --git a/core/core.services.yml b/core/core.services.yml
index c42ca2dd21..0ebbfae76e 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -448,6 +448,9 @@ services:
   logger.log_message_parser:
     class: Drupal\Core\Logger\LogMessageParser
 
+  database.schema.data:
+    class: Drupal\Core\Schema\SchemaData
+    arguments: ['@module_handler', '@cache.default', '@keyvalue', '@database', '@cache_tags.invalidator']
   serialization.json:
     class: Drupal\Component\Serialization\Json
   serialization.phpserialize:
@@ -522,7 +525,7 @@ services:
     class: Drupal\Core\Extension\ModuleInstaller
     tags:
       - { name: service_collector, tag: 'module_install.uninstall_validator', call: addUninstallValidator }
-    arguments: ['%app.root%', '@module_handler', '@kernel']
+    arguments: ['%app.root%', '@module_handler', '@kernel', '@database.schema.data']
     lazy: true
   extension.list.module:
     class: Drupal\Core\Extension\ModuleExtensionList
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index e0a4943fcd..0cfccbafaa 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -608,6 +608,13 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
  *   unit tests with a clean environment.
  */
 function drupal_static_reset($name = NULL) {
+  switch ($name) {
+    case 'drupal_get_schema_versions':
+    case 'drupal_get_installed_schema_version':
+      @trigger_error("Using drupal_static_reset() with '{$name}' as parameter is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Use \Drupal\Core\Schema\SchemaDataInterface::resetCache() instead. See https://www.drupal.org/node/2444417.", E_USER_DEPRECATED);
+      \Drupal::service('database.schema.data')->resetCache();
+      return;
+  }
   drupal_static($name, NULL, TRUE);
 }
 
diff --git a/core/includes/install.inc b/core/includes/install.inc
index ce7df4759e..f029635e80 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -80,7 +80,7 @@
 function drupal_load_updates() {
   /** @var \Drupal\Core\Extension\ModuleExtensionList $extension_list_module */
   $extension_list_module = \Drupal::service('extension.list.module');
-  foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema_version) {
+  foreach (\Drupal::service('database.schema.data')->getInstalledVersion() as $module => $schema_version) {
     if ($extension_list_module->exists($module) && !$extension_list_module->checkIncompatibility($module)) {
       if ($schema_version > -1) {
         module_load_install($module);
diff --git a/core/includes/schema.inc b/core/includes/schema.inc
index e168e89556..3cd4d36aba 100644
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc
@@ -24,38 +24,17 @@
  * @return array|bool
  *   If the module has updates, an array of available updates sorted by
  *   version. Otherwise, FALSE.
+ *
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
+ *   Use \Drupal\Core\Schema\SchemaDataInterface::getVersions() instead.
+ *
+ * @see https://www.drupal.org/node/2444417
  */
 function drupal_get_schema_versions($module) {
-  $updates = &drupal_static(__FUNCTION__, NULL);
-  if (!isset($updates[$module])) {
-    $updates = [];
-    foreach (\Drupal::moduleHandler()->getModuleList() as $loaded_module => $filename) {
-      $updates[$loaded_module] = [];
-    }
-
-    // Prepare regular expression to match all possible defined hook_update_N().
-    $regexp = '/^(?<module>.+)_update_(?<version>\d+)$/';
-    $functions = get_defined_functions();
-    // Narrow this down to functions ending with an integer, since all
-    // hook_update_N() functions end this way, and there are other
-    // possible functions which match '_update_'. We use preg_grep() here
-    // instead of foreaching through all defined functions, since the loop
-    // through all PHP functions can take significant page execution time
-    // and this function is called on every administrative page via
-    // system_requirements().
-    foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
-      // If this function is a module update function, add it to the list of
-      // module updates.
-      if (preg_match($regexp, $function, $matches)) {
-        $updates[$matches['module']][] = $matches['version'];
-      }
-    }
-    // Ensure that updates are applied in numerical order.
-    foreach ($updates as &$module_updates) {
-      sort($module_updates, SORT_NUMERIC);
-    }
-  }
-  return empty($updates[$module]) ? FALSE : $updates[$module];
+  @trigger_error('drupal_get_schema_versions() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Schema\SchemaDataInterface::getVersions() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED);
+  $versions = \Drupal::service('database.schema.data')->getVersions($module);
+  // Service returns an empty array instead of FALSE as before.
+  return $versions ?: FALSE;
 }
 
 /**
@@ -72,26 +51,20 @@ function drupal_get_schema_versions($module) {
  * @return string|int
  *   The currently installed schema version, or SCHEMA_UNINSTALLED if the
  *   module is not installed.
+ *
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
+ *   Use \Drupal\Core\Schema\SchemaDataInterface::getInstalledVersion() instead.
+ *
+ * @see https://www.drupal.org/node/2444417
  */
 function drupal_get_installed_schema_version($module, $reset = FALSE, $array = FALSE) {
-  $versions = &drupal_static(__FUNCTION__, []);
+  @trigger_error('drupal_get_installed_schema_version() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Schema\SchemaDataInterface::getInstalledVersion() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED);
 
   if ($reset) {
-    $versions = [];
-  }
-
-  if (!$versions) {
-    if (!$versions = \Drupal::keyValue('system.schema')->getAll()) {
-      $versions = [];
-    }
+    \Drupal::service('database.schema.data')->resetCache();
   }
 
-  if ($array) {
-    return $versions;
-  }
-  else {
-    return isset($versions[$module]) ? $versions[$module] : SCHEMA_UNINSTALLED;
-  }
+  return \Drupal::service('database.schema.data')->getInstalledVersion(!$array ? $module : NULL);
 }
 
 /**
@@ -101,11 +74,15 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
  *   A module name.
  * @param string $version
  *   The new schema version.
+ *
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
+ *   Use \Drupal\Core\Schema\SchemaDataInterface::getInstalledVersion() instead.
+ *
+ * @see https://www.drupal.org/node/2444417
  */
 function drupal_set_installed_schema_version($module, $version) {
-  \Drupal::keyValue('system.schema')->set($module, $version);
-  // Reset the static cache of module schema versions.
-  drupal_get_installed_schema_version(NULL, TRUE);
+  @trigger_error('drupal_set_installed_schema_version() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Schema\SchemaDataInterface::setInstalledVersion() instead. See https://www.drupal.org/node/2444417', E_USER_DEPRECATED);
+  \Drupal::service('database.schema.data')->setInstalledVersion($module, $version);
 }
 
 /**
diff --git a/core/includes/update.inc b/core/includes/update.inc
index 9fc3822624..76e16b14d3 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -50,7 +50,7 @@ function update_check_incompatibility($name, $type = 'module') {
 function update_system_schema_requirements() {
   $requirements = [];
 
-  $system_schema = drupal_get_installed_schema_version('system');
+  $system_schema = \Drupal::service('database.schema.data')->getInstalledVersion('system');
 
   $requirements['minimum schema']['title'] = 'Minimum schema version';
   if ($system_schema >= \Drupal::CORE_MINIMUM_SCHEMA_VERSION) {
@@ -100,6 +100,8 @@ function _update_fix_missing_schema() {
   $versions = \Drupal::keyValue('system.schema')->getAll();
   $module_handler = \Drupal::moduleHandler();
   $enabled_modules = $module_handler->getModuleList();
+  /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+  $schema_data = \Drupal::service('database.schema.data');
 
   foreach (array_keys($enabled_modules) as $module) {
     // All modules should have a recorded schema version, but when they
@@ -107,7 +109,7 @@ function _update_fix_missing_schema() {
     if (!isset($versions[$module])) {
       // Ensure the .install file is loaded.
       module_load_install($module);
-      $all_updates = drupal_get_schema_versions($module);
+      $all_updates = $schema_data->getVersions($module);
       // If the schema version of a module hasn't been recorded, we cannot
       // know the actual schema version a module is at, because
       // no updates will ever have been run on the site and it was not set
@@ -129,7 +131,7 @@ function _update_fix_missing_schema() {
       if ($last_removed = $module_handler->invoke($module, 'update_last_removed')) {
         $last_update = max($last_update, $last_removed);
       }
-      drupal_set_installed_schema_version($module, $last_update);
+      $schema_data->setInstalledVersion($module, $last_update);
       $args = ['%module' => $module, '%last_update_hook' => $module . '_update_' . $last_update . '()'];
       \Drupal::messenger()->addWarning(t('Schema information for module %module was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, %last_update_hook.', $args));
       \Drupal::logger('update')->warning('Schema information for module %module was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, %last_update_hook.', $args);
@@ -153,7 +155,7 @@ function update_set_schema($module, $schema_version) {
   \Drupal::service('extension.list.module')->reset();
   \Drupal::service('extension.list.theme_engine')->reset();
   \Drupal::service('extension.list.theme')->reset();
-  drupal_static_reset('drupal_get_installed_schema_version');
+  \Drupal::service('database.schema.data')->resetCache();
 }
 
 /**
@@ -249,7 +251,7 @@ function update_do_one($module, $number, $dependency_map, &$context) {
 
   // Record the schema update if it was completed successfully.
   if ($context['finished'] == 1 && empty($ret['#abort'])) {
-    drupal_set_installed_schema_version($module, $number);
+    \Drupal::service('database.schema.data')->setInstalledVersion($module, $number);
   }
 
   $context['message'] = t('Updating @module', ['@module' => $module]);
@@ -338,7 +340,9 @@ function update_get_update_list() {
   // Make sure that the system module is first in the list of updates.
   $ret = ['system' => []];
 
-  $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
+  /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+  $schema_data = \Drupal::service('database.schema.data');
+  $modules = $schema_data->getInstalledVersion();
   /** @var \Drupal\Core\Extension\ExtensionList $extension_list */
   $extension_list = \Drupal::service('extension.list.module');
   /** @var array $installed_module_info */
@@ -380,8 +384,8 @@ function update_get_update_list() {
       continue;
     }
     // Otherwise, get the list of updates defined by this module.
-    $updates = drupal_get_schema_versions($module);
-    if ($updates !== FALSE) {
+    $updates = $schema_data->getVersions($module);
+    if ($updates) {
       foreach ($updates as $update) {
         if ($update == \Drupal::CORE_MINIMUM_SCHEMA_VERSION) {
           $ret[$module]['warning'] = '<em>' . $module . '</em> module cannot be updated. It contains an update numbered as ' . \Drupal::CORE_MINIMUM_SCHEMA_VERSION . ' which is reserved for the earliest installation of a module in Drupal ' . \Drupal::CORE_COMPATIBILITY . ', before any updates. In order to update <em>' . $module . '</em> module, you will need to install a version of the module with valid updates.';
@@ -507,10 +511,11 @@ function update_get_update_function_list($starting_updates) {
   // Go through each module and find all updates that we need (including the
   // first update that was requested and any updates that run after it).
   $update_functions = [];
+  $schema_data = \Drupal::service('database.schema.data');
   foreach ($starting_updates as $module => $version) {
     $update_functions[$module] = [];
-    $updates = drupal_get_schema_versions($module);
-    if ($updates !== FALSE) {
+    $updates = $schema_data->getVersions($module);
+    if ($updates) {
       $max_version = max($updates);
       if ($version <= $max_version) {
         foreach ($updates as $update) {
@@ -639,7 +644,7 @@ function update_is_missing($module, $number, $update_functions) {
  *   performed; FALSE otherwise.
  */
 function update_already_performed($module, $number) {
-  return $number <= drupal_get_installed_schema_version($module);
+  return $number <= \Drupal::service('database.schema.data')->getInstalledVersion($module);
 }
 
 /**
diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
index 696203a6c5..48dcdc5ac4 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -14,10 +14,10 @@
 use Drupal\Core\Entity\EntityBundleListenerInterface;
 use Drupal\Core\Entity\EntityFieldManagerInterface;
 use Drupal\Core\Entity\EntityInterface;
-use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
-use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\EntityStorageException;
+use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\Query\QueryInterface;
 use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
index 824ed9d651..0913a72e4f 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
@@ -6,10 +6,10 @@
 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
 use Drupal\Core\Entity\ContentEntityTypeInterface;
 use Drupal\Core\Entity\EntityFieldManagerInterface;
-use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\EntityPublishedInterface;
 use Drupal\Core\Entity\EntityStorageException;
 use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
 use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
@@ -2544,6 +2544,7 @@ protected function addUniqueKey($table, $name, array $specifier) {
    *
    * @see hook_schema()
    * @see https://www.drupal.org/node/146843
+   * @see \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema
    */
   public static function castValue(array $info, $value) {
     // Preserve legal NULL values.
diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
index 09f8434370..1d9201598f 100644
--- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -8,6 +8,7 @@
 use Drupal\Core\Entity\EntityStorageException;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\Serialization\Yaml;
+use Drupal\Core\Schema\SchemaDataInterface;
 
 /**
  * Default implementation of the module installer.
@@ -43,6 +44,13 @@ class ModuleInstaller implements ModuleInstallerInterface {
    */
   protected $root;
 
+  /**
+   * The schema service.
+   *
+   * @var \Drupal\Core\Schema\SchemaDataInterface
+   */
+  protected $schemaData;
+
   /**
    * The uninstall validators.
    *
@@ -59,14 +67,21 @@ class ModuleInstaller implements ModuleInstallerInterface {
    *   The module handler.
    * @param \Drupal\Core\DrupalKernelInterface $kernel
    *   The drupal kernel.
+   * @param \Drupal\Core\Schema\SchemaDataInterface|null $schema_data
+   *   (Optional) The schema service.
    *
    * @see \Drupal\Core\DrupalKernel
    * @see \Drupal\Core\CoreServiceProvider
    */
-  public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) {
+  public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, SchemaDataInterface $schema_data = NULL) {
     $this->root = $root;
     $this->moduleHandler = $module_handler;
     $this->kernel = $kernel;
+    if (!$schema_data) {
+      @trigger_error('Calling ModuleInstaller::__construct() without the $schema_data argument is deprecated in drupal:9.1.0. The $schema_data argument will be required in drupal:10.0.0.. See https://www.drupal.org/project/drupal/issues/2124069.', E_USER_DEPRECATED);
+      $schema_data = \Drupal::service('database.schema.data');
+    }
+    $this->schemaData = $schema_data;
   }
 
   /**
@@ -233,7 +248,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
         // Set the schema version to the number of the last update provided by
         // the module, or the minimum core schema version.
         $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION;
-        $versions = drupal_get_schema_versions($module);
+        $versions = $this->schemaData->getVersions($module);
         if ($versions) {
           $version = max(max($versions), $version);
         }
@@ -293,7 +308,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
         if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) {
           $version = max($version, $last_removed);
         }
-        drupal_set_installed_schema_version($module, $version);
+        \Drupal::service('database.schema.data')->setInstalledVersion($module, $version);
 
         // Ensure that all post_update functions are registered already. This
         // should include existing post-updates, as well as any specified as
@@ -514,7 +529,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
     // fastCGI which executes ::destruct() after the Module uninstallation page
     // was sent already.
     \Drupal::service('router.builder')->rebuild();
-    drupal_get_installed_schema_version(NULL, TRUE);
+    \Drupal::service('database.schema.data')->resetCache();
 
     // Let other modules react.
     $this->moduleHandler->invokeAll('modules_uninstalled', [$module_list, $sync_status]);
@@ -581,6 +596,7 @@ protected function updateKernel($module_filenames) {
     // dependencies.
     $container = $this->kernel->getContainer();
     $this->moduleHandler = $container->get('module_handler');
+    $this->schemaData = $container->get('database.schema.data');
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Schema/SchemaData.php b/core/lib/Drupal/Core/Schema/SchemaData.php
new file mode 100644
index 0000000000..3850c7d8df
--- /dev/null
+++ b/core/lib/Drupal/Core/Schema/SchemaData.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace Drupal\Core\Schema;
+
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
+
+/**
+ * Provides database schema handling.
+ */
+class SchemaData implements SchemaDataInterface {
+
+  /**
+   * A static cache of schema currentVersions per module.
+   *
+   * @var array
+   */
+  protected $allVersions = [];
+
+  /**
+   * A static cache of installed schema versions per module.
+   *
+   * @var array
+   */
+  protected $installedVersions = [];
+
+  /**
+   * The module handler.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * The system.schema storage.
+   *
+   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
+   */
+  protected $keyValueStore;
+
+  /**
+   * Constructs a Schema object.
+   *
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler.
+   */
+  public function __construct(ModuleHandlerInterface $module_handler, KeyValueFactoryInterface $key_value) {
+    $this->moduleHandler = $module_handler;
+    $this->keyValueStore = $key_value->get('system.schema');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getVersions($module) {
+    if (!isset($this->allVersions[$module])) {
+      $this->allVersions[$module] = [];
+
+      foreach ($this->moduleHandler->getModuleList() as $loaded_module => $filename) {
+        $this->allVersions[$loaded_module] = [];
+      }
+
+      // Prepare regular expression to match all possible defined
+      // hook_update_N().
+      $regexp = '/^(?<module>.+)_update_(?<version>\d+)$/';
+      $functions = get_defined_functions();
+      // Narrow this down to functions ending with an integer, since all
+      // hook_update_N() functions end this way, and there are other
+      // possible functions which match '_update_'. We use preg_grep() here
+      // instead of foreaching through all defined functions, since the loop
+      // through all PHP functions can take significant page execution time
+      // and this function is called on every administrative page via
+      // system_requirements().
+      foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
+        // If this function is a module update function, add it to the list of
+        // module updates.
+        if (preg_match($regexp, $function, $matches)) {
+          $this->allVersions[$matches['module']][] = $matches['version'];
+        }
+      }
+      // Ensure that updates are applied in numerical order.
+      foreach ($this->allVersions as &$module_updates) {
+        sort($module_updates, SORT_NUMERIC);
+      }
+      unset($module_updates);
+    }
+
+    return empty($this->allVersions[$module]) ? [] : $this->allVersions[$module];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getInstalledVersion($module = NULL) {
+    if (!$this->installedVersions) {
+      $this->installedVersions = $this->keyValueStore->getAll();
+    }
+
+    if ($module) {
+      return $this->installedVersions[$module] ?? SCHEMA_UNINSTALLED;
+    }
+    else {
+      return $this->installedVersions;
+    }
+  }
+
+  public function setInstalledVersion($module, $version) {
+    $this->keyValueStore->set($module, $version);
+    // Update the static cache of module schema versions.
+    $this->installedVersions[$module] = $version;
+  }
+
+
+  /**
+   * {@inheritdoc}
+   */
+  public function resetCache() {
+    $this->allVersions = [];
+    $this->installedVersions = [];
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Schema/SchemaDataInterface.php b/core/lib/Drupal/Core/Schema/SchemaDataInterface.php
new file mode 100644
index 0000000000..0c5090a514
--- /dev/null
+++ b/core/lib/Drupal/Core/Schema/SchemaDataInterface.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Drupal\Core\Schema;
+
+/**
+ * Provides an interface for database schema handling.
+ */
+interface SchemaDataInterface {
+
+  /**
+   * Returns an array of available schema versions for a module.
+   *
+   * @param string $module
+   *   A module name.
+   *
+   * @return array
+   *   If the module has updates, an array of available updates sorted by
+   *   version. Otherwise, an empty array.
+   */
+  public function getVersions($module);
+
+  /**
+   * Returns the currently installed schema version for a module.
+   *
+   * @param string|null $module
+   *   A module name.
+   *
+   * @return string|int|array
+   *   The currently installed schema version, or SCHEMA_UNINSTALLED if the
+   *   module is not installed.
+   *   If $module is not set, information for all modules is returned.
+   */
+  public function getInstalledVersion($module = NULL);
+
+  /**
+   * Updates the installed version information for a module.
+   *
+   * @param string $module
+   *   A module name.
+   * @param string $version
+   *   The new schema version.
+   */
+  public function setInstalledVersion($module, $version);
+
+  /**
+   * Resets the static cache.
+   */
+  public function resetCache();
+
+}
diff --git a/core/lib/Drupal/Core/Updater/Module.php b/core/lib/Drupal/Core/Updater/Module.php
index 4829c53807..46ddfa61ce 100644
--- a/core/lib/Drupal/Core/Updater/Module.php
+++ b/core/lib/Drupal/Core/Updater/Module.php
@@ -89,7 +89,7 @@ public function getSchemaUpdates() {
     }
     module_load_include('install', $this->name);
 
-    if (!$updates = drupal_get_schema_versions($this->name)) {
+    if (!\Drupal::service('database.schema.data')->getVersions($this->name)) {
       return [];
     }
     $modules_with_updates = update_get_update_list();
diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php
index b8ea203de6..9db19c05cc 100644
--- a/core/modules/system/src/Controller/DbUpdateController.php
+++ b/core/modules/system/src/Controller/DbUpdateController.php
@@ -601,7 +601,7 @@ protected function triggerBatch(Request $request) {
         // correct place. (The updates are already sorted, so we can simply base
         // this on the first one we come across in the above foreach loop.)
         if (isset($start[$update['module']])) {
-          drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
+          \Drupal::service('database.schema.data')->setInstalledVersion($update['module'], $update['number'] - 1);
           unset($start[$update['module']]);
         }
         $operations[] = ['update_do_one', [$update['module'], $update['number'], $dependency_map[$function]]];
diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php
index 52f378e709..b2f5bb73e2 100644
--- a/core/modules/system/src/Form/ModulesUninstallForm.php
+++ b/core/modules/system/src/Form/ModulesUninstallForm.php
@@ -153,7 +153,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       // All modules which depend on this one must be uninstalled first, before
       // we can allow this module to be uninstalled.
       foreach (array_keys($module->required_by) as $dependent) {
-        if (drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
+        if (\Drupal::service('database.schema.data')->getInstalledVersion($dependent) != SCHEMA_UNINSTALLED) {
           $form['modules'][$module->getName()]['#required_by'][] = $dependent;
           $form['uninstall'][$module->getName()]['#disabled'] = TRUE;
         }
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index dc39b9a88c..6bb46a7b01 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -786,10 +786,11 @@ function system_requirements($phase) {
 
     // Check installed modules.
     $has_pending_updates = FALSE;
+    $schema_data = \Drupal::service('database.schema.data');
     foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
-      $updates = drupal_get_schema_versions($module);
-      if ($updates !== FALSE) {
-        $default = drupal_get_installed_schema_version($module);
+      $updates = $schema_data->getVersions($module);
+      if ($updates) {
+        $default = \Drupal::service('database.schema.data')->getInstalledVersion($module);
         if (max($updates) > $default) {
           $has_pending_updates = TRUE;
           break;
@@ -808,7 +809,7 @@ function system_requirements($phase) {
     if ($has_pending_updates) {
       $requirements['update']['severity'] = REQUIREMENT_ERROR;
       $requirements['update']['value'] = t('Out of date');
-      $requirements['update']['description'] = t('Some modules have database schema updates to install. You should run the <a href=":update">database update script</a> immediately.', [':update' => Url::fromRoute('system.db_update')->toString()]);
+      $requirements['update']['description'] = t('Some modules have database schema_data updates to install. You should run the <a href=":update">database update script</a> immediately.', [':update' => Url::fromRoute('system.db_update')->toString()]);
     }
 
     $requirements['entity_update'] = [
@@ -1231,17 +1232,19 @@ function system_requirements($phase) {
   // one that was last removed.
   if ($phase == 'update') {
     $module_handler = \Drupal::moduleHandler();
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
     $module_list = [];
     foreach ($module_handler->getImplementations('update_last_removed') as $module) {
       $last_removed = $module_handler->invoke($module, 'update_last_removed');
-      if ($last_removed && $last_removed > drupal_get_installed_schema_version($module)) {
+      if ($last_removed && $last_removed > $schema_data->getInstalledVersion($module)) {
 
         /** @var \Drupal\Core\Extension\Extension $module_info */
         $module_info = \Drupal::service('extension.list.module')->get($module);
         $module_list[$module] = [
           'name' => $module_info->info['name'],
           'last_removed' => $last_removed,
-          'installed_version' => drupal_get_installed_schema_version($module),
+          'installed_version' => $schema_data->getInstalledVersion($module),
         ];
       }
     }
diff --git a/core/modules/system/tests/src/Functional/Module/InstallTest.php b/core/modules/system/tests/src/Functional/Module/InstallTest.php
index e6a83e9323..03e8ad0c0e 100644
--- a/core/modules/system/tests/src/Functional/Module/InstallTest.php
+++ b/core/modules/system/tests/src/Functional/Module/InstallTest.php
@@ -51,9 +51,12 @@ public function testEnableUserTwice() {
    * Tests recorded schema versions of early installed modules in the installer.
    */
   public function testRequiredModuleSchemaVersions() {
-    $version = drupal_get_installed_schema_version('system', TRUE);
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
+    $schema_data->resetCache();
+    $version = $schema_data->getInstalledVersion('system');
     $this->assertTrue($version > 0, 'System module version is > 0.');
-    $version = drupal_get_installed_schema_version('user', TRUE);
+    $version = $schema_data->getInstalledVersion('user');
     $this->assertTrue($version > 0, 'User module version is > 0.');
 
     $post_update_key_value = \Drupal::keyValue('post_update');
diff --git a/core/modules/system/tests/src/Functional/System/StatusTest.php b/core/modules/system/tests/src/Functional/System/StatusTest.php
index 09f27a5ba0..1937aa1d69 100644
--- a/core/modules/system/tests/src/Functional/System/StatusTest.php
+++ b/core/modules/system/tests/src/Functional/System/StatusTest.php
@@ -66,14 +66,17 @@ public function testStatusPage() {
     // The setting config_sync_directory is not properly formed.
     $this->assertRaw(t("Your %file file must define the %setting setting", ['%file' => $this->siteDirectory . '/settings.php', '%setting' => "\$settings['config_sync_directory']"]));
 
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
+
     // Set the schema version of update_test_postupdate to a lower version, so
     // update_test_postupdate_update_8001() needs to be executed.
-    drupal_set_installed_schema_version('update_test_postupdate', 8000);
+    $schema_data->setInstalledVersion('update_test_postupdate', 8000);
     $this->drupalGet('admin/reports/status');
     $this->assertText(t('Out of date'));
 
     // Now cleanup the executed post update functions.
-    drupal_set_installed_schema_version('update_test_postupdate', 8001);
+    $schema_data->setInstalledVersion('update_test_postupdate', 8001);
     /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
     $post_update_registry = \Drupal::service('update.post_update_registry');
     $post_update_registry->filterOutInvokedUpdatesByModule('update_test_postupdate');
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
index 20d18856c1..16b19edd64 100644
--- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
@@ -53,8 +53,11 @@ protected function setUp(): void {
    * Tests that a module with a too old schema version can not be updated.
    */
   public function testLastRemovedVersion() {
-    drupal_set_installed_schema_version('update_test_last_removed', 8000);
-    drupal_set_installed_schema_version('system', 8804);
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
+
+    $schema_data->setInstalledVersion('update_test_last_removed', 8000);
+    $schema_data->setInstalledVersion('system', 8804);
 
     // Access the update page with a schema version that is too old for system
     // and the test module, only the generic core message should be shown.
@@ -70,7 +73,7 @@ public function testLastRemovedVersion() {
 
     // Update the installed version of system and then assert that now,
     // the test module is shown instead.
-    drupal_set_installed_schema_version('system', 8805);
+    $schema_data->setInstalledVersion('system', 8805);
     $this->drupalGet($this->updateUrl);
 
     $assert_session->pageTextNotContains('The version of Drupal you are trying to update from is too old');
@@ -81,10 +84,10 @@ public function testLastRemovedVersion() {
 
     // Set the expected schema version for the node and test module, updates are
     // successful now.
-    drupal_set_installed_schema_version('update_test_last_removed', 8002);
+    $schema_data->setInstalledVersion('update_test_last_removed', 8002);
 
     $this->runUpdates();
-    $this->assertEquals(8003, drupal_get_installed_schema_version('update_test_last_removed'));
+    $this->assertEquals(8003, $schema_data->getInstalledVersion('update_test_last_removed'));
 
   }
 
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php
index 6830c3b7f5..890c7d0d47 100644
--- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathNewDependencyTest.php
@@ -31,7 +31,7 @@ public function testUpdateNewDependency() {
       ->set('module.new_dependency_test', 0)
       ->set('module', module_config_sort($extension_config->get('module')))
       ->save(TRUE);
-    drupal_set_installed_schema_version('new_dependency_test', \Drupal::CORE_MINIMUM_SCHEMA_VERSION);
+    \Drupal::service('database.schema.data')->setInstalledVersion('new_dependency_test', \Drupal::CORE_MINIMUM_SCHEMA_VERSION);
 
     // Rebuild the container and test that the service with the optional unmet
     // dependency is still available while the ones that fail are not.
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php
index 95efd30eac..ce00c55323 100644
--- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateSchemaTest.php
@@ -55,8 +55,11 @@ protected function setUp(): void {
   public function testUpdateHooks() {
     $connection = Database::getConnection();
 
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
+
     // Verify that the 8000 schema is in place.
-    $this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8000);
+    $this->assertEqual($schema_data->getInstalledVersion('update_test_schema'), 8000);
     $this->assertFalse($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');
 
     // Increment the schema version.
@@ -72,7 +75,8 @@ public function testUpdateHooks() {
     $this->checkForMetaRefresh();
 
     // Ensure schema has changed.
-    $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
+    $schema_data->resetCache();
+    $this->assertEqual($schema_data->getInstalledVersion('update_test_schema'), 8001);
     // Ensure the index was added for column a.
     $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
 
@@ -80,7 +84,7 @@ public function testUpdateHooks() {
     require_once $this->root . '/core/includes/update.inc';
     update_set_schema('update_test_schema', 8003);
     // Ensure schema has changed.
-    $this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8003);
+    $this->assertEqual($schema_data->getInstalledVersion('update_test_schema'), 8003);
 
   }
 
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php
index 38a6120d8f..7af1475216 100644
--- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php
@@ -63,6 +63,13 @@ class UpdateScriptTest extends BrowserTestBase {
    */
   private $updateUser;
 
+  /**
+   * The database.schema.data service.
+   *
+   * @var \Drupal\Core\Schema\SchemaDataInterface
+   */
+  protected $schemaData;
+
   protected function setUp(): void {
     parent::setUp();
     $this->updateUrl = Url::fromRoute('system.db_update');
@@ -72,6 +79,7 @@ protected function setUp(): void {
       'access site in maintenance mode',
       'administer themes',
     ]);
+    $this->schemaData = \Drupal::service('database.schema.data');
   }
 
   /**
@@ -142,7 +150,7 @@ public function testRequirements() {
     // successfully.
     $this->drupalLogin($this->updateUser);
     $update_script_test_config->set('requirement_type', REQUIREMENT_WARNING)->save();
-    drupal_set_installed_schema_version('update_script_test', drupal_get_installed_schema_version('update_script_test') - 1);
+    $this->schemaData->setInstalledVersion('update_script_test', $this->schemaData->getInstalledVersion('update_script_test') - 1);
     $this->drupalGet($this->updateUrl, ['external' => TRUE]);
     $this->assertText('This is a requirements warning provided by the update_script_test module.');
     $this->clickLink('try again');
@@ -548,12 +556,13 @@ public function testSuccessfulUpdateFunctionality() {
     $this->assertEqual($final_maintenance_mode, $initial_maintenance_mode, 'Maintenance mode should not have changed after database updates.');
 
     // Reset the static cache to ensure we have the most current setting.
-    $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
+    $this->schemaData->resetCache();
+    $schema_version = $this->schemaData->getInstalledVersion('update_script_test');
     $this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.');
 
     // Set the installed schema version to one less than the current update.
-    drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
-    $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
+    $this->schemaData->setInstalledVersion('update_script_test', $schema_version - 1);
+    $schema_version = $this->schemaData->getInstalledVersion('update_script_test');
     $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
 
     // Click through update.php with 'access administration pages' and
@@ -608,12 +617,13 @@ public function testSuccessfulMultilingualUpdateFunctionality() {
     $config->save();
 
     // Reset the static cache to ensure we have the most current setting.
-    $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
+    $this->schemaData->resetCache();
+    $schema_version = $this->schemaData->getInstalledVersion('update_script_test');
     $this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.');
 
     // Set the installed schema version to one less than the current update.
-    drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
-    $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
+    $this->schemaData->setInstalledVersion('update_script_test', $schema_version - 1);
+    $schema_version = $this->schemaData->getInstalledVersion('update_script_test');
     $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
 
     // Create admin user.
@@ -662,12 +672,12 @@ public function testMaintenanceModeLink() {
    * Helper function to run updates via the browser.
    */
   protected function runUpdates($maintenance_mode) {
-    $schema_version = drupal_get_installed_schema_version('update_script_test');
+    $schema_version = $this->schemaData->getInstalledVersion('update_script_test');
     $this->assertEqual($schema_version, 8001, 'update_script_test is initially installed with schema version 8001.');
 
     // Set the installed schema version to one less than the current update.
-    drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
-    $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
+    $this->schemaData->setInstalledVersion('update_script_test', $schema_version - 1);
+    $schema_version = $this->schemaData->getInstalledVersion('update_script_test');
     $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
 
     // Click through update.php with 'administer software updates' permission.
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatesWith7xTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatesWith7xTest.php
index 27e721b762..37dfb6e9f6 100644
--- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatesWith7xTest.php
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatesWith7xTest.php
@@ -47,13 +47,16 @@ protected function setUp(): void {
   }
 
   public function testWith7x() {
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
+
     // Ensure that the minimum schema version is 8000, despite 7200 update
     // hooks and a 7XXX hook_update_last_removed().
-    $this->assertEqual(drupal_get_installed_schema_version('update_test_with_7x'), 8000);
+    $this->assertEqual($schema_data->getInstalledVersion('update_test_with_7x'), 8000);
 
     // Try to manually set the schema version to 7110 and ensure that no
     // updates are allowed.
-    drupal_set_installed_schema_version('update_test_with_7x', 7110);
+    $schema_data->setInstalledVersion('update_test_with_7x', 7110);
 
     // Click through update.php with 'administer software updates' permission.
     $this->drupalLogin($this->updateUser);
diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
index c1e2618795..0d757166e5 100644
--- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
+++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
@@ -124,8 +124,10 @@ public function testDependencyResolution() {
     $result = $this->moduleInstaller()->uninstall(['config', 'help', 'color']);
     $this->assertTrue($result, 'ModuleInstaller::uninstall() returned TRUE.');
 
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
     foreach (['color', 'config', 'help'] as $module) {
-      $this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, "$module module was uninstalled.");
+      $this->assertEqual($schema_data->getInstalledVersion($module), SCHEMA_UNINSTALLED, "$module module was uninstalled.");
     }
     $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order', []);
     $this->assertEqual($uninstalled_modules, ['color', 'config', 'help'], 'Modules were uninstalled in the correct order.');
@@ -174,10 +176,12 @@ public function testUninstallProfileDependency() {
     $this->assertTrue($this->moduleHandler()->moduleExists($dependency));
 
     // Uninstall the profile module that is not a dependent.
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
     $result = $this->moduleInstaller()->uninstall([$non_dependency]);
     $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.');
     $this->assertFalse($this->moduleHandler()->moduleExists($non_dependency));
-    $this->assertEquals(drupal_get_installed_schema_version($non_dependency), SCHEMA_UNINSTALLED, "$non_dependency module was uninstalled.");
+    $this->assertEquals($schema_data->getInstalledVersion($non_dependency), SCHEMA_UNINSTALLED, "$non_dependency module was uninstalled.");
 
     // Verify that the installation profile itself was not uninstalled.
     $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order', []);
@@ -270,9 +274,11 @@ public function testUninstallContentDependency() {
     // Deleting the entity.
     $entity->delete();
 
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
     $result = $this->moduleInstaller()->uninstall(['help']);
     $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.');
-    $this->assertEqual(drupal_get_installed_schema_version('entity_test'), SCHEMA_UNINSTALLED, "entity_test module was uninstalled.");
+    $this->assertEqual($schema_data->getInstalledVersion('entity_test'), SCHEMA_UNINSTALLED, "entity_test module was uninstalled.");
   }
 
   /**
diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php
index 34d2e86829..ee62c486d9 100644
--- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php
+++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php
@@ -34,8 +34,10 @@ public function testDatabaseLoaded() {
     // Set a value in the cache to prove caches are cleared.
     \Drupal::service('cache.default')->set(__CLASS__, 'Test');
 
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
     foreach (['user' => 8100, 'node' => 8700, 'system' => 8805, 'update_test_schema' => 8000] as $module => $schema) {
-      $this->assertEqual(drupal_get_installed_schema_version($module), $schema, new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema]));
+      $this->assertEqual($schema_data->getInstalledVersion($module), $schema, new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema]));
     }
 
     // Ensure that all {router} entries can be unserialized. If they cannot be
@@ -97,8 +99,11 @@ public function testUpdateHookN() {
     $this->assertEqual([], $container_cannot_be_saved_messages);
 
     // Ensure schema has changed.
-    $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
-    $this->assertEqual(drupal_get_installed_schema_version('update_test_semver_update_n', TRUE), 8001);
+    /** @var \Drupal\Core\Schema\SchemaDataInterface $schema_data */
+    $schema_data = \Drupal::service('database.schema.data');
+    $schema_data->resetCache();
+    $this->assertEqual($schema_data->getInstalledVersion('update_test_schema'), 8001);
+    $this->assertEqual($schema_data->getInstalledVersion('update_test_semver_update_n'), 8001);
     // Ensure the index was added for column a.
     $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
     // Ensure update_test_semver_update_n_update_8001 was run.
diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerDeprecationTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerDeprecationTest.php
new file mode 100644
index 0000000000..10e61faceb
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerDeprecationTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Drupal\KernelTests\Core\Extension;
+
+use Drupal\Core\DrupalKernelInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Extension\ModuleInstaller;
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * @group legacy
+ * @group extension
+ * @coversDefaultClass \Drupal\Core\Extension\ModuleInstaller
+ */
+class ModuleInstallerDeprecationTest extends KernelTestBase {
+
+  /**
+   * @covers ::__construct
+   * @expectedDeprecation Calling ModuleInstaller::__construct() without the $schema_data argument is deprecated in drupal:9.1.0. The $schema_data argument will be required in drupal:10.0.0.. See https://www.drupal.org/project/drupal/issues/2124069.
+   */
+  public function testConstructorDeprecation() {
+    $root = '';
+    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
+    $kernel = $this->prophesize(DrupalKernelInterface::class);
+    $this->assertNotNull(new ModuleInstaller($root, $module_handler->reveal(), $kernel->reveal()));
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Core/Schema/SchemaDataTest.php b/core/tests/Drupal/Tests/Core/Schema/SchemaDataTest.php
new file mode 100644
index 0000000000..1a07e00213
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Schema/SchemaDataTest.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Drupal\Tests\Core\Schema;
+
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
+use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
+use Drupal\Core\Schema\SchemaData;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Simulates a hook_update_N function.
+ */
+function undertest_update_3000() {
+
+}
+
+/**
+ * Simulates a hook_update_N function.
+ *
+ * When filtered this will be rejected.
+ */
+function bad_3() {
+
+}
+
+/**
+ * Simulates a hook_update_N function.
+ */
+function undertest_update_1() {
+
+}
+
+/**
+ * Simulates a hook_update_N functions.
+ *
+ * When filtered this will be rejected.
+ */
+function failed_22_update() {
+
+}
+
+/**
+ * Simulates a hook_update_N function.
+ */
+function undertest_update_20() {
+
+}
+
+/**
+ * Simulates a hook_update_N function.
+ *
+ * When filtered this will be rejected.
+ */
+function undertest_update_1234_failed() {
+
+}
+
+/**
+ * @coversDefaultClass \Drupal\Core\Schema\SchemaData
+ * @group Schema
+ */
+class SchemaDataTest extends UnitTestCase {
+
+  /**
+   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit\Framework\MockObject\MockObject
+   */
+  protected $keyValueStore;
+
+  /**
+   * @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
+   */
+  protected $keyValueFactory;
+
+  protected function setUp(): void {
+    parent::setUp();
+    $this->keyValueFactory = $this->createMock(KeyValueFactoryInterface::class);
+    $this->keyValueStore = $this->createMock(KeyValueStoreInterface::class);
+
+    $this->keyValueFactory
+      ->method('get')
+      ->with('system.schema')
+      ->willReturn($this->keyValueStore);
+  }
+
+  /**
+   * @covers ::getVersions
+   */
+  public function testGetVersions() {
+    $module_name = 'drupal\tests\core\schema\undertest';
+    $module_handler = $this->createMock(ModuleHandlerInterface::class);
+    $module_handler
+      ->method('getModuleList')
+      ->willReturn([]);
+
+    $schema_data = new SchemaData($module_handler, $this->keyValueFactory);
+
+    // Only undertest_update_X - passes through the filter.
+    $expected = ['1', '20', '3000'];
+    $actual = $schema_data->getVersions($module_name);
+
+    $this->assertSame($expected, $actual);
+  }
+
+  /**
+   * @covers ::getInstalledVersion
+   * @covers ::setInstalledVersion
+   * @covers ::resetCache
+   */
+  public function testGetInstalledVersion() {
+    $versions = [
+      'module1' => '1',
+      'module2' => '20',
+      'module3' => '3000',
+    ];
+
+    $this->keyValueStore
+      ->method('getAll')
+      ->willReturnCallback(static function () use ($versions) {
+        return $versions;
+      });
+    $this->keyValueStore
+      ->method('set')
+      ->willReturnCallback(static function ($key, $value) use (&$versions) {
+        $versions[$key] = $value;
+      });
+
+    $schema_data = new SchemaData($this->createMock(ModuleHandlerInterface::class), $this->keyValueFactory);
+
+    $this->assertSame($versions, $schema_data->getInstalledVersion());
+    $this->assertSame(3000, $schema_data->getInstalledVersion('module3'));
+    $schema_data->setInstalledVersion('module3', 3001);
+    $this->assertSame(3001, $schema_data->getInstalledVersion('module3'));
+    $schema_data->resetCache();
+    $this->assertSame(3001, $schema_data->getInstalledVersion('module3'));
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/UpdatePathTestTrait.php b/core/tests/Drupal/Tests/UpdatePathTestTrait.php
index a1ed2e8af5..0691f09681 100644
--- a/core/tests/Drupal/Tests/UpdatePathTestTrait.php
+++ b/core/tests/Drupal/Tests/UpdatePathTestTrait.php
@@ -60,7 +60,7 @@ protected function runUpdates($update_url = NULL) {
 
       // Ensure that there are no pending updates. Clear the schema version
       // static cache first in case it was accessed before running updates.
-      drupal_get_installed_schema_version(NULL, TRUE);
+      \Drupal::service('database.schema.data')->resetCache();
       foreach (['update', 'post_update'] as $update_type) {
         switch ($update_type) {
           case 'update':
