2004-07-22 00:31:26 +02:00
|
|
|
/*
|
|
|
|
* xlog_internal.h
|
|
|
|
*
|
|
|
|
* PostgreSQL transaction log internal declarations
|
|
|
|
*
|
|
|
|
* NOTE: this file is intended to contain declarations useful for
|
|
|
|
* manipulating the XLOG files directly, but it is not supposed to be
|
2005-06-06 19:01:25 +02:00
|
|
|
* needed by rmgr routines (redo support for individual record types).
|
2014-11-06 12:52:08 +01:00
|
|
|
* So the XLogRecord typedef and associated stuff appear in xlogrecord.h.
|
2004-07-22 00:31:26 +02:00
|
|
|
*
|
2012-12-13 13:59:13 +01:00
|
|
|
* Note: This file must be includable in both frontend and backend contexts,
|
2017-02-09 22:23:46 +01:00
|
|
|
* to allow stand-alone tools like pg_receivewal to deal with WAL files.
|
2012-12-13 13:59:13 +01:00
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
2004-07-22 00:31:26 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/access/xlog_internal.h
|
2004-07-22 00:31:26 +02:00
|
|
|
*/
|
|
|
|
#ifndef XLOG_INTERNAL_H
|
|
|
|
#define XLOG_INTERNAL_H
|
|
|
|
|
2012-12-13 13:59:13 +01:00
|
|
|
#include "access/xlogdefs.h"
|
Revamp the WAL record format.
Each WAL record now carries information about the modified relation and
block(s) in a standardized format. That makes it easier to write tools that
need that information, like pg_rewind, prefetching the blocks to speed up
recovery, etc.
There's a whole new API for building WAL records, replacing the XLogRecData
chains used previously. The new API consists of XLogRegister* functions,
which are called for each buffer and chunk of data that is added to the
record. The new API also gives more control over when a full-page image is
written, by passing flags to the XLogRegisterBuffer function.
This also simplifies the XLogReadBufferForRedo() calls. The function can dig
the relation and block number from the WAL record, so they no longer need to
be passed as arguments.
For the convenience of redo routines, XLogReader now disects each WAL record
after reading it, copying the main data part and the per-block data into
MAXALIGNed buffers. The data chunks are not aligned within the WAL record,
but the redo routines can assume that the pointers returned by XLogRecGet*
functions are. Redo routines are now passed the XLogReaderState, which
contains the record in the already-disected format, instead of the plain
XLogRecord.
The new record format also makes the fixed size XLogRecord header smaller,
by removing the xl_len field. The length of the "main data" portion is now
stored at the end of the WAL record, and there's a separate header after
XLogRecord for it. The alignment padding at the end of XLogRecord is also
removed. This compansates for the fact that the new format would otherwise
be more bulky than the old format.
Reviewed by Andres Freund, Amit Kapila, Michael Paquier, Alvaro Herrera,
Fujii Masao.
2014-11-20 16:56:26 +01:00
|
|
|
#include "access/xlogreader.h"
|
2012-12-13 13:59:13 +01:00
|
|
|
#include "datatype/timestamp.h"
|
|
|
|
#include "lib/stringinfo.h"
|
2011-09-09 19:23:41 +02:00
|
|
|
#include "pgtime.h"
|
2011-09-04 07:13:16 +02:00
|
|
|
#include "storage/block.h"
|
|
|
|
#include "storage/relfilenode.h"
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each page of XLOG file has a header like this:
|
|
|
|
*/
|
2017-02-08 21:45:30 +01:00
|
|
|
#define XLOG_PAGE_MAGIC 0xD095 /* can be used as WAL version indicator */
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
typedef struct XLogPageHeaderData
|
|
|
|
{
|
|
|
|
uint16 xlp_magic; /* magic value for correctness checks */
|
|
|
|
uint16 xlp_info; /* flag bits, see below */
|
|
|
|
TimeLineID xlp_tli; /* TimeLineID of first record on page */
|
|
|
|
XLogRecPtr xlp_pageaddr; /* XLOG address of this page */
|
2012-06-24 17:15:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When there is not enough space on current page for whole record, we
|
|
|
|
* continue on the next page. xlp_rem_len is the number of bytes
|
2012-06-24 17:27:10 +02:00
|
|
|
* remaining from a previous page.
|
2012-06-24 17:15:00 +02:00
|
|
|
*
|
|
|
|
* Note that xl_rem_len includes backup-block data; that is, it tracks
|
|
|
|
* xl_tot_len not xl_len in the initial header. Also note that the
|
|
|
|
* continuation data isn't necessarily aligned.
|
|
|
|
*/
|
|
|
|
uint32 xlp_rem_len; /* total len of remaining data for record */
|
2004-07-22 00:31:26 +02:00
|
|
|
} XLogPageHeaderData;
|
|
|
|
|
|
|
|
#define SizeOfXLogShortPHD MAXALIGN(sizeof(XLogPageHeaderData))
|
|
|
|
|
|
|
|
typedef XLogPageHeaderData *XLogPageHeader;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the XLP_LONG_HEADER flag is set, we store additional fields in the
|
|
|
|
* page header. (This is ordinarily done just in the first page of an
|
2004-08-29 07:07:03 +02:00
|
|
|
* XLOG file.) The additional fields serve to identify the file accurately.
|
2004-07-22 00:31:26 +02:00
|
|
|
*/
|
|
|
|
typedef struct XLogLongPageHeaderData
|
|
|
|
{
|
|
|
|
XLogPageHeaderData std; /* standard header fields */
|
|
|
|
uint64 xlp_sysid; /* system identifier from pg_control */
|
|
|
|
uint32 xlp_seg_size; /* just as a cross-check */
|
2006-04-05 05:34:05 +02:00
|
|
|
uint32 xlp_xlog_blcksz; /* just as a cross-check */
|
2004-07-22 00:31:26 +02:00
|
|
|
} XLogLongPageHeaderData;
|
|
|
|
|
|
|
|
#define SizeOfXLogLongPHD MAXALIGN(sizeof(XLogLongPageHeaderData))
|
|
|
|
|
|
|
|
typedef XLogLongPageHeaderData *XLogLongPageHeader;
|
|
|
|
|
|
|
|
/* When record crosses page boundary, set this flag in new page's header */
|
|
|
|
#define XLP_FIRST_IS_CONTRECORD 0x0001
|
|
|
|
/* This flag indicates a "long" page header */
|
|
|
|
#define XLP_LONG_HEADER 0x0002
|
2011-12-12 22:22:14 +01:00
|
|
|
/* This flag indicates backup blocks starting in this page are optional */
|
|
|
|
#define XLP_BKP_REMOVABLE 0x0004
|
2004-07-22 00:31:26 +02:00
|
|
|
/* All defined flag bits in xlp_info (used for validity checking of header) */
|
2011-12-12 22:22:14 +01:00
|
|
|
#define XLP_ALL_FLAGS 0x0007
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
#define XLogPageHeaderSize(hdr) \
|
|
|
|
(((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
|
|
|
|
|
|
|
|
/*
|
2012-06-24 17:06:38 +02:00
|
|
|
* The XLOG is split into WAL segments (physical files) of the size indicated
|
|
|
|
* by XLOG_SEG_SIZE.
|
2004-07-22 00:31:26 +02:00
|
|
|
*/
|
|
|
|
#define XLogSegSize ((uint32) XLOG_SEG_SIZE)
|
2012-06-24 20:41:23 +02:00
|
|
|
#define XLogSegmentsPerXLogId (UINT64CONST(0x100000000) / XLOG_SEG_SIZE)
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2012-06-24 17:06:38 +02:00
|
|
|
#define XLogSegNoOffsetToRecPtr(segno, offset, dest) \
|
2012-06-24 17:51:37 +02:00
|
|
|
(dest) = (segno) * XLOG_SEG_SIZE + (offset)
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute ID and segment from an XLogRecPtr.
|
|
|
|
*
|
|
|
|
* For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
|
2014-05-06 18:12:18 +02:00
|
|
|
* a boundary byte is taken to be in the previous segment. This is suitable
|
2004-07-22 00:31:26 +02:00
|
|
|
* for deciding which segment to write given a pointer to a record end,
|
2012-06-24 17:51:37 +02:00
|
|
|
* for example.
|
2004-07-22 00:31:26 +02:00
|
|
|
*/
|
2013-05-29 22:58:43 +02:00
|
|
|
#define XLByteToSeg(xlrp, logSegNo) \
|
2012-06-24 17:51:37 +02:00
|
|
|
logSegNo = (xlrp) / XLogSegSize
|
2012-06-24 17:06:38 +02:00
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
#define XLByteToPrevSeg(xlrp, logSegNo) \
|
2012-06-24 17:51:37 +02:00
|
|
|
logSegNo = ((xlrp) - 1) / XLogSegSize
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Is an XLogRecPtr within a particular XLOG segment?
|
|
|
|
*
|
|
|
|
* For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
|
|
|
|
* a boundary byte is taken to be in the previous segment.
|
|
|
|
*/
|
2013-05-29 22:58:43 +02:00
|
|
|
#define XLByteInSeg(xlrp, logSegNo) \
|
2012-06-24 17:51:37 +02:00
|
|
|
(((xlrp) / XLogSegSize) == (logSegNo))
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
#define XLByteInPrevSeg(xlrp, logSegNo) \
|
2012-06-24 17:51:37 +02:00
|
|
|
((((xlrp) - 1) / XLogSegSize) == (logSegNo))
|
|
|
|
|
|
|
|
/* Check if an XLogRecPtr value is in a plausible range */
|
|
|
|
#define XRecOffIsValid(xlrp) \
|
2012-06-25 18:14:43 +02:00
|
|
|
((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2005-07-04 06:51:52 +02:00
|
|
|
/*
|
|
|
|
* The XLog directory and control file (relative to $PGDATA)
|
|
|
|
*/
|
2016-10-20 17:24:37 +02:00
|
|
|
#define XLOGDIR "pg_wal"
|
2005-07-04 06:51:52 +02:00
|
|
|
#define XLOG_CONTROL_FILE "global/pg_control"
|
|
|
|
|
2004-07-22 00:31:26 +02:00
|
|
|
/*
|
|
|
|
* These macros encapsulate knowledge about the exact layout of XLog file
|
|
|
|
* names, timeline history file names, and archive-status file names.
|
|
|
|
*/
|
2004-08-03 22:32:36 +02:00
|
|
|
#define MAXFNAMELEN 64
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2015-07-02 03:35:38 +02:00
|
|
|
/* Length of XLog file name */
|
2016-06-10 00:02:36 +02:00
|
|
|
#define XLOG_FNAME_LEN 24
|
2015-07-02 03:35:38 +02:00
|
|
|
|
2012-06-24 17:06:38 +02:00
|
|
|
#define XLogFileName(fname, tli, logSegNo) \
|
|
|
|
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
|
|
|
|
(uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
|
|
|
|
(uint32) ((logSegNo) % XLogSegmentsPerXLogId))
|
|
|
|
|
2015-07-02 03:35:38 +02:00
|
|
|
#define XLogFileNameById(fname, tli, log, seg) \
|
|
|
|
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
|
|
|
|
|
2015-05-08 20:58:57 +02:00
|
|
|
#define IsXLogFileName(fname) \
|
2015-07-02 03:35:38 +02:00
|
|
|
(strlen(fname) == XLOG_FNAME_LEN && \
|
|
|
|
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN)
|
2015-05-08 20:58:57 +02:00
|
|
|
|
At promotion, archive last segment from old timeline with .partial suffix.
Previously, we would archive the possible-incomplete WAL segment with its
normal filename, but that causes trouble if the server owning that timeline
is still running, and tries to archive the same segment later. It's not nice
for the standby to trip up the master's archival like that. And it's pretty
confusing, anyway, to have an incomplete segment in the archive that's
indistinguishable from a normal, complete segment.
To avoid such confusion, add a .partial suffix to the file. Or to be more
precise, make a copy of the old segment under the .partial suffix, and
archive that instead of the original file. pg_receivexlog also uses the
.partial suffix for the same purpose, to tell apart incompletely streamed
files from complete ones.
There is no automatic mechanism to use the .partial files at recovery, so
they will go unused, unless the administrator manually copies to them to
the pg_xlog directory (and removes the .partial suffix). Recovery won't
normally need the WAL - when recovering to the new timeline, it will find
the same WAL on the first segment on the new timeline instead - but it
nevertheless feels better to archive the file with the .partial suffix, for
debugging purposes if nothing else.
2015-05-08 20:59:01 +02:00
|
|
|
/*
|
2017-02-09 22:23:46 +01:00
|
|
|
* XLOG segment with .partial suffix. Used by pg_receivewal and at end of
|
At promotion, archive last segment from old timeline with .partial suffix.
Previously, we would archive the possible-incomplete WAL segment with its
normal filename, but that causes trouble if the server owning that timeline
is still running, and tries to archive the same segment later. It's not nice
for the standby to trip up the master's archival like that. And it's pretty
confusing, anyway, to have an incomplete segment in the archive that's
indistinguishable from a normal, complete segment.
To avoid such confusion, add a .partial suffix to the file. Or to be more
precise, make a copy of the old segment under the .partial suffix, and
archive that instead of the original file. pg_receivexlog also uses the
.partial suffix for the same purpose, to tell apart incompletely streamed
files from complete ones.
There is no automatic mechanism to use the .partial files at recovery, so
they will go unused, unless the administrator manually copies to them to
the pg_xlog directory (and removes the .partial suffix). Recovery won't
normally need the WAL - when recovering to the new timeline, it will find
the same WAL on the first segment on the new timeline instead - but it
nevertheless feels better to archive the file with the .partial suffix, for
debugging purposes if nothing else.
2015-05-08 20:59:01 +02:00
|
|
|
* archive recovery, when we want to archive a WAL segment but it might not
|
|
|
|
* be complete yet.
|
|
|
|
*/
|
2015-05-08 20:58:57 +02:00
|
|
|
#define IsPartialXLogFileName(fname) \
|
2015-07-02 03:35:38 +02:00
|
|
|
(strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \
|
|
|
|
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
|
|
|
|
strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
|
2015-05-08 20:58:57 +02:00
|
|
|
|
2012-06-24 17:06:38 +02:00
|
|
|
#define XLogFromFileName(fname, tli, logSegNo) \
|
|
|
|
do { \
|
|
|
|
uint32 log; \
|
|
|
|
uint32 seg; \
|
2013-05-29 22:58:43 +02:00
|
|
|
sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
|
|
|
|
*logSegNo = (uint64) log * XLogSegmentsPerXLogId + seg; \
|
2012-06-24 17:06:38 +02:00
|
|
|
} while (0)
|
2010-04-12 12:40:43 +02:00
|
|
|
|
2012-06-24 17:06:38 +02:00
|
|
|
#define XLogFilePath(path, tli, logSegNo) \
|
|
|
|
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
|
|
|
|
(uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
|
|
|
|
(uint32) ((logSegNo) % XLogSegmentsPerXLogId))
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
#define TLHistoryFileName(fname, tli) \
|
|
|
|
snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
|
|
|
|
|
2015-05-08 20:58:57 +02:00
|
|
|
#define IsTLHistoryFileName(fname) \
|
|
|
|
(strlen(fname) == 8 + strlen(".history") && \
|
|
|
|
strspn(fname, "0123456789ABCDEF") == 8 && \
|
|
|
|
strcmp((fname) + 8, ".history") == 0)
|
|
|
|
|
2004-07-22 00:31:26 +02:00
|
|
|
#define TLHistoryFilePath(path, tli) \
|
2005-07-04 06:51:52 +02:00
|
|
|
snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
|
2004-07-22 00:31:26 +02:00
|
|
|
|
|
|
|
#define StatusFilePath(path, xlog, suffix) \
|
2005-07-04 06:51:52 +02:00
|
|
|
snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2012-06-24 17:06:38 +02:00
|
|
|
#define BackupHistoryFileName(fname, tli, logSegNo, offset) \
|
|
|
|
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
|
|
|
|
(uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
|
|
|
|
(uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
|
2004-08-03 22:32:36 +02:00
|
|
|
|
2015-05-08 20:58:57 +02:00
|
|
|
#define IsBackupHistoryFileName(fname) \
|
2015-07-02 03:35:38 +02:00
|
|
|
(strlen(fname) > XLOG_FNAME_LEN && \
|
|
|
|
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
|
2015-05-08 20:58:57 +02:00
|
|
|
strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
|
|
|
|
|
2012-06-24 17:06:38 +02:00
|
|
|
#define BackupHistoryFilePath(path, tli, logSegNo, offset) \
|
|
|
|
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
|
|
|
|
(uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
|
|
|
|
(uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2012-11-28 16:35:01 +01:00
|
|
|
/*
|
|
|
|
* Information logged when we detect a change in one of the parameters
|
|
|
|
* important for Hot Standby.
|
|
|
|
*/
|
|
|
|
typedef struct xl_parameter_change
|
|
|
|
{
|
|
|
|
int MaxConnections;
|
Add new GUC, max_worker_processes, limiting number of bgworkers.
In 9.3, there's no particular limit on the number of bgworkers;
instead, we just count up the number that are actually registered,
and use that to set MaxBackends. However, that approach causes
problems for Hot Standby, which needs both MaxBackends and the
size of the lock table to be the same on the standby as on the
master, yet it may not be desirable to run the same bgworkers in
both places. 9.3 handles that by failing to notice the problem,
which will probably work fine in nearly all cases anyway, but is
not theoretically sound.
A further problem with simply counting the number of registered
workers is that new workers can't be registered without a
postmaster restart. This is inconvenient for administrators,
since bouncing the postmaster causes an interruption of service.
Moreover, there are a number of applications for background
processes where, by necessity, the background process must be
started on the fly (e.g. parallel query). While this patch
doesn't actually make it possible to register new background
workers after startup time, it's a necessary prerequisite.
Patch by me. Review by Michael Paquier.
2013-07-04 17:24:24 +02:00
|
|
|
int max_worker_processes;
|
2012-11-28 16:35:01 +01:00
|
|
|
int max_prepared_xacts;
|
|
|
|
int max_locks_per_xact;
|
|
|
|
int wal_level;
|
2013-12-20 19:33:16 +01:00
|
|
|
bool wal_log_hints;
|
Keep track of transaction commit timestamps
Transactions can now set their commit timestamp directly as they commit,
or an external transaction commit timestamp can be fed from an outside
system using the new function TransactionTreeSetCommitTsData(). This
data is crash-safe, and truncated at Xid freeze point, same as pg_clog.
This module is disabled by default because it causes a performance hit,
but can be enabled in postgresql.conf requiring only a server restart.
A new test in src/test/modules is included.
Catalog version bumped due to the new subdirectory within PGDATA and a
couple of new SQL functions.
Authors: Álvaro Herrera and Petr Jelínek
Reviewed to varying degrees by Michael Paquier, Andres Freund, Robert
Haas, Amit Kapila, Fujii Masao, Jaime Casanova, Simon Riggs, Steven
Singer, Peter Eisentraut
2014-12-03 15:53:02 +01:00
|
|
|
bool track_commit_timestamp;
|
2012-11-28 16:35:01 +01:00
|
|
|
} xl_parameter_change;
|
|
|
|
|
|
|
|
/* logs restore point */
|
|
|
|
typedef struct xl_restore_point
|
|
|
|
{
|
|
|
|
TimestampTz rp_time;
|
|
|
|
char rp_name[MAXFNAMELEN];
|
|
|
|
} xl_restore_point;
|
|
|
|
|
2013-01-29 01:06:15 +01:00
|
|
|
/* End of recovery mark, when we don't do an END_OF_RECOVERY checkpoint */
|
|
|
|
typedef struct xl_end_of_recovery
|
|
|
|
{
|
|
|
|
TimestampTz end_time;
|
2013-02-11 17:13:09 +01:00
|
|
|
TimeLineID ThisTimeLineID; /* new TLI */
|
|
|
|
TimeLineID PrevTimeLineID; /* previous TLI we forked off from */
|
2013-01-29 01:06:15 +01:00
|
|
|
} xl_end_of_recovery;
|
2004-07-22 00:31:26 +02:00
|
|
|
|
Revamp the WAL record format.
Each WAL record now carries information about the modified relation and
block(s) in a standardized format. That makes it easier to write tools that
need that information, like pg_rewind, prefetching the blocks to speed up
recovery, etc.
There's a whole new API for building WAL records, replacing the XLogRecData
chains used previously. The new API consists of XLogRegister* functions,
which are called for each buffer and chunk of data that is added to the
record. The new API also gives more control over when a full-page image is
written, by passing flags to the XLogRegisterBuffer function.
This also simplifies the XLogReadBufferForRedo() calls. The function can dig
the relation and block number from the WAL record, so they no longer need to
be passed as arguments.
For the convenience of redo routines, XLogReader now disects each WAL record
after reading it, copying the main data part and the per-block data into
MAXALIGNed buffers. The data chunks are not aligned within the WAL record,
but the redo routines can assume that the pointers returned by XLogRecGet*
functions are. Redo routines are now passed the XLogReaderState, which
contains the record in the already-disected format, instead of the plain
XLogRecord.
The new record format also makes the fixed size XLogRecord header smaller,
by removing the xl_len field. The length of the "main data" portion is now
stored at the end of the WAL record, and there's a separate header after
XLogRecord for it. The alignment padding at the end of XLogRecord is also
removed. This compansates for the fact that the new format would otherwise
be more bulky than the old format.
Reviewed by Andres Freund, Amit Kapila, Michael Paquier, Alvaro Herrera,
Fujii Masao.
2014-11-20 16:56:26 +01:00
|
|
|
/*
|
|
|
|
* The functions in xloginsert.c construct a chain of XLogRecData structs
|
|
|
|
* to represent the final WAL record.
|
|
|
|
*/
|
|
|
|
typedef struct XLogRecData
|
|
|
|
{
|
|
|
|
struct XLogRecData *next; /* next struct in chain, or NULL */
|
|
|
|
char *data; /* start of rmgr data to include */
|
|
|
|
uint32 len; /* length of rmgr data to include */
|
|
|
|
} XLogRecData;
|
|
|
|
|
2014-11-25 21:13:30 +01:00
|
|
|
/*
|
|
|
|
* Recovery target action.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
RECOVERY_TARGET_ACTION_PAUSE,
|
|
|
|
RECOVERY_TARGET_ACTION_PROMOTE,
|
2016-04-15 03:54:06 +02:00
|
|
|
RECOVERY_TARGET_ACTION_SHUTDOWN
|
2014-11-25 21:13:30 +01:00
|
|
|
} RecoveryTargetAction;
|
|
|
|
|
2004-07-22 00:31:26 +02:00
|
|
|
/*
|
|
|
|
* Method table for resource managers.
|
|
|
|
*
|
2013-02-05 21:21:29 +01:00
|
|
|
* This struct must be kept in sync with the PG_RMGR definition in
|
|
|
|
* rmgr.c.
|
|
|
|
*
|
2014-09-19 15:17:12 +02:00
|
|
|
* rm_identify must return a name for the record based on xl_info (without
|
|
|
|
* reference to the rmid). For example, XLOG_BTREE_VACUUM would be named
|
|
|
|
* "VACUUM". rm_desc can then be called to obtain additional detail for the
|
|
|
|
* record, if available (e.g. the last block).
|
|
|
|
*
|
2017-02-08 21:45:30 +01:00
|
|
|
* rm_mask takes as input a page modified by the resource manager and masks
|
|
|
|
* out bits that shouldn't be flagged by wal_consistency_checking.
|
|
|
|
*
|
2013-02-05 21:21:29 +01:00
|
|
|
* RmgrTable[] is indexed by RmgrId values (see rmgrlist.h).
|
2004-07-22 00:31:26 +02:00
|
|
|
*/
|
|
|
|
typedef struct RmgrData
|
|
|
|
{
|
|
|
|
const char *rm_name;
|
Revamp the WAL record format.
Each WAL record now carries information about the modified relation and
block(s) in a standardized format. That makes it easier to write tools that
need that information, like pg_rewind, prefetching the blocks to speed up
recovery, etc.
There's a whole new API for building WAL records, replacing the XLogRecData
chains used previously. The new API consists of XLogRegister* functions,
which are called for each buffer and chunk of data that is added to the
record. The new API also gives more control over when a full-page image is
written, by passing flags to the XLogRegisterBuffer function.
This also simplifies the XLogReadBufferForRedo() calls. The function can dig
the relation and block number from the WAL record, so they no longer need to
be passed as arguments.
For the convenience of redo routines, XLogReader now disects each WAL record
after reading it, copying the main data part and the per-block data into
MAXALIGNed buffers. The data chunks are not aligned within the WAL record,
but the redo routines can assume that the pointers returned by XLogRecGet*
functions are. Redo routines are now passed the XLogReaderState, which
contains the record in the already-disected format, instead of the plain
XLogRecord.
The new record format also makes the fixed size XLogRecord header smaller,
by removing the xl_len field. The length of the "main data" portion is now
stored at the end of the WAL record, and there's a separate header after
XLogRecord for it. The alignment padding at the end of XLogRecord is also
removed. This compansates for the fact that the new format would otherwise
be more bulky than the old format.
Reviewed by Andres Freund, Amit Kapila, Michael Paquier, Alvaro Herrera,
Fujii Masao.
2014-11-20 16:56:26 +01:00
|
|
|
void (*rm_redo) (XLogReaderState *record);
|
|
|
|
void (*rm_desc) (StringInfo buf, XLogReaderState *record);
|
2014-09-19 15:17:12 +02:00
|
|
|
const char *(*rm_identify) (uint8 info);
|
2004-07-22 00:31:26 +02:00
|
|
|
void (*rm_startup) (void);
|
|
|
|
void (*rm_cleanup) (void);
|
2017-02-08 21:45:30 +01:00
|
|
|
void (*rm_mask) (char *pagedata, BlockNumber blkno);
|
2004-07-22 00:31:26 +02:00
|
|
|
} RmgrData;
|
|
|
|
|
|
|
|
extern const RmgrData RmgrTable[];
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
/*
|
2011-11-01 18:14:47 +01:00
|
|
|
* Exported to support xlog switching from checkpointer
|
2006-08-18 01:04:10 +02:00
|
|
|
*/
|
Skip checkpoints, archiving on idle systems.
Some background activity (like checkpoints, archive timeout, standby
snapshots) is not supposed to happen on an idle system. Unfortunately
so far it was not easy to determine when a system is idle, which
defeated some of the attempts to avoid redundant activity on an idle
system.
To make that easier, allow to make individual WAL insertions as not
being "important". By checking whether any important activity happened
since the last time an activity was performed, it now is easy to check
whether some action needs to be repeated.
Use the new facility for checkpoints, archive timeout and standby
snapshots.
The lack of a facility causes some issues in older releases, but in my
opinion the consequences (superflous checkpoints / archived segments)
aren't grave enough to warrant backpatching.
Author: Michael Paquier, editorialized by Andres Freund
Reviewed-By: Andres Freund, David Steele, Amit Kapila, Kyotaro HORIGUCHI
Bug: #13685
Discussion:
https://www.postgresql.org/message-id/20151016203031.3019.72930@wrigleys.postgresql.org
https://www.postgresql.org/message-id/CAB7nPqQcPqxEM3S735Bd2RzApNqSNJVietAC=6kfkYv_45dKwA@mail.gmail.com
Backpatch: -
2016-12-22 20:31:50 +01:00
|
|
|
extern pg_time_t GetLastSegSwitchData(XLogRecPtr *lastSwitchLSN);
|
2017-03-14 17:57:10 +01:00
|
|
|
extern XLogRecPtr RequestXLogSwitch(bool mark_unimportant);
|
2006-08-18 01:04:10 +02:00
|
|
|
|
2012-10-02 12:37:19 +02:00
|
|
|
extern void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli);
|
|
|
|
|
|
|
|
/*
|
2014-05-06 18:12:18 +02:00
|
|
|
* Exported for the functions in timeline.c and xlogarchive.c. Only valid
|
2012-10-02 12:37:19 +02:00
|
|
|
* in the startup process.
|
|
|
|
*/
|
2013-03-07 11:18:41 +01:00
|
|
|
extern bool ArchiveRecoveryRequested;
|
2012-10-02 12:37:19 +02:00
|
|
|
extern bool InArchiveRecovery;
|
|
|
|
extern bool StandbyMode;
|
|
|
|
extern char *recoveryRestoreCommand;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes for functions in xlogarchive.c
|
|
|
|
*/
|
|
|
|
extern bool RestoreArchivedFile(char *path, const char *xlogfname,
|
2012-11-19 09:02:25 +01:00
|
|
|
const char *recovername, off_t expectedSize,
|
|
|
|
bool cleanupEnabled);
|
2012-10-02 12:37:19 +02:00
|
|
|
extern void ExecuteRecoveryCommand(char *command, char *commandName,
|
|
|
|
bool failOnerror);
|
2013-05-29 22:58:43 +02:00
|
|
|
extern void KeepFileRestoredFromArchive(char *path, char *xlogfname);
|
2012-10-02 12:37:19 +02:00
|
|
|
extern void XLogArchiveNotify(const char *xlog);
|
|
|
|
extern void XLogArchiveNotifySeg(XLogSegNo segno);
|
2012-08-09 00:58:49 +02:00
|
|
|
extern void XLogArchiveForceDone(const char *xlog);
|
2012-10-02 12:37:19 +02:00
|
|
|
extern bool XLogArchiveCheckDone(const char *xlog);
|
|
|
|
extern bool XLogArchiveIsBusy(const char *xlog);
|
Don't archive bogus recycled or preallocated files after timeline switch.
After a timeline switch, we would leave behind recycled WAL segments that
are in the future, but on the old timeline. After promotion, and after they
become old enough to be recycled again, we would notice that they don't have
a .ready or .done file, create a .ready file for them, and archive them.
That's bogus, because the files contain garbage, recycled from an older
timeline (or prealloced as zeros). We shouldn't archive such files.
This could happen when we're following a timeline switch during replay, or
when we switch to new timeline at end-of-recovery.
To fix, whenever we switch to a new timeline, scan the data directory for
WAL segments on the old timeline, but with a higher segment number, and
remove them. Those don't belong to our timeline history, and are most
likely bogus recycled or preallocated files. They could also be valid files
that we streamed from the primary ahead of time, but in any case, they're
not needed to recover to the new timeline.
2015-04-13 15:53:49 +02:00
|
|
|
extern bool XLogArchiveIsReady(const char *xlog);
|
At promotion, don't leave behind a partial segment on the old timeline.
With commit de768844, a copy of the partial segment was archived with the
.partial suffix, but the original file was still left in pg_xlog, so it
didn't actually solve the problems with archiving the partial segment that
it was supposed to solve. With this patch, the partial segment is renamed
rather than copied, so we only archive it with the .partial suffix.
Also be more robust in detecting if the last segment is already being
archived. Previously I used XLogArchiveIsBusy() for that, but that's not
quite right. With archive_mode='always', there might be a .ready file for
it, and we don't want to rename it to .partial in that case.
The old segment is needed until we're fully committed to the new timeline,
i.e. until we've written the end-of-recovery WAL record and updated the
min recovery point and timeline in the control file. So move the renaming
later in the startup sequence, after all that's been done.
2015-05-21 14:28:22 +02:00
|
|
|
extern bool XLogArchiveIsReadyOrDone(const char *xlog);
|
2012-10-02 12:37:19 +02:00
|
|
|
extern void XLogArchiveCleanup(const char *xlog);
|
|
|
|
|
2004-07-22 00:31:26 +02:00
|
|
|
#endif /* XLOG_INTERNAL_H */
|