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

Commit2812059

Browse files
Fix pg_sequence_last_value() for unlogged sequences on standbys.
Presently, when this function is called for an unlogged sequence ona standby server, it will error out with a message likeERROR: could not open file "base/5/16388": No such file or directorySince the pg_sequences system view uses pg_sequence_last_value(),it can error similarly. To fix, modify the function to return NULLfor unlogged sequences on standby servers. Since this bug ispresent on all versions since v15, this approach is preferable tomaking the ERROR nicer because we need to repair the pg_sequencesview without modifying its definition on released versions. Forconsistency, this commit also modifies the function to return NULLfor other sessions' temporary sequences. The pg_sequences viewalready appropriately filters out such sequences, so there's no bugthere, but we might as well offer some defense in case someoneinvokes this function directly.Unlogged sequences were first introduced in v15, but temporarysequences are much older, so while the fix for unlogged sequencesis only back-patched to v15, the temporary sequence portion isback-patched to all supported versions.We could also remove the privilege check in the pg_sequences viewdefinition in v18 if we modify this function to return NULL forsequences for which the current user lacks privileges, but that isleft as a future exercise for when v18 development begins.Reviewed-by: Tom Lane, Michael PaquierDiscussion:https://postgr.es/m/20240501005730.GA594666%40nathanxps13Backpatch-through: 12
1 parent157b1e6 commit2812059

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

‎src/backend/commands/sequence.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,11 +1857,8 @@ pg_sequence_last_value(PG_FUNCTION_ARGS)
18571857
Oidrelid=PG_GETARG_OID(0);
18581858
SeqTableelm;
18591859
Relationseqrel;
1860-
Bufferbuf;
1861-
HeapTupleDataseqtuple;
1862-
Form_pg_sequence_dataseq;
1863-
boolis_called;
1864-
int64result;
1860+
boolis_called= false;
1861+
int64result=0;
18651862

18661863
/* open and lock sequence */
18671864
init_sequence(relid,&elm,&seqrel);
@@ -1872,12 +1869,24 @@ pg_sequence_last_value(PG_FUNCTION_ARGS)
18721869
errmsg("permission denied for sequence %s",
18731870
RelationGetRelationName(seqrel))));
18741871

1875-
seq=read_seq_tuple(seqrel,&buf,&seqtuple);
1872+
/*
1873+
* We return NULL for other sessions' temporary sequences. The
1874+
* pg_sequences system view already filters those out, but this offers a
1875+
* defense against ERRORs in case someone invokes this function directly.
1876+
*/
1877+
if (!RELATION_IS_OTHER_TEMP(seqrel))
1878+
{
1879+
Bufferbuf;
1880+
HeapTupleDataseqtuple;
1881+
Form_pg_sequence_dataseq;
18761882

1877-
is_called=seq->is_called;
1878-
result=seq->last_value;
1883+
seq=read_seq_tuple(seqrel,&buf,&seqtuple);
18791884

1880-
UnlockReleaseBuffer(buf);
1885+
is_called=seq->is_called;
1886+
result=seq->last_value;
1887+
1888+
UnlockReleaseBuffer(buf);
1889+
}
18811890
relation_close(seqrel,NoLock);
18821891

18831892
if (is_called)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp