*** a/src/backend/access/rmgrdesc/dbasedesc.c
--- b/src/backend/access/rmgrdesc/dbasedesc.c
***************
*** 35,43 **** dbase_desc(StringInfo buf, XLogReaderState *record)
  	else if (info == XLOG_DBASE_DROP)
  	{
  		xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) rec;
  
! 		appendStringInfo(buf, "dir %u/%u",
! 						 xlrec->db_id, xlrec->tablespace_id);
  	}
  }
  
--- 35,46 ----
  	else if (info == XLOG_DBASE_DROP)
  	{
  		xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) rec;
+ 		int		i;
  
! 		appendStringInfo(buf, "dir");
! 		for (i = 0; i < xlrec->tablespace_num; i++)
! 			appendStringInfo(buf, " %u/%u",
! 							 xlrec->db_id, xlrec->tablespace_ids[i]);
  	}
  }
  
*** a/src/backend/commands/dbcommands.c
--- b/src/backend/commands/dbcommands.c
***************
*** 1362,1371 **** movedb(const char *dbname, const char *tblspcname)
  		xl_dbase_drop_rec xlrec;
  
  		xlrec.db_id = db_id;
! 		xlrec.tablespace_id = src_tblspcoid;
  
  		XLogBeginInsert();
  		XLogRegisterData((char *) &xlrec, sizeof(xl_dbase_drop_rec));
  
  		(void) XLogInsert(RM_DBASE_ID,
  						  XLOG_DBASE_DROP | XLR_SPECIAL_REL_UPDATE);
--- 1362,1372 ----
  		xl_dbase_drop_rec xlrec;
  
  		xlrec.db_id = db_id;
! 		xlrec.tablespace_num = 1;
  
  		XLogBeginInsert();
  		XLogRegisterData((char *) &xlrec, sizeof(xl_dbase_drop_rec));
+ 		XLogRegisterData((char *) &src_tblspcoid, sizeof(Oid));
  
  		(void) XLogInsert(RM_DBASE_ID,
  						  XLOG_DBASE_DROP | XLR_SPECIAL_REL_UPDATE);
***************
*** 1873,1878 **** remove_dbtablespaces(Oid db_id)
--- 1874,1884 ----
  	Relation	rel;
  	HeapScanDesc scan;
  	HeapTuple	tuple;
+ 	List		*ltblspc = NIL;
+ 	ListCell	*cell;
+ 	int		ntblspc;
+ 	int		i;
+ 	Oid		*tablespace_ids;
  
  	rel = heap_open(TableSpaceRelationId, AccessShareLock);
  	scan = heap_beginscan_catalog(rel, 0, NULL);
***************
*** 1900,1922 **** remove_dbtablespaces(Oid db_id)
  					(errmsg("some useless files may be left behind in old database directory \"%s\"",
  							dstpath)));
  
! 		/* Record the filesystem change in XLOG */
! 		{
! 			xl_dbase_drop_rec xlrec;
  
! 			xlrec.db_id = db_id;
! 			xlrec.tablespace_id = dsttablespace;
  
! 			XLogBeginInsert();
! 			XLogRegisterData((char *) &xlrec, sizeof(xl_dbase_drop_rec));
  
! 			(void) XLogInsert(RM_DBASE_ID,
! 							  XLOG_DBASE_DROP | XLR_SPECIAL_REL_UPDATE);
! 		}
  
! 		pfree(dstpath);
  	}
  
  	heap_endscan(scan);
  	heap_close(rel, AccessShareLock);
  }
--- 1906,1940 ----
  					(errmsg("some useless files may be left behind in old database directory \"%s\"",
  							dstpath)));
  
! 		ltblspc = lappend_oid(ltblspc, dsttablespace);
! 		pfree(dstpath);
! 	}
  
! 	ntblspc = list_length(ltblspc);
! 	Assert(ntblspc > 0);
  
! 	tablespace_ids = (Oid *) palloc(ntblspc * sizeof(Oid));
! 	i = 0;
! 	foreach(cell, ltblspc)
! 		tablespace_ids[i++] = lfirst_oid(cell);
  
! 	/* Record the filesystem change in XLOG */
! 	{
! 		xl_dbase_drop_rec xlrec;
! 		xlrec.db_id = db_id;
! 		xlrec.tablespace_num = ntblspc;
  
! 		XLogBeginInsert();
! 		XLogRegisterData((char *) &xlrec, MinSizeOfDbaseDropRec);
! 		XLogRegisterData((char *) tablespace_ids, ntblspc * sizeof(Oid));
! 
! 		(void) XLogInsert(RM_DBASE_ID,
! 						  XLOG_DBASE_DROP | XLR_SPECIAL_REL_UPDATE);
  	}
  
+ 	list_free(ltblspc);
+ 	pfree(tablespace_ids);
+ 
  	heap_endscan(scan);
  	heap_close(rel, AccessShareLock);
  }
***************
*** 2122,2129 **** dbase_redo(XLogReaderState *record)
  	{
  		xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) XLogRecGetData(record);
  		char	   *dst_path;
! 
! 		dst_path = GetDatabasePath(xlrec->db_id, xlrec->tablespace_id);
  
  		if (InHotStandby)
  		{
--- 2140,2146 ----
  	{
  		xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) XLogRecGetData(record);
  		char	   *dst_path;
! 		int			i;
  
  		if (InHotStandby)
  		{
***************
*** 2153,2163 **** dbase_redo(XLogReaderState *record)
  		/* Clean out the xlog relcache too */
  		XLogDropDatabase(xlrec->db_id);
  
! 		/* And remove the physical files */
! 		if (!rmtree(dst_path, true))
! 			ereport(WARNING,
! 					(errmsg("some useless files may be left behind in old database directory \"%s\"",
! 							dst_path)));
  
  		if (InHotStandby)
  		{
--- 2170,2186 ----
  		/* Clean out the xlog relcache too */
  		XLogDropDatabase(xlrec->db_id);
  
! 		for (i = 0; i < xlrec->tablespace_num; i++)
! 		{
! 			dst_path = GetDatabasePath(xlrec->db_id, xlrec->tablespace_ids[i]);
! 
! 			/* And remove the physical files */
! 			if (!rmtree(dst_path, true))
! 				ereport(WARNING,
! 						(errmsg("some useless files may be left behind in old database directory \"%s\"",
! 								dst_path)));
! 			pfree(dst_path);
! 		}
  
  		if (InHotStandby)
  		{
*** a/src/include/commands/dbcommands_xlog.h
--- b/src/include/commands/dbcommands_xlog.h
***************
*** 32,41 **** typedef struct xl_dbase_create_rec
  
  typedef struct xl_dbase_drop_rec
  {
- 	/* Records dropping of a single subdirectory incl. contents */
  	Oid			db_id;
! 	Oid			tablespace_id;
  } xl_dbase_drop_rec;
  
  extern void dbase_redo(XLogReaderState *rptr);
  extern void dbase_desc(StringInfo buf, XLogReaderState *rptr);
--- 32,42 ----
  
  typedef struct xl_dbase_drop_rec
  {
  	Oid			db_id;
! 	int			tablespace_num;		/* number of tablespace IDs */
! 	Oid			tablespace_ids[FLEXIBLE_ARRAY_MEMBER];
  } xl_dbase_drop_rec;
+ #define MinSizeOfDbaseDropRec offsetof(xl_dbase_drop_rec, tablespace_ids)
  
  extern void dbase_redo(XLogReaderState *rptr);
  extern void dbase_desc(StringInfo buf, XLogReaderState *rptr);
