From d64d6f49e8935b4bde52510c02307c201fba8f6a Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Sun, 20 Sep 2026 09:39:56 +0800
Subject: [PATCH v2] Fix input LSN validation error messages in pg_walinspect.

Commit 5c1b6628075a changed the input LSN validation checks to
allow an input LSN equal to the current LSN, and a start LSN equal
to the end LSN. However, the corresponding error messages
continued to say that the LSNs had to be less than the current LSN
or the end LSN.

Fix this oversight by changing those messages from "must be less
than" to "must be less than or equal to", matching the actual
validation conditions. Similar wording is used elsewhere in the
code.

Not back-patched, as the fix is not critical and the inaccuracy
went unnoticed for years.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Kiran Kaki <itskkpg@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/7B8F5F12-98A5-4618-867A-904EA1334FD4@gmail.com
---
 contrib/pg_walinspect/expected/oldextversions.out |  4 ++--
 contrib/pg_walinspect/expected/pg_walinspect.out  | 14 +++++++-------
 contrib/pg_walinspect/pg_walinspect.c             | 10 +++++-----
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/contrib/pg_walinspect/expected/oldextversions.out b/contrib/pg_walinspect/expected/oldextversions.out
index 89953af3d0e..fd65ed149c6 100644
--- a/contrib/pg_walinspect/expected/oldextversions.out
+++ b/contrib/pg_walinspect/expected/oldextversions.out
@@ -43,9 +43,9 @@ SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_stats_till_end_of_wal(:'wal_lsn1');
 
 -- Failures with start LSNs.
 SELECT * FROM pg_get_wal_records_info_till_end_of_wal('FFFFFFFF/FFFFFFFF');
-ERROR:  WAL start LSN must be less than current LSN
+ERROR:  WAL start LSN must be less than or equal to current LSN
 SELECT * FROM pg_get_wal_stats_till_end_of_wal('FFFFFFFF/FFFFFFFF');
-ERROR:  WAL start LSN must be less than current LSN
+ERROR:  WAL start LSN must be less than or equal to current LSN
 -- Move to new version 1.1.
 ALTER EXTENSION pg_walinspect UPDATE TO '1.1';
 -- List what version 1.1 contains.
diff --git a/contrib/pg_walinspect/expected/pg_walinspect.out b/contrib/pg_walinspect/expected/pg_walinspect.out
index f955ff5d3c5..b9abeeebdfd 100644
--- a/contrib/pg_walinspect/expected/pg_walinspect.out
+++ b/contrib/pg_walinspect/expected/pg_walinspect.out
@@ -29,14 +29,14 @@ SELECT * FROM pg_get_wal_block_info('0/0', :'wal_lsn1');
 ERROR:  could not read WAL at LSN 0/00000000
 -- Start LSN > End LSN.
 SELECT * FROM pg_get_wal_records_info(:'wal_lsn2', :'wal_lsn1');
-ERROR:  WAL start LSN must be less than end LSN
+ERROR:  WAL start LSN must be less than or equal to end LSN
 SELECT * FROM pg_get_wal_stats(:'wal_lsn2', :'wal_lsn1');
-ERROR:  WAL start LSN must be less than end LSN
+ERROR:  WAL start LSN must be less than or equal to end LSN
 SELECT * FROM pg_get_wal_block_info(:'wal_lsn2', :'wal_lsn1');
-ERROR:  WAL start LSN must be less than end LSN
+ERROR:  WAL start LSN must be less than or equal to end LSN
 -- LSNs with the highest value possible.
 SELECT * FROM pg_get_wal_record_info('FFFFFFFF/FFFFFFFF');
-ERROR:  WAL input LSN must be less than current LSN
+ERROR:  WAL input LSN must be less than or equal to current LSN
 -- Success with end LSNs.
 SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
  ok 
@@ -58,11 +58,11 @@ SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_block_info(:'wal_lsn1', 'FFFFFFFF/FFF
 
 -- Failures with start LSNs.
 SELECT * FROM pg_get_wal_records_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
-ERROR:  WAL start LSN must be less than current LSN
+ERROR:  WAL start LSN must be less than or equal to current LSN
 SELECT * FROM pg_get_wal_stats('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
-ERROR:  WAL start LSN must be less than current LSN
+ERROR:  WAL start LSN must be less than or equal to current LSN
 SELECT * FROM pg_get_wal_block_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
-ERROR:  WAL start LSN must be less than current LSN
+ERROR:  WAL start LSN must be less than or equal to current LSN
 -- ===================================================================
 -- Tests for all function executions
 -- ===================================================================
diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index a172f9e2b40..6edd6f8cb35 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -488,7 +488,7 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
 	if (lsn > curr_lsn)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("WAL input LSN must be less than current LSN"),
+				 errmsg("WAL input LSN must be less than or equal to current LSN"),
 				 errdetail("Current WAL LSN on the database system is at %X/%08X.",
 						   LSN_FORMAT_ARGS(curr_lsn))));
 
@@ -530,14 +530,14 @@ ValidateInputLSNs(XLogRecPtr start_lsn, XLogRecPtr *end_lsn)
 	if (start_lsn > curr_lsn)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("WAL start LSN must be less than current LSN"),
+				 errmsg("WAL start LSN must be less than or equal to current LSN"),
 				 errdetail("Current WAL LSN on the database system is at %X/%08X.",
 						   LSN_FORMAT_ARGS(curr_lsn))));
 
 	if (start_lsn > *end_lsn)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("WAL start LSN must be less than end LSN")));
+				 errmsg("WAL start LSN must be less than or equal to end LSN")));
 
 	if (*end_lsn > curr_lsn)
 		*end_lsn = curr_lsn;
@@ -836,7 +836,7 @@ pg_get_wal_records_info_till_end_of_wal(PG_FUNCTION_ARGS)
 	if (start_lsn > end_lsn)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("WAL start LSN must be less than current LSN"),
+				 errmsg("WAL start LSN must be less than or equal to current LSN"),
 				 errdetail("Current WAL LSN on the database system is at %X/%08X.",
 						   LSN_FORMAT_ARGS(end_lsn))));
 
@@ -855,7 +855,7 @@ pg_get_wal_stats_till_end_of_wal(PG_FUNCTION_ARGS)
 	if (start_lsn > end_lsn)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("WAL start LSN must be less than current LSN"),
+				 errmsg("WAL start LSN must be less than or equal to current LSN"),
 				 errdetail("Current WAL LSN on the database system is at %X/%08X.",
 						   LSN_FORMAT_ARGS(end_lsn))));
 
-- 
2.47.3

