  import warnings
  
  from django.conf import settings
  from django.core.exceptions import ImproperlyConfigured
  from django.db import DEFAULT_DB_ALIAS
  from django.db.backends.base.base import BaseDatabaseWrapper
  from django.db.utils import DatabaseError as WrappedDatabaseError
  from django.utils.functional import cached_property
  from django.utils.safestring import SafeText
  from django.utils.version import get_version_tuple
 
</s> remove from django.db import DatabaseError, connection
 </s> add from django.db import DatabaseError, connection, connections </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         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             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.",
from django.db import connections
  import warnings
  
  from django.conf import settings
  from django.core.exceptions import ImproperlyConfigured
from django.db import connections
  from django.db.backends.base.base import BaseDatabaseWrapper
  from django.db.utils import DatabaseError as WrappedDatabaseError
  from django.utils.functional import cached_property
  from django.utils.safestring import SafeText
  from django.utils.version import get_version_tuple
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. 
django/db/backends/postgresql/base.py