  import unittest
  import warnings
  from unittest import mock
  
  from django.db import DatabaseError, connection
  from django.test import TestCase
  
  
  @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL tests')
  class Tests(TestCase):
 
</s> remove from django.db import DEFAULT_DB_ALIAS
 </s> add from django.db import connections </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         self.assertEqual(nodb_conn.settings_dict['NAME'], connection.settings_dict['NAME'])
 </s> add         self.assertEqual(nodb_conn.settings_dict['NAME'], connections['other'].settings_dict['NAME']) </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                 "and will use the default database instead.",
 </s> add                 "and will use the first PostgreSQL database instead.",
from django.db import DatabaseError, connection, connections
  import unittest
  import warnings
  from unittest import mock
  
from django.db import DatabaseError, connection, connections
  from django.test import TestCase
  
  
  @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL tests')
  class Tests(TestCase):
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