Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb93172c

Browse files
author
Amit Kapila
committed
Expose sequence page LSN via pg_get_sequence_data.
This patch enhances the pg_get_sequence_data function to include thepage-level LSN (Log Sequence Number) of the sequence. This additionalmetadata will be used by upcoming patches to support synchronizationof sequences during logical replication.By exposing the LSN, we enable more accurate tracking of sequencechanges, which is essential for maintaining consistency acrossreplicated 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
1 parent42c6b74 commitb93172c

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

‎src/backend/commands/sequence.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include"utils/acl.h"
4646
#include"utils/builtins.h"
4747
#include"utils/lsyscache.h"
48+
#include"utils/pg_lsn.h"
4849
#include"utils/resowner.h"
4950
#include"utils/syscache.h"
5051
#include"utils/varlena.h"
@@ -1795,15 +1796,15 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
17951796

17961797

17971798
/*
1798-
* Return the sequence tuple.
1799+
* Return the sequence tuple along with its page LSN.
17991800
*
18001801
* This is primarily intended for use by pg_dump to gather sequence data
18011802
* without needing to individually query each sequence relation.
18021803
*/
18031804
Datum
18041805
pg_get_sequence_data(PG_FUNCTION_ARGS)
18051806
{
1806-
#definePG_GET_SEQUENCE_DATA_COLS2
1807+
#definePG_GET_SEQUENCE_DATA_COLS3
18071808
Oidrelid=PG_GETARG_OID(0);
18081809
SeqTableelm;
18091810
Relationseqrel;
@@ -1818,6 +1819,8 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
18181819
INT8OID,-1,0);
18191820
TupleDescInitEntry(resultTupleDesc, (AttrNumber)2,"is_called",
18201821
BOOLOID,-1,0);
1822+
TupleDescInitEntry(resultTupleDesc, (AttrNumber)3,"page_lsn",
1823+
LSNOID,-1,0);
18211824
resultTupleDesc=BlessTupleDesc(resultTupleDesc);
18221825

18231826
init_sequence(relid,&elm,&seqrel);
@@ -1833,11 +1836,14 @@ pg_get_sequence_data(PG_FUNCTION_ARGS)
18331836
Bufferbuf;
18341837
HeapTupleDataseqtuple;
18351838
Form_pg_sequence_dataseq;
1839+
Pagepage;
18361840

18371841
seq=read_seq_tuple(seqrel,&buf,&seqtuple);
1842+
page=BufferGetPage(buf);
18381843

18391844
values[0]=Int64GetDatum(seq->last_value);
18401845
values[1]=BoolGetDatum(seq->is_called);
1846+
values[2]=LSNGetDatum(PageGetLSN(page));
18411847

18421848
UnlockReleaseBuffer(buf);
18431849
}

‎src/include/catalog/catversion.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#defineCATALOG_VERSION_NO202510061
60+
#defineCATALOG_VERSION_NO202510062
6161

6262
#endif

‎src/include/catalog/pg_proc.dat‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,8 +3436,8 @@
34363436
{ oid => '6427', descr => 'return sequence tuple, for use by pg_dump',
34373437
proname => 'pg_get_sequence_data', provolatile => 'v', proparallel => 'u',
34383438
prorettype => 'record', proargtypes => 'regclass',
3439-
proallargtypes => '{regclass,int8,bool}', proargmodes => '{i,o,o}',
3440-
proargnames => '{sequence_oid,last_value,is_called}',
3439+
proallargtypes => '{regclass,int8,bool,pg_lsn}', proargmodes => '{i,o,o,o}',
3440+
proargnames => '{sequence_oid,last_value,is_called,page_lsn}',
34413441
prosrc => 'pg_get_sequence_data' },
34423442

34433443
{ oid => '275', descr => 'return the next oid for a system table',

‎src/test/regress/expected/sequence.out‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,10 @@ SELECT nextval('test_seq1');
840840
(1 row)
841841

842842
-- pg_get_sequence_data
843-
SELECT* FROM pg_get_sequence_data('test_seq1');
844-
last_value | is_called
845-
------------+-----------
846-
10 | t
843+
SELECTlast_value, is_called, page_lsn <= pg_current_wal_lsn() as lsn FROM pg_get_sequence_data('test_seq1');
844+
last_value | is_called| lsn
845+
------------+-----------+-----
846+
10 | t | t
847847
(1 row)
848848

849849
DROP SEQUENCE test_seq1;

‎src/test/regress/sql/sequence.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,6 @@ SELECT nextval('test_seq1');
414414
SELECT nextval('test_seq1');
415415

416416
-- pg_get_sequence_data
417-
SELECT*FROM pg_get_sequence_data('test_seq1');
417+
SELECTlast_value, is_called, page_lsn<= pg_current_wal_lsn()as lsnFROM pg_get_sequence_data('test_seq1');
418418

419419
DROPSEQUENCE test_seq1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp