diff --git a/composer.json b/composer.json
index 2dc16113f6..a600aae077 100644
--- a/composer.json
+++ b/composer.json
@@ -92,6 +92,7 @@
         "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
         "drupal-phpunit-upgrade-check": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
         "drupal-phpunit-upgrade": "@composer update phpunit/phpunit symfony/phpunit-bridge phpspec/prophecy symfony/yaml --with-dependencies --no-progress",
+        "drupal-pgsql-fallback": "@composer require drupal/pgsql_fallback:^2",
         "post-update-cmd": [
             "Drupal\\Composer\\Composer::generateMetapackages"
         ],
diff --git a/core/lib/Drupal/Core/Composer/Composer.php b/core/lib/Drupal/Core/Composer/Composer.php
index bd87d53922..12bb65e1fe 100644
--- a/core/lib/Drupal/Core/Composer/Composer.php
+++ b/core/lib/Drupal/Core/Composer/Composer.php
@@ -323,6 +323,11 @@ public static function upgradePHPUnit(Event $event) {
         ->getEventDispatcher()
         ->dispatchScript('drupal-phpunit-upgrade');
     }
+
+    // Hack to get DrupalCI to install the pgsql_fallback contrib project.
+    $event->getComposer()
+      ->getEventDispatcher()
+      ->dispatchScript('drupal-pgsql-fallback');
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php
index 719dd29c4d..24dff3efec 100644
--- a/core/lib/Drupal/Core/Database/Database.php
+++ b/core/lib/Drupal/Core/Database/Database.php
@@ -468,6 +468,15 @@ public static function convertDbUrlToConnectionInfo($url, $root) {
     }
     $driver = $matches[1];
 
+    // Make DrupalCI test the fallback pgsql driver instead of the core one.
+    if ($driver === 'pgsql') {
+      $driver = 'PgsqlFallback';
+      // Replace the driver name in the URL.
+      $url = $driver . substr($url, 5);
+      // Append the module query parameter to the URL.
+      $url .= '?module=pgsql_fallback';
+    }
+
     // Determine if the database driver is provided by a module.
     $module = NULL;
     $connection_class = NULL;
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php
index 86db1ba7bc..6b0b68e740 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php
@@ -46,7 +46,7 @@ public function process(ContainerBuilder $container) {
     }
     else {
       try {
-        $default_backend = $container->get('database')->driver();
+        $default_backend = $container->get('database')->databaseType();
         $container->set('database', NULL);
       }
       catch (\Exception $e) {
diff --git a/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
index 7ff31796d4..d6ccc82b59 100644
--- a/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
@@ -31,6 +31,7 @@ class EndOfTransactionQueriesTest extends KernelTestBase {
    * {@inheritdoc}
    */
   protected function setUp(): void {
+    $this->root = static::getDrupalRoot();
     if (!class_exists($this->getDatabaseConnectionInfo()['default']['namespace'] . '\Connection')) {
       $this->markTestSkipped(sprintf('No logging override exists for the %s database driver. Create it, subclass this test class and override ::getDatabaseConnectionInfo().', $this->getDatabaseConnectionInfo()['default']['driver']));
     }
@@ -182,7 +183,11 @@ protected function getDatabaseConnectionInfo() {
     // @see \Drupal\database_statement_monitoring_test\mysql\Connection
     // @see \Drupal\database_statement_monitoring_test\pgsql\Connection
     // @see \Drupal\database_statement_monitoring_test\sqlite\Connection
-    $info['default']['namespace'] = '\Drupal\database_statement_monitoring_test\\' . $info['default']['driver'];
+    $driver = $info['default']['driver'];
+    if ($driver === 'PgsqlFallback') {
+      $driver = 'pgsql';
+    }
+    $info['default']['namespace'] = '\Drupal\database_statement_monitoring_test\\' . $driver;
     return $info;
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php b/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php
index d0b8283566..eb7a3ccbfc 100644
--- a/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php
+++ b/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Database\Database;
 use Drupal\Core\Test\TestSetupTrait;
+use Drupal\KernelTests\KernelTestBase;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -17,7 +18,7 @@
  * @runTestsInSeparateProcesses
  * @preserveGlobalState disabled
  */
-class TestSetupTraitTest extends UnitTestCase {
+class TestSetupTraitTest extends KernelTestBase {
 
   /**
    * Tests the SIMPLETEST_DB environment variable is used.
diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php
index caabc84f75..55a74707ee 100644
--- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php
+++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php
@@ -5,6 +5,7 @@
 use Drupal\Component\FileSystem\FileSystem;
 use Drupal\Core\Database\Database;
 use Drupal\Core\Test\TestDatabase;
+use Drupal\KernelTests\KernelTestBase;
 use Drupal\Tests\UnitTestCase;
 use GuzzleHttp\Client;
 use GuzzleHttp\Psr7\Request;
@@ -26,7 +27,7 @@
  * @see \Drupal\TestSite\Commands\TestSiteInstallCommand
  * @see \Drupal\TestSite\Commands\TestSiteTearDownCommand
  */
-class TestSiteApplicationTest extends UnitTestCase {
+class TestSiteApplicationTest extends KernelTestBase {
 
   /**
    * The PHP executable path.
