#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"
/*
- * 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.
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;
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);
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);
}
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202510061
+#define CATALOG_VERSION_NO 202510062
#endif
{ 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',
(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;
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;