Add timeline ID to file names generated with pg_waldump --save-fullpage
authorMichael Paquier <michael@paquier.xyz>
Wed, 28 Jun 2023 07:26:55 +0000 (16:26 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 28 Jun 2023 07:26:55 +0000 (16:26 +0900)
Not including the timeline IDs to the file names generated by pg_waldump
for the individual blocks saved could cause some of these files to be
overwritten when scanning segments across multiple timelines.  Having
this information is also as much useful as the LSNs, to be able to know
from exactly which WAL segment a block is comes from.

While on it, this fixes a few comments in the tests, where the format of
the file was not described as matching with the reality.

Reported-by: Fujii Masao
Reviewed-by: Kyotaro Horiguchi, David Christensen
Discussion: https://postgr.es/m/ZJp921+nITFnvBVS@paquier.xyz

doc/src/sgml/ref/pg_waldump.sgml
src/bin/pg_waldump/pg_waldump.c
src/bin/pg_waldump/t/002_save_fullpage.pl

index e5f9637847e5f0773106679536c1ce1808cdfad5..4592d6016a55150b919ae0c39fdd2ac3e4a47722 100644 (file)
@@ -283,7 +283,7 @@ PostgreSQL documentation
        </para>
        <para>
         The full page images are saved with the following file name format:
-        <literal><replaceable>LSN</replaceable>.<replaceable>RELTABLESPACE</replaceable>.<replaceable>DATOID</replaceable>.<replaceable>RELNODE</replaceable>.<replaceable>BLKNO</replaceable><replaceable>FORK</replaceable></literal>
+        <literal><replaceable>TIMELINE</replaceable>-<replaceable>LSN</replaceable>.<replaceable>RELTABLESPACE</replaceable>.<replaceable>DATOID</replaceable>.<replaceable>RELNODE</replaceable>.<replaceable>BLKNO</replaceable><replaceable>FORK</replaceable></literal>
 
         The file names are composed of the following parts:
         <informaltable>
@@ -296,6 +296,13 @@ PostgreSQL documentation
           </thead>
 
           <tbody>
+           <row>
+            <entry>TIMELINE</entry>
+            <entry>The timeline of the WAL segment file where the record
+             is located formatted as one 8-character hexadecimal number
+             <literal>%08X</literal></entry>
+           </row>
+
            <row>
             <entry>LSN</entry>
             <entry>The <acronym>LSN</acronym> of the record with this image,
index c6d3ae63445da96f0b84012a361a462d199e0027..96845e1a1aeb7acca3a13cf6dca27545be0ff23c 100644 (file)
@@ -518,7 +518,8 @@ XLogRecordSaveFPWs(XLogReaderState *record, const char *savepath)
                else
                        pg_fatal("invalid fork number: %u", fork);
 
-               snprintf(filename, MAXPGPATH, "%s/%08X-%08X.%u.%u.%u.%u%s", savepath,
+               snprintf(filename, MAXPGPATH, "%s/%08X-%08X-%08X.%u.%u.%u.%u%s", savepath,
+                                record->seg.ws_tli,
                                 LSN_FORMAT_ARGS(record->ReadRecPtr),
                                 rnode.spcOid, rnode.dbOid, rnode.relNumber, blk, forkname);
 
index 831ffdefefd61a3be3ad8d9ff2715ad0dda6902d..f0725805f21921d6d79c2d42d08d6f4a524a43f8 100644 (file)
@@ -79,15 +79,16 @@ $node->command_ok(
        'pg_waldump with --save-fullpage runs');
 
 # This regexp will match filenames formatted as:
-# XXXXXXXX-XXXXXXXX.DBOID.TLOID.NODEOID.dd_fork with the components being:
-# - WAL LSN in hex format,
-# - Tablespace OID (0 for global)
+# TLI-LSNh-LSNl.TBLSPCOID.DBOID.NODEOID.dd_fork with the components being:
+# - Timeline ID in hex format.
+# - WAL LSN in hex format, as two 8-character numbers.
+# - Tablespace OID (0 for global).
 # - Database OID.
 # - Relfilenode.
 # - Block number.
 # - Fork this block came from (vm, init, fsm, or main).
 my $file_re =
-  qr/^([0-9A-F]{8})-([0-9A-F]{8})[.][0-9]+[.][0-9]+[.][0-9]+[.][0-9]+(?:_vm|_init|_fsm|_main)?$/;
+  qr/^[0-9A-F]{8}-([0-9A-F]{8})-([0-9A-F]{8})[.][0-9]+[.][0-9]+[.][0-9]+[.][0-9]+(?:_vm|_init|_fsm|_main)?$/;
 
 my $file_count = 0;