[File] Identify PostgreSQL WAL segment files
Arthur Nascimento
tureba at gmail.com
Mon Nov 10 15:40:53 UTC 2025
Hi,
It's useful to identify WAL segments when investigating issues with
incorrect archiving, where WAL segments of different sources might
have gotten mixed up. In this case, it's helpful to be able to quickly
identify the major version, timeline, and systemid of each file.
WAL segment files have a 16-bit number that changes in each major
version (I intend to send updates yearly if this gets accepted.), and
is repeated in the header of every page (8kB by default) of a WAL
segment file (16MB by default). So comparing at least two of those
magic numbers is necessary.
Most other files of postgres (such as tables, indexes) don't have any
magic number or other identifying information to easily figure out
what they are. It may be possible, but such investigation comes up so
rarely that falling back to pg_filedump is usually acceptable.
So for now, the attachment contains rules to identify current and past
WAL segment versions, and print out the timeline and systemid fields
along with the major version:
# file 00000001*
00000001000000000000000B: PostgreSQL 18 WAL segment file (System ID
7571110129374440511, Timeline 1)
00000001000000000000003E: PostgreSQL 16 WAL segment file (System ID
7571111824638524783, Timeline 1)
000000010000000000000042: PostgreSQL 17 WAL segment file (System ID
7571110503725968496, Timeline 1)
Let me know if there is anything I need to adjust in this submission.
--
Tureba - Arthur Nascimento
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pg.magic
Type: application/octet-stream
Size: 2132 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20251110/dc3741b0/attachment.obj>
More information about the File
mailing list