[PGSQL]wal日志文件名的规则

 

使用pgcontroldata看到的checkpoint信息如下:

Latest checkpoint location:           0/E010020

Prior checkpoint location:            0/A1B2B00

Latest checkpoint's REDO location:    0/C00EF48

日志中也可以看WAL文件位置信息:

LOG:  database system was interrupted; last known up at 2011-08-16 14:46:03 CST

LOG:  database system was not properly shut down; automatic recovery in progress

LOG:  redo starts at 0/F00E980

LOG:  record with zero length at 0/F010B28

LOG:  redo done at 0/F010AE0

LOG:  last completed transaction was at log time 2011-08-16 14:44:51.809264+08

LOG:  database system is ready to accept connections

而WAL文件名为: 00000001000000000000000F

-rw------- 1 osdba osdba 16777216 2011-08-16 14:46 00000001000000000000000F

这两都有什么关系呢:

#define XLogFileName(fname, tli, log, seg) \

snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)

WAL文件名由4字节的时间线+4字节的logid+4字节的序号组成

日志中的WAL的location为:0/F010B28,0表示为logid,F010B28表示位置

换算成WAL文件中的序号+offset:

序号 = F010B28 / (WAL文件大小)

offset:F010B28 % (WAL文件大小)

 

xlog文件由多个xlog record组成,每个record有如下结构:

/*

 * The overall layout of an XLOG record is:

 * Fixed-size header (XLogRecord struct)

 * rmgr-specific data

 * BkpBlock

 * backup block data

 * BkpBlock

 * backup block data

 * ...

 

typedef struct XLogRecord

{

pg_crc32 xl_crc; /* CRC for this record */

XLogRecPtr xl_prev; /* ptr to previous record in log */

TransactionId xl_xid; /* xact id */

uint32 xl_tot_len; /* total len of entire record */

uint32 xl_len; /* total len of rmgr data */

uint8 xl_info; /* flag bits, see below */

RmgrId xl_rmid; /* resource manager for this record */

 

/* Depending on MAXALIGN, there are either 2 or 6 wasted bytes here */

 

/* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */

 

} XLogRecord;