diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index fde1ec1..6c522ae 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -288,6 +288,7 @@ static void postgresExplainForeignModify(ModifyTableState *mtstate,
 static bool postgresAnalyzeForeignTable(Relation relation,
 							AcquireSampleRowsFunc *func,
 							BlockNumber *totalpages);
+static List *postgresImportForeignSchema(ForeignServer *server, ImportForeignSchemaStmt * parsetree);
 
 /*
  * Helper functions
@@ -328,6 +329,7 @@ static HeapTuple make_tuple_from_result_row(PGresult *res,
 						   List *retrieved_attrs,
 						   MemoryContext temp_context);
 static void conversion_error_callback(void *arg);
+static PGresult *fetch_remote_tables(PGconn *conn, ImportForeignSchemaStmt * stmt);
 
 
 /*
@@ -365,6 +367,9 @@ postgres_fdw_handler(PG_FUNCTION_ARGS)
 	/* Support functions for ANALYZE */
 	routine->AnalyzeForeignTable = postgresAnalyzeForeignTable;
 
+	/* Support functions for IMPORT FOREIGN SCHEMA */
+	routine->ImportForeignSchema = postgresImportForeignSchema;
+
 	PG_RETURN_POINTER(routine);
 }
 
@@ -2300,6 +2305,170 @@ postgresAnalyzeForeignTable(Relation relation,
 	return true;
 }
 
+static PGresult *
+fetch_remote_tables(PGconn *conn, ImportForeignSchemaStmt * stmt)
+{
+	StringInfoData buf;
+	int			numparams;
+	const char **params = palloc0(sizeof(char *) * 2);
+	PGresult   *res = NULL;
+
+	initStringInfo(&buf);
+	params[0] = strdup((stmt->remote_schema));
+
+	// Check that the schema really exists
+	appendStringInfo(&buf, "SELECT 1 FROM pg_namespace WHERE nspname = $1");
+	res = PQexecParams(conn, buf.data, 1, NULL, params, NULL, NULL, 0);
+	if (PQresultStatus(res) != PGRES_TUPLES_OK)
+		pgfdw_report_error(ERROR, res, conn, true, buf.data);
+	if(PQntuples(res) != 1)
+	{
+		ereport(ERROR,
+				(errcode(ERRCODE_FDW_SCHEMA_NOT_FOUND),
+					errmsg("The schema %s does not exist on the server", params[0])));
+	}
+
+
+	// Fetch all tables from this schema
+	resetStringInfo(&buf);
+	appendStringInfo(&buf,
+		"SELECT relname, "
+			"array_agg(attname::name) as colnames, "
+			"array_agg(atttypid::regtype) as coltypes, "
+			"array_agg(atttypmod::int4) as coltypmod "
+		"FROM pg_class "
+		"INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid "
+		"LEFT  JOIN pg_attribute ON pg_class.oid = pg_attribute.attrelid "
+			 "  AND pg_attribute.attnum >= 0 AND NOT pg_attribute.attisdropped "
+		"WHERE relkind IN ('r', 'v', 'f') "
+		"AND pg_namespace.nspname = $1 ");
+	if (stmt->restriction->restriction_type != IMPORT_ALL)
+	{
+		/* Add conditions */
+		Oid			outfuncoid;
+		bool		isvarlena;
+		Datum	   *elems = palloc0(list_length(stmt->restriction->table_list) * sizeof(Datum));
+		ArrayType  *array;
+		int			i = 0;
+		ListCell   *lc;
+		FmgrInfo   *fmout = palloc0(sizeof(FmgrInfo));
+		getTypeOutputInfo(CSTRINGARRAYOID, &outfuncoid, &isvarlena);
+		fmgr_info(outfuncoid, fmout);
+		foreach(lc, stmt->restriction->table_list)
+		{
+			elems[i] = CStringGetDatum(((RangeVar *) lfirst(lc))->relname);
+			i++;
+		}
+		array = construct_array(elems, i, CSTRINGOID, -2, false, 'c');
+		params[1] = OutputFunctionCall(fmout, PointerGetDatum(array));
+		appendStringInfo(&buf, "AND ");
+		if (stmt->restriction->restriction_type == IMPORT_EXCEPT)
+		{
+			appendStringInfo(&buf, "NOT ");
+		}
+		appendStringInfo(&buf, "pg_class.relname = ANY($2)");
+		numparams = 2;
+		pfree(fmout);
+		pfree(elems);
+	}
+	else
+	{
+		numparams = 1;
+	}
+	appendStringInfo(&buf, "GROUP BY pg_class.oid, pg_class.relname");
+	res = PQexecParams(conn, buf.data, numparams, NULL, params, NULL, NULL, 0);
+	if (PQresultStatus(res) != PGRES_TUPLES_OK)
+		pgfdw_report_error(ERROR, res, conn, true, buf.data);
+	pfree(params);
+	return res;
+}
+
+/*
+ * Map a remote schema to a local one.
+ */
+static List *
+postgresImportForeignSchema(ForeignServer *server,
+							ImportForeignSchemaStmt * parsetree)
+{
+	List	   *tables = NULL;
+	Oid			userid = GetUserId();
+	UserMapping *mapping = GetUserMapping(userid, server->serverid);
+	PGconn	   *conn = GetConnection(server, mapping, false);
+	PGresult   *res;
+	int			numrows,
+				i;
+
+	/* Initialize FmgrInfo for parsing arrays */
+	FmgrInfo   *fmgr_infos = palloc0(sizeof(FmgrInfo) * 3);
+	Oid			typoid,
+			   *typioparam = palloc0(sizeof(Oid) * 3);
+	ArrayIterator *arrays = palloc0(sizeof(ArrayIterator) * 3);
+	Oid			column_types[3] = {NAMEARRAYOID, REGTYPEARRAYOID, INT4ARRAYOID};
+	Datum	   *array_item = palloc0(sizeof(Datum) * 3);
+	bool	   *isnull = palloc0(sizeof(bool) * 3);
+
+	for (i = 0; i < 3; i++)
+	{
+		getTypeInputInfo(column_types[i], &typoid, &typioparam[i]);
+		fmgr_info(typoid, &fmgr_infos[i]);
+	}
+	res = fetch_remote_tables(conn, parsetree);
+	numrows = PQntuples(res);
+	for (i = 0; i < numrows; i++)
+	{
+		CreateForeignTableStmt *stmt = makeNode(CreateForeignTableStmt);
+		char	   *tablename;
+		int			colindex;
+
+		tablename = PQgetvalue(res, i, 0);
+		/* setup the base relation information */
+		stmt->base.relation = makeRangeVar(NULL, tablename, 0);
+		stmt->base.relation->schemaname = strdup(parsetree->local_schema);
+		stmt->servername = server->servername;
+		/* Parse arrays of columns from the result */
+		for (colindex = 0; colindex < 3; colindex++)
+		{
+			Datum		array_datum = InputFunctionCall(&fmgr_infos[colindex],
+											PQgetvalue(res, i, colindex + 1),
+												   typioparam[colindex], -1);
+
+			arrays[colindex] = array_create_iterator(DatumGetArrayTypeP(array_datum), 0);
+		}
+		/* add the individual columns */
+		while (array_iterate(arrays[0], &array_item[0], &isnull[0]) &&
+			   array_iterate(arrays[1], &array_item[1], &isnull[1]) &&
+			   array_iterate(arrays[2], &array_item[2], &isnull[2]))
+		{
+			ColumnDef  *new_column = makeNode(ColumnDef);
+
+			new_column->colname = DatumGetCString(array_item[0]);
+			new_column->typeName = makeTypeNameFromOid(DatumGetObjectId(array_item[1]),
+											   DatumGetInt32(array_item[2]));
+			stmt->base.tableElts = lappend(stmt->base.tableElts, new_column);
+		}
+
+		/*
+		 * Add schema_name and table_name options table_name is added to
+		 * survive a foreign table rename.
+		 */
+		stmt->options = lappend(stmt->options,
+								makeDefElem("schema_name", (Node *) makeString(parsetree->remote_schema)));
+		stmt->options = lappend(stmt->options,
+				  makeDefElem("table_name", (Node *) makeString(tablename)));
+		tables = lappend(tables, stmt);
+	}
+	/* Cleanup */
+	PQclear(res);
+	ReleaseConnection(conn);
+	pfree(array_item);
+	pfree(fmgr_infos);
+	pfree(arrays);
+	pfree(typioparam);
+	pfree(isnull);
+
+	return tables;
+}
+
 /*
  * Acquire a random sample of rows from foreign table managed by postgres_fdw.
  *
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index db18a23..47efb2f 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -445,6 +445,7 @@ DATA(insert OID = 1000 (  _bool		 PGNSP PGUID -1 f b A f t \054 0	16 0 array_in
 DATA(insert OID = 1001 (  _bytea	 PGNSP PGUID -1 f b A f t \054 0	17 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
 DATA(insert OID = 1002 (  _char		 PGNSP PGUID -1 f b A f t \054 0	18 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
 DATA(insert OID = 1003 (  _name		 PGNSP PGUID -1 f b A f t \054 0	19 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
+#define NAMEARRAYOID 1003
 DATA(insert OID = 1005 (  _int2		 PGNSP PGUID -1 f b A f t \054 0	21 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
 #define INT2ARRAYOID		1005
 DATA(insert OID = 1006 (  _int2vector PGNSP PGUID -1 f b A f t \054 0	22 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
