]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Expose sequence page LSN via pg_get_sequence_data.
authorAmit Kapila <akapila@postgresql.org>
Mon, 6 Oct 2025 08:27:22 +0000 (08:27 +0000)
committerAmit Kapila <akapila@postgresql.org>
Mon, 6 Oct 2025 08:30:16 +0000 (08:30 +0000)
This patch enhances the pg_get_sequence_data function to include the
page-level LSN (Log Sequence Number) of the sequence. This additional
metadata will be used by upcoming patches to support synchronization
of sequences during logical replication.

By exposing the LSN, we enable more accurate tracking of sequence
changes, which is essential for maintaining consistency across
replicated nodes.

Author: vignesh C <vignesh21@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAA4eK1LC+KJiAkSrpE_NwvNdidw9F2os7GERUeSxSKv71gXysQ@mail.gmail.com

src/backend/commands/sequence.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/regress/expected/sequence.out
src/test/regress/sql/sequence.sql

index 636d3c3ec737b4c9e4640c9555e6af330d2a6c9b..cf46a5433648791fc72da41a7a98a04d479463bd 100644 (file)
@@ -45,6 +45,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
+#include "utils/pg_lsn.h"
 #include "utils/resowner.h"
 #include "utils/syscache.h"
 #include "utils/varlena.h"
@@ -1795,7 +1796,7 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
 
 
 /*
- * Return the sequence tuple.
+ * Return the sequence tuple along with its page LSN.
  *
  * This is primarily intended for use by pg_dump to gather sequence data
  * without needing to individually query each sequence relation.
@@ -1803,7 +1804,7 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
 Datum
 pg_get_sequence_data(PG_FUNCTION_ARGS)
 {
-#define PG_GET_SEQUENCE_DATA_COLS      2
+#define PG_GET_SEQUENCE_DATA_COLS      3
        Oid                     relid = PG_GETARG_OID(0);
        SeqTable        elm;
        Relation        seqrel;
@@ -1818,6 +1819,8 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
                                           INT8OID, -1, 0);
        TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "is_called",
                                           BOOLOID, -1, 0);
+       TupleDescInitEntry(resultTupleDesc, (AttrNumber) 3, "page_lsn",
+                                          LSNOID, -1, 0);
        resultTupleDesc = BlessTupleDesc(resultTupleDesc);
 
        init_sequence(relid, &elm, &seqrel);
@@ -1833,11 +1836,14 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
                Buffer          buf;
                HeapTupleData seqtuple;
                Form_pg_sequence_data seq;
+               Page            page;
 
                seq = read_seq_tuple(seqrel, &buf, &seqtuple);
+               page = BufferGetPage(buf);
 
                values[0] = Int64GetDatum(seq->last_value);
                values[1] = BoolGetDatum(seq->is_called);
+               values[2] = LSNGetDatum(PageGetLSN(page));
 
                UnlockReleaseBuffer(buf);
        }
index 6d6daf1d5a7ca09293026777dab14533d065612e..642abe5217e3662a473561b0f1674431160a92d4 100644 (file)
@@ -57,6 +57,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     202510061
+#define CATALOG_VERSION_NO     202510062
 
 #endif
index 5d5a9483fecd656eef8ceb5ecb3ed248633193c8..7c20180637f69d8d8d883d42c73dac6a01bb235d 100644 (file)
 { oid => '6427', descr => 'return sequence tuple, for use by pg_dump',
   proname => 'pg_get_sequence_data', provolatile => 'v', proparallel => 'u',
   prorettype => 'record', proargtypes => 'regclass',
-  proallargtypes => '{regclass,int8,bool}', proargmodes => '{i,o,o}',
-  proargnames => '{sequence_oid,last_value,is_called}',
+  proallargtypes => '{regclass,int8,bool,pg_lsn}', proargmodes => '{i,o,o,o}',
+  proargnames => '{sequence_oid,last_value,is_called,page_lsn}',
   prosrc => 'pg_get_sequence_data' },
 
 { oid => '275', descr => 'return the next oid for a system table',
index 15925d99c8a38256c59f76424c361164a8140c21..c4454e5b435a173d0859d8556863024442fc46c7 100644 (file)
@@ -840,10 +840,10 @@ SELECT nextval('test_seq1');
 (1 row)
 
 -- pg_get_sequence_data
-SELECT * FROM pg_get_sequence_data('test_seq1');
- last_value | is_called 
-------------+-----------
-         10 | t
+SELECT last_value, is_called, page_lsn <= pg_current_wal_lsn() as lsn FROM pg_get_sequence_data('test_seq1');
+ last_value | is_called | lsn 
+------------+-----------+-----
+         10 | t         | t
 (1 row)
 
 DROP SEQUENCE test_seq1;
index 2c220b60749ea58d98f5d2c26716a5b6ad645d86..b334453792924242705b4474785bf18a327f1610 100644 (file)
@@ -414,6 +414,6 @@ SELECT nextval('test_seq1');
 SELECT nextval('test_seq1');
 
 -- pg_get_sequence_data
-SELECT * FROM pg_get_sequence_data('test_seq1');
+SELECT last_value, is_called, page_lsn <= pg_current_wal_lsn() as lsn FROM pg_get_sequence_data('test_seq1');
 
 DROP SEQUENCE test_seq1;