          )
  
      def _clone_test_db(self, number, verbosity, keepdb=False):
          # CREATE DATABASE ... WITH TEMPLATE ... requires closing connections
          # to the template database.
          self.connection.close()
 
</s> remove         suffix = self._get_database_create_suffix(template=source_database_name)
        creation_sql = "CREATE DATABASE {} {}".format(self._quote_name(target_database_name), suffix)

 </s> add         test_db_params = {
            'dbname': self._quote_name(target_database_name),
            'suffix': self._get_database_create_suffix(template=source_database_name),
        } </s> remove                         cursor.execute(
                            "DROP DATABASE %s" % qn(test_database_name))
                        cursor.execute(
                            "CREATE DATABASE %s %s" % (qn(test_database_name),
                                                       suffix))
 </s> add                         cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
                        self._execute_create_test_db(cursor, test_db_params, keepdb) </s> remove                     cursor.execute("DROP DATABASE %s" % self._quote_name(target_database_name))
                    cursor.execute(creation_sql)
 </s> add                     cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
                    self._execute_create_test_db(cursor, test_db_params, keepdb) </s> remove                 cursor.execute(creation_sql)
            except Exception:
                if keepdb:
                    return
 </s> add                 self._execute_create_test_db(cursor, test_db_params, keepdb)
            except Exception as e:
    def _execute_create_test_db(self, cursor, parameters, keepdb=False):
        try:
            super()._execute_create_test_db(cursor, parameters, keepdb)
        except Exception as e:
            exc_msg = 'database %s already exists' % parameters['dbname']
            if exc_msg not in str(e):
                # All errors except "database already exists" cancel tests
                sys.stderr.write('Got an error creating the test database: %s\n' % e)
                sys.exit(2)
            elif not keepdb:
                # If the database should be kept, ignore "database already
                # exists".
                raise e

          )
  
    def _execute_create_test_db(self, cursor, parameters, keepdb=False):
        try:
            super()._execute_create_test_db(cursor, parameters, keepdb)
        except Exception as e:
            exc_msg = 'database %s already exists' % parameters['dbname']
            if exc_msg not in str(e):
                # All errors except "database already exists" cancel tests
                sys.stderr.write('Got an error creating the test database: %s\n' % e)
                sys.exit(2)
            elif not keepdb:
                # If the database should be kept, ignore "database already
                # exists".
                raise e

      def _clone_test_db(self, number, verbosity, keepdb=False):
          # CREATE DATABASE ... WITH TEMPLATE ... requires closing connections
          # to the template database.
          self.connection.close()
keep add keep keep keep keep
 Fixed #25406 -- Removed exception hiding in PostgreSQL test database creation during --keepdb.

Thanks Markus Holtermann and Tim Graham for reviews. 
django/db/backends/postgresql/creation.py