Re: pg_sequence_last_value() for unlogged sequences on standbys

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, pgsql-hackers@postgresql.org
Date: 2024-05-07T17:44:16Z
Lists: pgsql-hackers
Nathan Bossart <nathandbossart@gmail.com> writes:
> Okay, so are we okay to back-patch something like v1?  Or should we also
> return NULL for other sessions' temporary schemas on primaries?  That would
> change the condition to something like

> 	char relpersist = seqrel->rd_rel->relpersistence;

> 	if (relpersist == RELPERSISTENCE_PERMANENT ||
> 		(relpersist == RELPERSISTENCE_UNLOGGED && !RecoveryInProgress()) ||
> 		!RELATION_IS_OTHER_TEMP(seqrel))
> 	{
> 		...
> 	}

Should be AND'ing not OR'ing the !TEMP condition, no?  Also I liked
your other formulation of the persistence check better.

> I personally think that would be fine to back-patch since pg_sequences
> already filters it out anyway.

+1 to include that, as it offers a defense if someone invokes this
function directly.  In HEAD we could then rip out the test in the
view.

BTW, I think you also need something like

-	int64		result;
+	int64		result = 0;

Your compiler may not complain about result being possibly
uninitialized, but IME others will.

			regards, tom lane



Commits

  1. Remove redundant privilege check from pg_sequences system view.

  2. Fix pg_sequence_last_value() for unlogged sequences on standbys.