archive_mode

A configuration parameter determining when completed WAL segments are sent to archive storage

archive_mode is a configuration parameter determining when completed WAL segments are sent to archive storage.

archive_mode was added in PostgreSQL 8.3.

Usage

archive_mode requires wal_level to be set to be a value higher than minimal.

archive_mode has three possible options:

When set to on or always, the command defined in archive_command will be executed to archive each WAL segment.

on means archive_command will only be applied on the primary.

always means archive_command will be applied regardless of whether the server is a primary or a standby.

Change history

Source code

In src/include/access/xlog.h:

 /* Archive modes */
typedef enum ArchiveMode
{
        ARCHIVE_MODE_OFF = 0,           /* disabled */
        ARCHIVE_MODE_ON,                        /* enabled while server is running normally */
        ARCHIVE_MODE_ALWAYS                     /* enabled always (even during recovery) */
} ArchiveMode;
extern int      XLogArchiveMode;

In src/backend/access/transam/xlog.c:

/* User-settable parameters */
...
int			XLogArchiveMode = ARCHIVE_MODE_OFF;

In src/backend/utils/misc/guc.c:

        {
                {"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
        },

In src/backend/postmaster/postmaster.c:

		if (XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level == WAL_LEVEL_MINIMAL)
		ereport(ERROR,
				(errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));

In src/backend/access/transam/xlogarchive.c:

	/*
	 * Create .done file forcibly to prevent the restored segment from being
	 * archived again later.
	 */
	if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
		XLogArchiveForceDone(xlogfname);
	else
		XLogArchiveNotify(xlogfname);

In src/backend/replication/walreceiver.c:

                        /*
                         * Create .done file forcibly to prevent the streamed segment from
                         * being archived later.
                         */
                        XLogFileName(xlogfname, recvFileTLI, recvSegNo, wal_segment_size);
                        if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
                                XLogArchiveForceDone(xlogfname);
                        else
                                XLogArchiveNotify(xlogfname);

Categories

Backup, GUC configuration item, Replication, Storage, WAL

See also

archive_command, pg_stat_archiver