BUG #16018: pg_sequence_last_value() doesn't give results for owners

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: rob(at)xzilla(dot)net
Subject: BUG #16018: pg_sequence_last_value() doesn't give results for owners
Date: 2019-09-23 21:45:49
Message-ID: 16018-e617465560d648c5@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16018
Logged by: Robert Treat
Email address: rob(at)xzilla(dot)net
PostgreSQL version: 11.5
Operating system: osx
Description:

I think there is a bug of sorts with pg_sequence_last_value(), in that the
security checks prevent a superuser (or owner) from seeing the last_value of
a sequence by way of this function. That seems like a use case that should
be supported (and since it isn't, it causes problems for a lot of other use
cases). As an example:

postgres(at)54321:pagila=# create sequence x;
CREATE SEQUENCE

postgres(at)54321:pagila=# select pg_sequence_last_value('x'::regclass);
pg_sequence_last_value
------------------------

(1 row)

postgres(at)54321:pagila=# select * from x;
last_value | log_cnt | is_called
------------+---------+-----------
1 | 0 | f
(1 row)

postgres(at)54321:pagila=# select * from pg_sequences where sequencename =
'x';
-[ RECORD 1 ]-+--------------------
schemaname | public
sequencename | x
sequenceowner | postgres
data_type | bigint
start_value | 1
min_value | 1
max_value | 9223372036854775807
increment_by | 1
cycle | f
cache_size | 1
last_value |

Related, has_sequence_privilege() seems to indicate that this should all
work:

postgres(at)54321:pagila=# select has_sequence_privilege('x'::regclass,
'SELECT,USAGE'::text);
has_sequence_privilege
------------------------
t
(1 row)

The backend code for pg_sequence_last_value is checking this:
if (pg_class_aclcheck(relid, GetUserId(), ACL_SELECT | ACL_USAGE) !=
ACLCHECK_OK)

Robert Treat
https://xzilla.net

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2019-09-23 22:33:46 Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners
Previous Message Orr, James 2019-09-23 14:50:36 Query tool won't load