diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php
index 5387c7ef7e..d6c0c6a188 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 f36121ef51..58259c910c 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 b1298e4b67..10fe04f619 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 ae99a8731e..cbf1a17088 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 b136c2fb07..ce0b442319 100644
--- a/core/modules/shortcut/src/ShortcutSetStorage.php
+++ b/core/modules/shortcut/src/ShortcutSetStorage.php
@@ -71,7 +71,7 @@ public function deleteAssignedShortcutSets(ShortcutSetInterface $entity) {
    * {@inheritdoc}
    */
   public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
-    db_merge('shortcut_set_users')
+    \Drupal::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 4a93989ad5..e965336336 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 dbde704a5a..5bca47141c 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 9a5688c5df..0b860f92c1 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 e0badd88d1..f21f38092d 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,
