diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php
index 5387c7e..d6c0c6a 100644
--- a/core/lib/Drupal/Core/Entity/entity.api.php
+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -1155,7 +1155,7 @@ function hook_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
     ->fetchField();
 
   // Log the count in a table that records this statistic for deleted entities.
-  db_merge('example_deleted_entity_statistics')
+  \Drupal::database()->merge('example_deleted_entity_statistics')
     ->key(['type' => $type, 'id' => $id])
     ->fields(['count' => $count])
     ->execute();
@@ -1183,7 +1183,7 @@ function hook_ENTITY_TYPE_predelete(Drupal\Core\Entity\EntityInterface $entity)
     ->fetchField();
 
   // Log the count in a table that records this statistic for deleted entities.
-  db_merge('example_deleted_entity_statistics')
+  \Drupal::database()->merge('example_deleted_entity_statistics')
     ->key(['type' => $type, 'id' => $id])
     ->fields(['count' => $count])
     ->execute();
diff --git a/core/modules/history/history.module b/core/modules/history/history.module
index f36121e..58259c9 100644
--- a/core/modules/history/history.module
+++ b/core/modules/history/history.module
@@ -107,7 +107,7 @@ function history_write($nid, $account = NULL) {
   }
 
   if ($account->isAuthenticated()) {
-    db_merge('history')
+    \Drupal::database()->merge('history')
       ->keys([
         'uid' => $account->id(),
         'nid' => $nid,
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index b1298e4..10fe04f 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -837,7 +837,7 @@ function locale_translation_get_file_history() {
  *   FALSE on failure. Otherwise SAVED_NEW or SAVED_UPDATED.
  */
 function locale_translation_update_file_history($file) {
-  $status = db_merge('locale_file')
+  $status = \Drupal::database()->merge('locale_file')
     ->key([
       'project' => $file->project,
       'langcode' => $file->langcode,
diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index ae99a87..cbf1a17 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -210,7 +210,7 @@ function search_update_totals() {
     $total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", [':word' => $word], ['target' => 'replica'])->fetchField();
     // Apply Zipf's law to equalize the probability distribution.
     $total = log10(1 + 1 / (max(1, $total)));
-    db_merge('search_total')
+    \Drupal::database()->merge('search_total')
       ->key('word', $word)
       ->fields(['count' => $total])
       ->execute();
@@ -538,7 +538,7 @@ function search_index($type, $sid, $langcode, $text) {
     // If a word already exists in the database, its score gets increased
     // appropriately. If not, we create a new record with the appropriate
     // starting score.
-    db_merge('search_index')
+    \Drupal::database()->merge('search_index')
       ->keys([
         'word' => $word,
         'sid' => $sid,
diff --git a/core/modules/shortcut/src/ShortcutSetStorage.php b/core/modules/shortcut/src/ShortcutSetStorage.php
index b136c2f..54140b4 100644
--- a/core/modules/shortcut/src/ShortcutSetStorage.php
+++ b/core/modules/shortcut/src/ShortcutSetStorage.php
@@ -9,6 +9,7 @@
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Language\LanguageManagerInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\Core\Database\Connection;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -22,6 +23,13 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
    * @var \Drupal\Core\Extension\ModuleHandlerInterface
    */
   protected $moduleHandler;
+  
+  /**
+   * The database connection.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $database;
 
   /**
    * Constructs a ShortcutSetStorageController object.
@@ -37,10 +45,11 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
    * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
    *   The language manager.
    */
-  public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) {
+  public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, Connection $database) {
     parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager);
 
     $this->moduleHandler = $module_handler;
+    $this->database = $database;
   }
 
   /**
@@ -52,7 +61,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
       $container->get('config.factory'),
       $container->get('uuid'),
       $container->get('module_handler'),
-      $container->get('language_manager')
+      $container->get('language_manager'),
+      $container->get('database')
     );
   }
 
@@ -71,7 +81,7 @@ public function deleteAssignedShortcutSets(ShortcutSetInterface $entity) {
    * {@inheritdoc}
    */
   public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
-    db_merge('shortcut_set_users')
+    $this->database->merge('shortcut_set_users')
       ->key('uid', $account->id())
       ->fields(['set_name' => $shortcut_set->id()])
       ->execute();
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 4a93989..e965336 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -529,7 +529,7 @@ function taxonomy_build_node_index($node) {
     // Insert index entries for all the node's terms.
     if (!empty($tid_all)) {
       foreach ($tid_all as $tid) {
-        db_merge('taxonomy_index')
+        \Drupal::database()->merge('taxonomy_index')
           ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
           ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
           ->execute();
diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module
index dbde704..5bca471 100644
--- a/core/modules/tracker/tracker.module
+++ b/core/modules/tracker/tracker.module
@@ -249,7 +249,7 @@ function _tracker_add($nid, $uid, $changed) {
   $changed = max($node->changed, $changed);
 
   // Update the node-level data.
-  db_merge('tracker_node')
+  \Drupal::database()->merge('tracker_node')
     ->key('nid', $nid)
     ->fields([
       'changed' => $changed,
@@ -258,7 +258,7 @@ function _tracker_add($nid, $uid, $changed) {
     ->execute();
 
   // Create or update the user-level data, first for the user posting.
-  db_merge('tracker_user')
+  \Drupal::database()->merge('tracker_user')
     ->keys([
       'nid' => $nid,
       'uid' => $uid,
diff --git a/core/tests/Drupal/KernelTests/Core/Database/MergeTest.php b/core/tests/Drupal/KernelTests/Core/Database/MergeTest.php
index 9a5688c..0b860f9 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/MergeTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/MergeTest.php
@@ -18,7 +18,7 @@ class MergeTest extends DatabaseTestBase {
   public function testMergeInsert() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    $result = db_merge('test_people')
+    $result = \Drupal::database()->merge('test_people')
       ->key('job', 'Presenter')
       ->fields([
         'age' => 31,
@@ -43,7 +43,7 @@ public function testMergeInsert() {
   public function testMergeUpdate() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    $result = db_merge('test_people')
+    $result = \Drupal::database()->merge('test_people')
       ->key('job', 'Speaker')
       ->fields([
         'age' => 31,
@@ -71,7 +71,7 @@ public function testMergeUpdate() {
   public function testMergeUpdateExcept() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    db_merge('test_people')
+    \Drupal::database()->merge('test_people')
       ->key('job', 'Speaker')
       ->insertFields(['age' => 31])
       ->updateFields(['name' => 'Tiffany'])
@@ -92,7 +92,7 @@ public function testMergeUpdateExcept() {
   public function testMergeUpdateExplicit() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    db_merge('test_people')
+    \Drupal::database()->merge('test_people')
       ->key('job', 'Speaker')
       ->insertFields([
         'age' => 31,
@@ -125,7 +125,7 @@ public function testMergeUpdateExpression() {
     // Note that we are also double-setting age here, once as a literal and
     // once as an expression. This test will only pass if the expression wins,
     // which is what is supposed to happen.
-    db_merge('test_people')
+    \Drupal::database()->merge('test_people')
       ->key('job', 'Speaker')
       ->fields(['name' => 'Tiffany'])
       ->insertFields(['age' => 31])
@@ -147,7 +147,7 @@ public function testMergeUpdateExpression() {
   public function testMergeInsertWithoutUpdate() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    db_merge('test_people')
+    \Drupal::database()->merge('test_people')
       ->key('job', 'Presenter')
       ->execute();
 
@@ -166,7 +166,7 @@ public function testMergeInsertWithoutUpdate() {
   public function testMergeUpdateWithoutUpdate() {
     $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    db_merge('test_people')
+    \Drupal::database()->merge('test_people')
       ->key('job', 'Speaker')
       ->execute();
 
@@ -178,7 +178,7 @@ public function testMergeUpdateWithoutUpdate() {
     $this->assertEqual($person->age, 30, 'Age skipped correctly.');
     $this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
 
-    db_merge('test_people')
+    \Drupal::database()->merge('test_people')
       ->key('job', 'Speaker')
       ->insertFields(['age' => 31])
       ->execute();
@@ -201,7 +201,7 @@ public function testInvalidMerge() {
       // Normally it would throw an exception but we are suppressing it with
       // the throw_exception option.
       $options['throw_exception'] = FALSE;
-      db_merge('test_people', $options)
+      \Drupal::database()->merge('test_people', $options)
         ->fields([
           'age' => 31,
           'name' => 'Tiffany',
@@ -216,7 +216,7 @@ public function testInvalidMerge() {
 
     try {
       // This query will fail because there is no key field specified.
-      db_merge('test_people')
+      \Drupal::database()->merge('test_people')
         ->fields([
           'age' => 31,
           'name' => 'Tiffany',
diff --git a/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php b/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php
index e0badd8..f21f380 100644
--- a/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php
@@ -43,7 +43,7 @@ public function testGarbageCollection() {
 
     // Manually expire the data.
     for ($i = 0; $i <= 3; $i++) {
-      db_merge('key_value_expire')
+      \Drupal::database()->merge('key_value_expire')
         ->keys([
             'name' => 'key_' . $i,
             'collection' => $collection,
