*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 81,87 **** int			CheckPointSegments = 3;
  int			wal_keep_segments = 0;
  int			XLOGbuffers = -1;
  int			XLogArchiveTimeout = 0;
! bool		XLogArchiveMode = false;
  char	   *XLogArchiveCommand = NULL;
  bool		EnableHotStandby = false;
  bool		fullPageWrites = true;
--- 81,87 ----
  int			wal_keep_segments = 0;
  int			XLOGbuffers = -1;
  int			XLogArchiveTimeout = 0;
! int			XLogArchiveMode = ARCHIVE_MODE_OFF;
  char	   *XLogArchiveCommand = NULL;
  bool		EnableHotStandby = false;
  bool		fullPageWrites = true;
*** a/src/backend/postmaster/postmaster.c
--- b/src/backend/postmaster/postmaster.c
***************
*** 89,94 ****
--- 89,95 ----
  
  #include "access/transam.h"
  #include "access/xlog.h"
+ #include "access/xlogarchive.h"
  #include "bootstrap/bootstrap.h"
  #include "catalog/pg_control.h"
  #include "lib/ilist.h"
***************
*** 823,831 **** PostmasterMain(int argc, char *argv[])
  		write_stderr("%s: max_wal_senders must be less than max_connections\n", progname);
  		ExitPostmaster(1);
  	}
! 	if (XLogArchiveMode && wal_level == WAL_LEVEL_MINIMAL)
  		ereport(ERROR,
! 				(errmsg("WAL archival (archive_mode=on) requires wal_level \"archive\", \"hot_standby\", or \"logical\"")));
  	if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
  		ereport(ERROR,
  				(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"archive\", \"hot_standby\", or \"logical\"")));
--- 824,832 ----
  		write_stderr("%s: max_wal_senders must be less than max_connections\n", progname);
  		ExitPostmaster(1);
  	}
! 	if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
  		ereport(ERROR,
! 				(errmsg("WAL archival (archive_mode=on/always) requires wal_level \"archive\", \"hot_standby\", or \"logical\"")));
  	if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
  		ereport(ERROR,
  				(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"archive\", \"hot_standby\", or \"logical\"")));
***************
*** 1617,1624 **** ServerLoop(void)
  				start_autovac_launcher = false; /* signal processed */
  		}
  
! 		/* If we have lost the archiver, try to start a new one */
! 		if (XLogArchivingActive() && PgArchPID == 0 && pmState == PM_RUN)
  			PgArchPID = pgarch_start();
  
  		/* If we have lost the stats collector, try to start a new one */
--- 1618,1634 ----
  				start_autovac_launcher = false; /* signal processed */
  		}
  
! 		/*
! 		 * If we have lost the archiver, try to start a new one.
! 		 *
! 		 * If WAL archiving is enabled always, we try to start a new archiver
! 		 * even during recovery.
! 		 */
! 		if (PgArchPID == 0 &&
! 			((XLogArchivingActive() && pmState == PM_RUN) ||
! 			 (XLogArchivingActiveAlways() &&
! 			  (pmState == PM_RECOVERY ||
! 			   pmState == PM_HOT_STANDBY))))
  			PgArchPID = pgarch_start();
  
  		/* If we have lost the stats collector, try to start a new one */
***************
*** 4780,4785 **** sigusr1_handler(SIGNAL_ARGS)
--- 4790,4803 ----
  		Assert(BgWriterPID == 0);
  		BgWriterPID = StartBackgroundWriter();
  
+ 		/*
+ 		 * Try to start an archiver even during recovery if archiving is
+ 		 * enabled always.
+ 		 */
+ 		Assert(PgArchPID == 0);
+ 		if (XLogArchivingActiveAlways())
+ 			PgArchPID = pgarch_start();
+ 
  		pmState = PM_RECOVERY;
  	}
  	if (CheckPostmasterSignal(PMSIGNAL_BEGIN_HOT_STANDBY) &&
*** a/src/backend/replication/walreceiver.c
--- b/src/backend/replication/walreceiver.c
***************
*** 547,557 **** WalReceiverMain(void)
  								XLogFileNameP(recvFileTLI, recvSegNo))));
  
  			/*
! 			 * Create .done file forcibly to prevent the streamed segment from
! 			 * being archived later.
  			 */
  			XLogFileName(xlogfname, recvFileTLI, recvSegNo);
! 			XLogArchiveForceDone(xlogfname);
  		}
  		recvFile = -1;
  
--- 547,563 ----
  								XLogFileNameP(recvFileTLI, recvSegNo))));
  
  			/*
! 			 * Notify the archiver that the WAL segment is ready to
! 			 * copy to archival storage even during recovery
! 			 * if WAL archiving is enabled always. Otherwise,
! 			 * create .done file forcibly to prevent the streamed segment
! 			 * from being archived later.
  			 */
  			XLogFileName(xlogfname, recvFileTLI, recvSegNo);
! 			if (XLogArchivingActiveAlways())
! 				XLogArchiveNotify(xlogfname);
! 			else
! 				XLogArchiveForceDone(xlogfname);
  		}
  		recvFile = -1;
  
***************
*** 904,914 **** XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
  									XLogFileNameP(recvFileTLI, recvSegNo))));
  
  				/*
! 				 * Create .done file forcibly to prevent the streamed segment
  				 * from being archived later.
  				 */
  				XLogFileName(xlogfname, recvFileTLI, recvSegNo);
! 				XLogArchiveForceDone(xlogfname);
  			}
  			recvFile = -1;
  
--- 910,926 ----
  									XLogFileNameP(recvFileTLI, recvSegNo))));
  
  				/*
! 				 * Notify the archiver that the WAL segment is ready to
! 				 * copy to archival storage even during recovery
! 				 * if WAL archiving is enabled always. Otherwise,
! 				 * create .done file forcibly to prevent the streamed segment
  				 * from being archived later.
  				 */
  				XLogFileName(xlogfname, recvFileTLI, recvSegNo);
! 				if (XLogArchivingActiveAlways())
! 					XLogArchiveNotify(xlogfname);
! 				else
! 					XLogArchiveForceDone(xlogfname);
  			}
  			recvFile = -1;
  
*** a/src/backend/utils/misc/guc.c
--- b/src/backend/utils/misc/guc.c
***************
*** 401,406 **** static const struct config_enum_entry huge_pages_options[] = {
--- 401,423 ----
  };
  
  /*
+  * Although only "on", "off", and "always" are documented,
+  * we accept all the likely variants of "on" and "off".
+  */
+ static const struct config_enum_entry archive_mode_options[] = {
+ 	{"always", ARCHIVE_MODE_ALWAYS, false},
+ 	{"on", ARCHIVE_MODE_ON, false},
+ 	{"off", ARCHIVE_MODE_OFF, false},
+ 	{"true", ARCHIVE_MODE_ON, true},
+ 	{"false", ARCHIVE_MODE_OFF, true},
+ 	{"yes", ARCHIVE_MODE_ON, true},
+ 	{"no", ARCHIVE_MODE_OFF, true},
+ 	{"1", ARCHIVE_MODE_ON, true},
+ 	{"0", ARCHIVE_MODE_OFF, true},
+ 	{NULL, 0, false}
+ };
+ 
+ /*
   * Options for enum values stored in other modules
   */
  extern const struct config_enum_entry wal_level_options[];
***************
*** 1429,1444 **** static struct config_bool ConfigureNamesBool[] =
  	},
  
  	{
- 		{"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
- 			gettext_noop("Allows archiving of WAL files using archive_command."),
- 			NULL
- 		},
- 		&XLogArchiveMode,
- 		false,
- 		NULL, NULL, NULL
- 	},
- 
- 	{
  		{"hot_standby", PGC_POSTMASTER, REPLICATION_STANDBY,
  			gettext_noop("Allows connections and queries during recovery."),
  			NULL
--- 1446,1451 ----
***************
*** 3421,3426 **** static struct config_enum ConfigureNamesEnum[] =
--- 3428,3443 ----
  	},
  
  	{
+ 		{"archive_mode", PGC_POSTMASTER, WAL_ARCHIVING,
+ 			gettext_noop("Allows archiving of WAL files using archive command."),
+ 			NULL
+ 		},
+ 		&XLogArchiveMode,
+ 		ARCHIVE_MODE_OFF, archive_mode_options,
+ 		NULL, NULL, NULL
+ 	},
+ 
+ 	{
  		{"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
  			gettext_noop("Enables logging of recovery-related debugging information."),
  			gettext_noop("Each level includes all the levels that follow it. The later"
*** a/src/backend/utils/misc/postgresql.conf.sample
--- b/src/backend/utils/misc/postgresql.conf.sample
***************
*** 202,208 ****
  
  # - Archiving -
  
! #archive_mode = off		# allows archiving to be done
  				# (change requires restart)
  #archive_command = ''		# command to use to archive a logfile segment
  				# placeholders: %p = path of file to archive
--- 202,208 ----
  
  # - Archiving -
  
! #archive_mode = off		# allows archiving to be done; off, on, or always
  				# (change requires restart)
  #archive_command = ''		# command to use to archive a logfile segment
  				# placeholders: %p = path of file to archive
*** a/src/include/access/xlog.h
--- b/src/include/access/xlog.h
***************
*** 12,17 ****
--- 12,18 ----
  #define XLOG_H
  
  #include "access/rmgr.h"
+ #include "access/xlogarchive.h"
  #include "access/xlogdefs.h"
  #include "datatype/timestamp.h"
  #include "lib/stringinfo.h"
***************
*** 188,194 **** extern int	CheckPointSegments;
  extern int	wal_keep_segments;
  extern int	XLOGbuffers;
  extern int	XLogArchiveTimeout;
! extern bool XLogArchiveMode;
  extern char *XLogArchiveCommand;
  extern bool EnableHotStandby;
  extern bool fullPageWrites;
--- 189,195 ----
  extern int	wal_keep_segments;
  extern int	XLOGbuffers;
  extern int	XLogArchiveTimeout;
! extern int	XLogArchiveMode;
  extern char *XLogArchiveCommand;
  extern bool EnableHotStandby;
  extern bool fullPageWrites;
***************
*** 206,212 **** typedef enum WalLevel
  } WalLevel;
  extern int	wal_level;
  
! #define XLogArchivingActive()	(XLogArchiveMode && wal_level >= WAL_LEVEL_ARCHIVE)
  #define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
  
  /*
--- 207,216 ----
  } WalLevel;
  extern int	wal_level;
  
! #define XLogArchivingActive()	(XLogArchiveMode > ARCHIVE_MODE_OFF \
! 								 && wal_level >= WAL_LEVEL_ARCHIVE)
! #define XLogArchivingActiveAlways()	(XLogArchiveMode == ARCHIVE_MODE_ALWAYS \
! 								 && wal_level >= WAL_LEVEL_ARCHIVE)
  #define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
  
  /*
*** /dev/null
--- b/src/include/access/xlogarchive.h
***************
*** 0 ****
--- 1,21 ----
+ /*
+  * xlogarchive.h
+  *
+  * Functions for archiving WAL files and restoring from the archive.
+  *
+  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
+  * Portions Copyright (c) 1994, Regents of the University of California
+  *
+  * src/include/access/xlogarchive.h
+  */
+ #ifndef XLOG_ARCHIVE_H
+ #define XLOG_ARCHIVE_H
+ 
+ typedef enum
+ {
+ 	ARCHIVE_MODE_OFF,	/* disabled*/
+ 	ARCHIVE_MODE_ON,	/*enabled while server is running normally */
+ 	ARCHIVE_MODE_ALWAYS	/* enabled always (even during recovery) */
+ }	ArchiveModeLevel;
+ 
+ #endif   /* XLOG_ARCHIVE_H */
