postgresql/src/backend
Nathan Bossart 3cb2f13ac5 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
2024-05-13 15:53:50 -05:00
..
access Fix an assortment of typos 2024-05-04 02:33:25 +12:00
archive Add built-in ERROR handling for archive callbacks. 2024-04-02 22:28:11 -05:00
backup Fix unnecessary padding in incremental backups 2024-04-14 20:37:49 +02:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Revert structural changes to not-null constraints 2024-05-13 11:31:09 +02:00
commands Fix pg_sequence_last_value() for unlogged sequences on standbys. 2024-05-13 15:53:50 -05:00
executor Fix ON CONFLICT DO NOTHING/UPDATE for temporal indexes 2024-05-10 14:55:31 +02:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit Remove dead code 2024-04-17 10:48:04 +02:00
lib Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
libpq Reject SSL connection if ALPN is used but there's no common protocol 2024-04-29 18:12:26 +03:00
main Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
nodes Fix query pullup issue with WindowClause runCondition 2024-05-05 12:54:46 +12:00
optimizer Revert structural changes to not-null constraints 2024-05-13 11:31:09 +02:00
parser Revert structural changes to not-null constraints 2024-05-13 11:31:09 +02:00
partitioning Fix error message in check_partition_bounds_for_split_range() 2024-04-30 12:00:39 +03:00
po Translation updates 2024-05-06 12:06:31 +02:00
port Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
postmaster Avoid repeating loads of frozen ID values. 2024-04-29 10:25:33 -07:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Fix incorrect format placeholder 2024-05-08 08:37:46 +02:00
rewrite Fix assorted bugs related to identity column in partitioned tables 2024-05-07 22:50:00 +02:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
storage Fix typos and incorrect type in read_stream.c 2024-05-01 17:04:52 +12:00
tcop Remove COMMAND_TAG_NEXTTAG from enum CommandTag. 2024-05-13 13:52:17 -04:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Revert structural changes to not-null constraints 2024-05-13 11:31:09 +02:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Rework lwlocknames.txt to become lwlocklist.h 2024-03-20 11:55:20 +01:00
meson.build Remove AIX support 2024-02-28 15:17:23 +04:00
nls.mk Remove distprep 2023-11-06 15:18:04 +01:00