diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 9fc53cad68..fc061adedb 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -688,6 +688,15 @@ postgresGetForeignRelSize(PlannerInfo *root,
 		/* Report estimated baserel size to planner. */
 		baserel->rows = fpinfo->rows;
 		baserel->reltarget->width = fpinfo->width;
+
+		/*
+		 * plancat.c copied baserel->pages and baserel->tuples from pg_class.
+		 * If the foreign table has never been ANALYZEd, or if its stats are
+		 * out of date, baserel->tuples might now be less than baserel->rows,
+		 * which will confuse assorted logic.  Hack it to appear minimally
+		 * sensible.  (Do we need to hack baserel->pages too?)
+		 */
+		baserel->tuples = Max(baserel->tuples, baserel->rows);
 	}
 	else
 	{
