diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-05-13 15:53:50 -0500 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-05-13 15:53:50 -0500 |
commit | 3cb2f13ac500983c9c6b1eef3b3c2091c26f3040 (patch) | |
tree | 749f18b670ffd6604d0b028e6bddfb76c775aca5 /doc/src | |
parent | 1f7452fa598ee5f1ed32f1fcce101c63c6f1933f (diff) | |
download | postgresql-3cb2f13ac500983c9c6b1eef3b3c2091c26f3040.tar.gz postgresql-3cb2f13ac500983c9c6b1eef3b3c2091c26f3040.zip |
Fix pg_sequence_last_value() for unlogged sequences on standbys.
Presently, when this function is called for an unlogged sequence on
a standby server, it will error out with a message like
ERROR: could not open file "base/5/16388": No such file or directory
Since the pg_sequences system view uses pg_sequence_last_value(),
it can error similarly. To fix, modify the function to return NULL
for unlogged sequences on standby servers. Since this bug is
present on all versions since v15, this approach is preferable to
making the ERROR nicer because we need to repair the pg_sequences
view without modifying its definition on released versions. For
consistency, this commit also modifies the function to return NULL
for other sessions' temporary sequences. The pg_sequences view
already appropriately filters out such sequences, so there's no bug
there, but we might as well offer some defense in case someone
invokes this function directly.
Unlogged sequences were first introduced in v15, but temporary
sequences are much older, so while the fix for unlogged sequences
is only back-patched to v15, the temporary sequence portion is
back-patched to all supported versions.
We could also remove the privilege check in the pg_sequences view
definition in v18 if we modify this function to return NULL for
sequences for which the current user lacks privileges, but that is
left as a future exercise for when v18 development begins.
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/20240501005730.GA594666%40nathanxps13
Backpatch-through: 12
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/system-views.sgml | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/doc/src/sgml/system-views.sgml b/doc/src/sgml/system-views.sgml index a54f4a47431..8c18bea902f 100644 --- a/doc/src/sgml/system-views.sgml +++ b/doc/src/sgml/system-views.sgml @@ -3091,15 +3091,36 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <para> The last sequence value written to disk. If caching is used, this value can be greater than the last value handed out from the - sequence. Null if the sequence has not been read from yet. Also, if - the current user does not have <literal>USAGE</literal> - or <literal>SELECT</literal> privilege on the sequence, the value is - null. + sequence. </para></entry> </row> </tbody> </tgroup> </table> + + <para> + The <structfield>last_value</structfield> column will read as null if any of + the following are true: + <itemizedlist> + <listitem> + <para> + The sequence has not been read from yet. + </para> + </listitem> + <listitem> + <para> + The current user does not have <literal>USAGE</literal> or + <literal>SELECT</literal> privilege on the sequence. + </para> + </listitem> + <listitem> + <para> + The sequence is unlogged and the server is a standby. + </para> + </listitem> + </itemizedlist> + </para> + </sect1> <sect1 id="view-pg-settings"> |