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..5309aa2bbc 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;
@@ -476,6 +485,13 @@ public static function convertDbUrlToConnectionInfo($url, $root) {
       parse_str($url_components['query'], $query);
       if (isset($query['module']) && $query['module']) {
         $module = $query['module'];
+
+        // Tests for core drivers don't require this function, but it's needed
+        // for drivers in modules.
+        if ($module === 'pgsql_fallback' && !function_exists('drupal_valid_test_ua')) {
+          require_once $root . '/core/includes/bootstrap.inc';
+        }
+
         // Set up an additional autoloader. We don't use the main autoloader as
         // this method can be called before Drupal is installed and is never
         // called during regular runtime.
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/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
index a10af1e48c..bc8d42afc3 100644
--- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
+++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
@@ -507,6 +507,7 @@ protected function installParameters() {
     $connection_info['default']['prefix'] = $connection_info['default']['prefix']['default'];
     unset($connection_info['default']['driver']);
     unset($connection_info['default']['namespace']);
+    unset($connection_info['default']['autoload']);
     unset($connection_info['default']['pdo']);
     unset($connection_info['default']['init_commands']);
     // Remove database connection info that is not used by SQLite.
diff --git a/core/modules/system/tests/modules/database_statement_monitoring_test/src/PgSqlFallback/Connection.php b/core/modules/system/tests/modules/database_statement_monitoring_test/src/PgSqlFallback/Connection.php
new file mode 100644
index 0000000000..55fcbda7b3
--- /dev/null
+++ b/core/modules/system/tests/modules/database_statement_monitoring_test/src/PgSqlFallback/Connection.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Drupal\database_statement_monitoring_test\PgsqlFallback;
+
+use Drupal\pgsql_fallback\Driver\Database\PgsqlFallback\Connection as BaseConnection;
+use Drupal\database_statement_monitoring_test\LoggedStatementsTrait;
+
+/**
+ * PostgreSQL Connection class that can log executed queries.
+ */
+class Connection extends BaseConnection {
+  use LoggedStatementsTrait;
+
+}
diff --git a/core/modules/system/tests/modules/database_statement_monitoring_test/src/PgSqlFallback/Install/Tasks.php b/core/modules/system/tests/modules/database_statement_monitoring_test/src/PgSqlFallback/Install/Tasks.php
new file mode 100644
index 0000000000..63607d10af
--- /dev/null
+++ b/core/modules/system/tests/modules/database_statement_monitoring_test/src/PgSqlFallback/Install/Tasks.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Drupal\database_statement_monitoring_test\PgsqlFallback\Install;
+
+use Drupal\pgsql_fallback\Driver\Database\PgsqlFallback\Install\Tasks as BaseTasks;
+
+class Tasks extends BaseTasks {
+}
diff --git a/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
index 7ff31796d4..d35fd3100f 100644
--- a/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
@@ -31,10 +31,6 @@ class EndOfTransactionQueriesTest extends KernelTestBase {
    * {@inheritdoc}
    */
   protected function setUp(): void {
-    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']));
-    }
-
     parent::setUp();
 
     $this->installSchema('system', 'sequences');
diff --git a/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php b/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php
index d0b8283566..101e9b9407 100644
--- a/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php
+++ b/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php
@@ -35,7 +35,7 @@ public function testChangeDatabasePrefix() {
     // used to avoid unnecessary set up.
     $test_setup = $this->getMockForTrait(TestSetupTrait::class);
     $test_setup->databasePrefix = 'testDbPrefix';
-    $test_setup->root = '';
+    $test_setup->root = dirname(__FILE__, 7);
 
     $method = new \ReflectionMethod(get_class($test_setup), 'changeDatabasePrefix');
     $method->setAccessible(TRUE);
@@ -43,7 +43,7 @@ public function testChangeDatabasePrefix() {
 
     // Ensure that SIMPLETEST_DB defines the default database connection after
     // calling \Drupal\Core\Test\TestSetupTrait::changeDatabasePrefix().
-    $this->assertEquals('pgsql', Database::getConnectionInfo()['default']['driver']);
+    $this->assertEquals('PgsqlFallback', Database::getConnectionInfo()['default']['driver']);
     $this->assertEquals('127.0.0.1', Database::getConnectionInfo()['default']['host']);
   }
 
