Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hzZAW-0006Gz-5v for pgsql-general@arkaria.postgresql.org; Mon, 19 Aug 2019 04:21:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hzZAT-0007Bj-ST for pgsql-general@arkaria.postgresql.org; Mon, 19 Aug 2019 04:21:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hzZAT-0007Bc-GL for pgsql-general@lists.postgresql.org; Mon, 19 Aug 2019 04:21:17 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hzZAQ-0001UB-IO for pgsql-general@postgresql.org; Mon, 19 Aug 2019 04:21:17 +0000 Received: by mail-pf1-x441.google.com with SMTP id q139so371876pfc.13 for ; Sun, 18 Aug 2019 21:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=gb4TQwjr/J+b9M0jPOKuz3ZftFnBVS6nLbdLu6fQWsY=; b=Pas2cG0CaZLUvRrzKQ4GK4gvsZgjXWClX/g86VMou/m13V+c+1kPz4HMe8Z2nTxfMV jPmClpXQU0YcvJX5QShztfgZzpA3I2k+rp0YM5I9nDwQz6Z3/dW3524Qld+wXkTsLY/A TiAdKpH/qeLeNBoq+g4WSN0F6HwXIYCwPINWcdAb/HIaO13z0p/LNrgGfIi0Il5gJvES 5HM5ftonXNn2+kIyrlZ4eioPJXoVBb7sebCvAYHyBVN4n4mWn+PKNW5oPcYFJaES5XrU KSKKrBXnsSMtpJLPhWNIkZnW+6e8vyEXObbigWzuHygf8dQskg+6ThnoOQzJKG8d4BDJ TcMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=gb4TQwjr/J+b9M0jPOKuz3ZftFnBVS6nLbdLu6fQWsY=; b=C7O70xJ/OnXreioWr3q25RXLCb/ECPnIX09uvL+IPRrZnPOAflDL5JoIpiqNNxAbYT KoM2DgFuIAiKU1RVW/1akzPLzF56O5tkgaTjEXzZ30mVkP2J1UmuuJkjhPL5tbBzKRdO 3hMvr7KDV98FmCHORyyZC/8EjejMgvp+I8TNEQsjg3xuGHE8xZyopPTc+F40wVIuI/FI UGSvjESgWPFp3huVxAEFjZGpcn0wJdNpkbU1+Dmivymiu/zpg9Lge/zFixDTE+PEBTUq RL3r6YmAXE5lqGULRrhjmJ+iLYRZGg7N7JJMTLjsc5i/6egn/SPMDXqWS4rUyyB6MIj+ 3M8Q== X-Gm-Message-State: APjAAAUMicIYz6PwISD1AdbvF8lEdjl/8605lAmq/wvL1hqvX1Y3J52E slV8Ia/B6hCJd7M+metNTm8= X-Google-Smtp-Source: APXvYqwaOE/PgFl1IHsKg+Yq/18RlW4I0AgAeRwUEFAykIpOPza/1dergGDkC6V0o0RsoHTnNmlOdQ== X-Received: by 2002:a62:7790:: with SMTP id s138mr21322536pfc.243.1566188471923; Sun, 18 Aug 2019 21:21:11 -0700 (PDT) Received: from localhost (w204177.dynamic.ppp.asahi-net.or.jp. [121.1.204.177]) by smtp.gmail.com with ESMTPSA id f7sm13552060pfd.43.2019.08.18.21.21.10 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 18 Aug 2019 21:21:11 -0700 (PDT) Date: Mon, 19 Aug 2019 13:21:02 +0900 (Tokyo Standard Time) Message-Id: <20190819.132102.92767303.horikyota.ntt@gmail.com> To: fluca1978@gmail.com Cc: pgsql-general@postgresql.org Subject: Re: question about zeroes in the wal file names From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.5 on Emacs 22.2 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.01-dev (TSUBO-SUMIRE) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk At Sun, 18 Aug 2019 16:17:03 +0200, Luca Ferrari wrote in > 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