From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: fluca1978@gmail.com
Cc: pgsql-general@postgresql.org
Subject: Re: question about zeroes in the wal file names
Date: Mon, 19 Aug 2019 13:21:02 +0900 (Tokyo Standard Time)
Message-ID: <20190819.132102.92767303.horikyota.ntt@gmail.com> (raw)
In-Reply-To: <CAKoxK+67oS+PSygdmRHbn-GSjE_TY+t6Gzk6CRzcw-HVGswzOA@mail.gmail.com>
References: <CAKoxK+67oS+PSygdmRHbn-GSjE_TY+t6Gzk6CRzcw-HVGswzOA@mail.gmail.com>
At Sun, 18 Aug 2019 16:17:03 +0200, Luca Ferrari <fluca1978@gmail.com> wrote in <CAKoxK+67oS+PSygdmRHbn-GSjE_TY+t6Gzk6CRzcw-HVGswzOA@mail.gmail.com>
> I'm just curious to better understand the naming convention behind wal
> files, because I've seen on a system of mine that the wals created
> were:
>
> 000000050000020E000000FF
> 000000050000020F00000000
>
> while I was expecting 20E0x100. So I digged into the code and I've
> seen, from the XLogFileName macro, that the last part is built as the
> reminder of the number of segments per wal file:
>
> #define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes) \
> snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
> (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
> (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
>
>
> and with the default wal size of 16 MB that gives a remainder of 256
> (FF + 1). Assuming I haven't missed anything, this means that there
> are 6 zeroes that will never change in the last 8 chars of the wal
> filename. Is therefore this only done to handle PostgreSQL WAL sizes
> of 4 GB each?
I think that's right. I don't see it used in other than WAL file
names. As the macro name suggests, the 4GB block is internally
called as "xlog id" (XLogId). The block size is determined so
that the location within it can be handled as a 32-bit
integer. Older versions of postgresql defined XLogRecPtr as a
pair of two 32-bit integers.
xlogdefs.h.~REL9_1_0~:17
/*
* Pointer to a location in the XLOG. These pointers are 64 bits wide,
* because we don't want them ever to overflow.
*
* NOTE: xrecoff == 0 is used to indicate an invalid pointer. This is OK
* because we use page headers in the XLOG, so no XLOG record can start
* right at the beginning of a file.
*
* NOTE: the "log file number" is somewhat misnamed, since the actual files
* making up the XLOG are much smaller than 4Gb. Each actual file is an
* XLogSegSize-byte "segment" of a logical log file having the indicated
* xlogid. The log file number and segment number together identify a
* physical XLOG file. Segment number and offset within the physical file
* are computed from xrecoff div and mod XLogSegSize.
*/
typedef struct XLogRecPtr
{
uint32 xlogid; /* log file #, 0 based */
uint32 xrecoff; /* byte offset of location in log file */
} XLogRecPtr;
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: horikyota.ntt@gmail.com, fluca1978@gmail.com
Subject: Re: question about zeroes in the wal file names
In-Reply-To: <20190819.132102.92767303.horikyota.ntt@gmail.com>
References: <CAKoxK+67oS+PSygdmRHbn-GSjE_TY+t6Gzk6CRzcw-HVGswzOA@mail.gmail.com> <20190819.132102.92767303.horikyota.ntt@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox