*
* pg_control.h
* The system control file "pg_control" is not a heap relation.
* However, we define it here so that the format is documented.
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/catalog/pg_control.h
*
* -------------------------------------------------------------------------
*/
#ifndef PG_CONTROL_H
#define PG_CONTROL_H
#include "access/xlogdefs.h"
#include "pgtime.h"
#include "utils/pg_crc.h"
#include "port/pg_crc32c.h"
#define PG_CONTROL_VERSION 923
* Body of CheckPoint XLOG records. This is declared here because we keep
* a copy of the latest one in pg_control for possible disaster recovery.
* Changing this struct requires a PG_CONTROL_VERSION bump.
*/
typedef struct CheckPoint {
XLogRecPtr redo;
* create CheckPoint (i.e. REDO start point) */
TimeLineID ThisTimeLineID;
bool fullPageWrites;
TransactionId nextXid;
Oid nextOid;
MultiXactId nextMulti;
MultiXactOffset nextMultiOffset;
TransactionId oldestXid;
Oid oldestXidDB;
pg_time_t time;
XLogSegNo remove_seg;
* Oldest XID still running. This is only needed to initialize hot standby
* mode from an online checkpoint, so we only bother calculating this for
* online checkpoints and only when wal_level is hot_standby. Otherwise
* it's set to InvalidTransactionId.
*/
TransactionId oldestActiveXid;
} CheckPoint;
* checkpoint new
*/
typedef struct CheckPointNew {
CheckPoint ori_checkpoint;
CommitSeqNo next_csn;
} CheckPointNew;
typedef struct CheckPointPlus
{
CheckPoint ori_checkpoint;
CommitSeqNo next_csn;
uint64 length;
TransactionId recent_global_xmin;
} CheckPointPlus;
typedef struct CheckPointUndo
{
CheckPoint ori_checkpoint;
CommitSeqNo next_csn;
uint64 length;
TransactionId recent_global_xmin;
uint64 globalRecycleXid;
} CheckPointUndo;
#define XLOG_CHECKPOINT_SHUTDOWN 0x00
#define XLOG_CHECKPOINT_ONLINE 0x10
#define XLOG_NOOP 0x20
#define XLOG_NEXTOID 0x30
#define XLOG_SWITCH 0x40
#define XLOG_BACKUP_END 0x50
#define XLOG_PARAMETER_CHANGE 0x60
#define XLOG_RESTORE_POINT 0x70
#define XLOG_FPW_CHANGE 0x80
#define XLOG_END_OF_RECOVERY 0x90
#define XLOG_FPI_FOR_HINT 0xA0
#define XLOG_FPI 0xB0
#define XLOG_DELAY_XLOG_RECYCLE 0xC0
#define XLOG_MERGE_RECORD 0x01
* System status indicator. Note this is stored in pg_control; if you change
* it, you must bump PG_CONTROL_VERSION
*/
typedef enum DBState {
DB_STARTUP = 0,
DB_SHUTDOWNED,
DB_SHUTDOWNED_IN_RECOVERY,
DB_SHUTDOWNING,
DB_IN_CRASH_RECOVERY,
DB_IN_ARCHIVE_RECOVERY,
DB_IN_PRODUCTION
} DBState;
* Contents of pg_control.
*
* NOTE: try to keep this under 512 bytes so that it will fit on one physical
* sector of typical disk drives. This reduces the odds of corruption due to
* power failure midway through a write.
*/
typedef struct ControlFileData {
* Unique system identifier --- to ensure we match up xlog files with the
* installation that produced them.
*/
uint64 system_identifier;
* Version identifier information. Keep these fields at the same offset,
* especially pg_control_version; they won't be real useful if they move
* around. (For historical reasons they must be 8 bytes into the file
* rather than immediately at the front.)
*
* pg_control_version identifies the format of pg_control itself.
* catalog_version_no identifies the format of the system catalogs.
*
* There are additional version identifiers in individual files; for
* example, WAL logs contain per-page magic numbers that can serve as
* version cues for the WAL log.
*/
uint32 pg_control_version;
uint32 catalog_version_no;
uint32 timeline;
* System status data
*/
DBState state;
pg_time_t time;
XLogRecPtr checkPoint;
XLogRecPtr prevCheckPoint;
CheckPoint checkPointCopy;
* These two values determine the minimum point we must recover up to
* before starting up:
*
* minRecoveryPoint is updated to the latest replayed LSN whenever we
* flush a data change during archive recovery. That guards against
* starting archive recovery, aborting it, and restarting with an earlier
* stop location. If we've already flushed data changes from WAL record X
* to disk, we mustn't start up until we reach X again. Zero when not
* doing archive recovery.
*
* backupStartPoint is the redo pointer of the backup start checkpoint, if
* we are recovering from an online backup and haven't reached the end of
* backup yet. It is reset to zero when the end of backup is reached, and
* we mustn't start up before that. A boolean would suffice otherwise, but
* we use the redo pointer as a cross-check when we see an end-of-backup
* record, to make sure the end-of-backup record corresponds the base
* backup we're recovering from.
*
* backupEndPoint is the backup end location, if we are recovering from an
* online backup which was taken from the standby and haven't reached the
* end of backup yet. It is initialized to the minimum recovery point in
* pg_control which was backed up last. It is reset to zero when the end
* of backup is reached, and we mustn't start up before that.
*
* If backupEndRequired is true, we know for sure that we're restoring
* from a backup, and must see a backup-end record before we can safely
* start up. If it's false, but backupStartPoint is set, a backup_label
* file was found at startup but it may have been a leftover from a stray
* pg_start_backup() call, not accompanied by pg_stop_backup().
*/
XLogRecPtr minRecoveryPoint;
XLogRecPtr backupStartPoint;
XLogRecPtr backupEndPoint;
bool backupEndRequired;
* Parameter settings that determine if the WAL can be used for archival
* or hot standby.
*/
int wal_level;
int MaxConnections;
int max_prepared_xacts;
int max_locks_per_xact;
* This data is used to check for hardware-architecture compatibility of
* the database and the backend executable. We need not check endianness
* explicitly, since the pg_control version will surely look wrong to a
* machine of different endianness, but we do need to worry about MAXALIGN
* and floating-point format. (Note: storage layout nominally also
* depends on SHORTALIGN and INTALIGN, but in practice these are the same
* on all architectures of interest.)
*
* Testing just one double value is not a very bulletproof test for
* floating-point compatibility, but it will catch most cases.
*/
uint32 maxAlign;
double floatFormat;
#define FLOATFORMAT_VALUE 1234567.0
* This data is used to make sure that configuration of this database is
* compatible with the backend executable.
*/
uint32 blcksz;
uint32 relseg_size;
uint32 xlog_blcksz;
uint32 xlog_seg_size;
uint32 nameDataLen;
uint32 indexMaxKeys;
uint32 toast_max_chunk_size;
bool enableIntTimes;
bool float4ByVal;
bool float8ByVal;
bool bootstrap_segment;
pg_crc32c crc;
} ControlFileData;
typedef struct LsnXlogFlushData {
XLogRecPtr localLsnFlushPoint;
XLogRecPtr peerXlogFlushPoint;
pg_crc32 crc;
} LsnXlogFlushData;
* Physical size of the pg_control file. Note that this is considerably
* bigger than the actually used size (ie, sizeof(ControlFileData)).
* The idea is to keep the physical size constant independent of format
* changes, so that ReadControlFile will deliver a suitable wrong-version
* message instead of a read error if it's looking at an incompatible file.
*/
#define PG_CONTROL_SIZE 8192
#define MIN_INSTANCEID 0
#define MAX_INSTANCEID 63
#define REFORMER_CTL_INSTANCEID (MAX_INSTANCEID + 1)
#define INVALID_INSTANCEID -1
#define MAX_INSTANCEID_LEN 3
#define PG_LSNXLOGFLUSHCHK_FILESIZE 512
extern uint32 get_controlfile_timeline(void);
* LsnXlogFlushData struct reserved 40 bytes,may be used in the future.
*/
#define PG_LSNXLOGFLUSHCHK_DATASIZE (40 + 2 * sizeof (XLogRecPtr))
#endif