                      if verbosity >= 1:
                          print("Destroying old test database for alias %s..." % (
                              self._get_database_display_str(verbosity, target_database_name),
                          ))
                      cursor.execute("DROP DATABASE %s" % self._quote_name(target_database_name))
                      cursor.execute(creation_sql)
                  except Exception as e:
                      sys.stderr.write("Got an error cloning the test database: %s\n" % e)
                      sys.exit(2)
 
</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(creation_sql)
            except Exception:
                if keepdb:
                    return
 </s> add                 self._execute_create_test_db(cursor, test_db_params, keepdb)
            except Exception as e: </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),
        }
                    cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
                    self._execute_create_test_db(cursor, test_db_params, keepdb)
                      if verbosity >= 1:
                          print("Destroying old test database for alias %s..." % (
                              self._get_database_display_str(verbosity, target_database_name),
                          ))
                    cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
                    self._execute_create_test_db(cursor, test_db_params, keepdb)
                    cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
                    self._execute_create_test_db(cursor, test_db_params, keepdb)
                  except Exception as e:
                      sys.stderr.write("Got an error cloning the test database: %s\n" % e)
                      sys.exit(2)
keep keep keep keep replace replace 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