                              side_effect=mocked_connect, autospec=True):
                  warnings.simplefilter('always', RuntimeWarning)
                  nodb_conn = connection._nodb_connection
          self.assertIsNotNone(nodb_conn.settings_dict['NAME'])
          self.assertEqual(nodb_conn.settings_dict['NAME'], connection.settings_dict['NAME'])
          # Check a RuntimeWarning has been emitted
          self.assertEqual(len(w), 1)
          self.assertEqual(w[0].message.__class__, RuntimeWarning)
  
      def test_connect_and_rollback(self):
 
</s> remove                 warnings.simplefilter('always', RuntimeWarning)
                nodb_conn = connection._nodb_connection
 </s> add                 with mock.patch.object(
                    connection,
                    'settings_dict',
                    {**connection.settings_dict, 'NAME': 'postgres'},
                ):
                    warnings.simplefilter('always', RuntimeWarning)
                    nodb_conn = connection._nodb_connection </s> remove             settings_dict = self.settings_dict.copy()
            settings_dict['NAME'] = settings.DATABASES[DEFAULT_DB_ALIAS]['NAME']
            nodb_connection = self.__class__(
                self.settings_dict.copy(),
                alias=self.alias,
                allow_thread_sharing=False,
            )
 </s> add             for connection in connections.all():
                if connection.vendor == 'postgresql' and connection.settings_dict['NAME'] != 'postgres':
                    return self.__class__(
                        {**self.settings_dict, 'NAME': connection.settings_dict['NAME']},
                        alias=self.alias,
                        allow_thread_sharing=False,
                    ) </s> remove                 "and will use the default database instead.",
 </s> add                 "and will use the first PostgreSQL database instead.", </s> remove from django.db import DatabaseError, connection
 </s> add from django.db import DatabaseError, connection, connections </s> remove from django.db import DEFAULT_DB_ALIAS
 </s> add from django.db import connections
        self.assertEqual(nodb_conn.settings_dict['NAME'], connections['other'].settings_dict['NAME'])
                              side_effect=mocked_connect, autospec=True):
                  warnings.simplefilter('always', RuntimeWarning)
                  nodb_conn = connection._nodb_connection
          self.assertIsNotNone(nodb_conn.settings_dict['NAME'])
        self.assertEqual(nodb_conn.settings_dict['NAME'], connections['other'].settings_dict['NAME'])
          # Check a RuntimeWarning has been emitted
          self.assertEqual(len(w), 1)
          self.assertEqual(w[0].message.__class__, RuntimeWarning)
  
      def test_connect_and_rollback(self):
keep keep keep keep replace keep keep keep keep keep
 Refs #24791 -- Made PostgreSQL's nodb connection use first PostgresSQL db when 'postgres' db isn't available.

Thanks Tim Graham and Claude Paroz for reviews. 
tests/backends/postgresql/tests.py