Request XLOG switch before writing checkpoint in pg_start_backup(). Otherwise you can end up with an unrecoverable backup if you start a new base backup right after finishing archive recovery. In that scenario, the redo pointer of the checkpoint that pg_start_backup() writes points to the XLOG segment where the timeline-changing end-of-archive-recovery checkpoint is. The beginning of that segment contains pages with the old timeline ID, and we don't accept that in recovery unless we find a history file covering the old timeline ID. If you omit pg_xlog from the base backup and clear the archive directory before starting the backup, there will be no such history file available.
Request XLOG switch before writing checkpoint in pg_start_backup(). Otherwise
you can end up with an unrecoverable backup if you start a new base backup
right after finishing archive recovery. In that scenario, the redo pointer of
the checkpoint that pg_start_backup() writes points to the XLOG segment where
the timeline-changing end-of-archive-recovery checkpoint is. The beginning
of that segment contains pages with the old timeline ID, and we don't accept
that in recovery unless we find a history file covering the old timeline ID.
If you omit pg_xlog from the base backup and clear the archive directory
before starting the backup, there will be no such history file available.

The bug is present in all versions since PITR was introduced in 8.0, but I'm
back-patching only back to 8.2. Earlier versions didn't have XLOG switch
records, making this fix unfeasible. Given the lack of reports until now,
it doesn't seem worthwhile to spend more effort to fix 8.0 and 8.1.

Per report and suggestion by Mikael Krantz

50wu/gpdb,edespino/gpdb,ahachete/gpdb,zaksoup/gpdb,Quikling/gpdb,rvs/gpdb,Chibin/gpdb,janebeckman/gpdb,ahachete/gpdb,xinzweb/gpdb,janebeckman/gpdb,adam8157/gpdb,janebeckman/gpdb,kaknikhil/gpdb,ahachete/gpdb,50wu/gpdb,yuanzhao/gpdb,ashwinstar/gpdb,kaknikhil/gpdb,lisakowen/gpdb,chrishajas/gpdb,lisakowen/gpdb,cjcjameson/gpdb,jmcatamney/gpdb,Chibin/gpdb,lintzc/gpdb,lisakowen/gpdb,Quikling/gpdb,jmcatamney/gpdb,rvs/gpdb,zaksoup/gpdb,jmcatamney/gpdb,xinzweb/gpdb,jmcatamney/gpdb,zaksoup/gpdb,greenplum-db/gpdb,janebeckman/gpdb,edespino/gpdb,xinzweb/gpdb,zaksoup/gpdb,0x0FFF/gpdb,royc1/gpdb,lisakowen/gpdb,CraigHarris/gpdb,ahachete/gpdb,CraigHarris/gpdb,janebeckman/gpdb,ahachete/gpdb,greenplum-db/gpdb,chrishajas/gpdb,adam8157/gpdb,greenplum-db/gpdb,Quikling/gpdb,ashwinstar/gpdb,Chibin/gpdb,xuegang/gpdb,greenplum-db/gpdb,lintzc/gpdb,adam8157/gpdb,greenplum-db/gpdb,edespino/gpdb,0x0FFF/gpdb,janebeckman/gpdb,royc1/gpdb,ashwinstar/gpdb,rvs/gpdb,Quikling/gpdb,Quikling/gpdb,greenplum-db/gpdb,yuanzhao/gpdb,Chibin/gpdb,ahachete/gpdb,janebeckman/gpdb,yuanzhao/gpdb,greenplum-db/gpdb,yuanzhao/gpdb,xuegang/gpdb,ashwinstar/gpdb,adam8157/gpdb,lisakowen/gpdb,yuanzhao/gpdb,CraigHarris/gpdb,cjcjameson/gpdb,chrishajas/gpdb,CraigHarris/gpdb,50wu/gpdb,edespino/gpdb,lintzc/gpdb,jmcatamney/gpdb,xinzweb/gpdb,zaksoup/gpdb,cjcjameson/gpdb,xuegang/gpdb,adam8157/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,0x0FFF/gpdb,adam8157/gpdb,rvs/gpdb,janebeckman/gpdb,xuegang/gpdb,Chibin/gpdb,50wu/gpdb,ahachete/gpdb,chrishajas/gpdb,ashwinstar/gpdb,lisakowen/gpdb,xuegang/gpdb,50wu/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,cjcjameson/gpdb,cjcjameson/gpdb,chrishajas/gpdb,adam8157/gpdb,yuanzhao/gpdb,Chibin/gpdb,adam8157/gpdb,50wu/gpdb,xuegang/gpdb,CraigHarris/gpdb,cjcjameson/gpdb,rvs/gpdb,Chibin/gpdb,cjcjameson/gpdb,rvs/gpdb,royc1/gpdb,0x0FFF/gpdb,lisakowen/gpdb,kaknikhil/gpdb,CraigHarris/gpdb,ashwinstar/gpdb,kaknikhil/gpdb,edespino/gpdb,kaknikhil/gpdb,kaknikhil/gpdb,xinzweb/gpdb,lintzc/gpdb,zaksoup/gpdb,edespino/gpdb,0x0FFF/gpdb,yuanzhao/gpdb,xinzweb/gpdb,edespino/gpdb,xuegang/gpdb,xuegang/gpdb,yuanzhao/gpdb,ashwinstar/gpdb,cjcjameson/gpdb,Quikling/gpdb,lisakowen/gpdb,Chibin/gpdb,Chibin/gpdb,ahachete/gpdb,Quikling/gpdb,royc1/gpdb,royc1/gpdb,rvs/gpdb,lintzc/gpdb,yuanzhao/gpdb,0x0FFF/gpdb,lintzc/gpdb,janebeckman/gpdb,Quikling/gpdb,xinzweb/gpdb,edespino/gpdb,0x0FFF/gpdb,jmcatamney/gpdb,kaknikhil/gpdb,xuegang/gpdb,chrishajas/gpdb,royc1/gpdb,kaknikhil/gpdb,CraigHarris/gpdb,chrishajas/gpdb,50wu/gpdb,Quikling/gpdb,kaknikhil/gpdb,cjcjameson/gpdb,edespino/gpdb,lintzc/gpdb,kaknikhil/gpdb,jmcatamney/gpdb,50wu/gpdb,xinzweb/gpdb,royc1/gpdb,chrishajas/gpdb,janebeckman/gpdb,Chibin/gpdb,rvs/gpdb,Quikling/gpdb,rvs/gpdb,lintzc/gpdb,rvs/gpdb,edespino/gpdb,CraigHarris/gpdb,zaksoup/gpdb,CraigHarris/gpdb,zaksoup/gpdb,lintzc/gpdb,royc1/gpdb,0x0FFF/gpdb,greenplum-db/gpdb