Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCXpq-0005aM-A9 for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2019 23:33:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iCXpn-0003Ee-Bf for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2019 23:33:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCXpm-0003EX-Tr for pgsql-bugs@lists.postgresql.org; Mon, 23 Sep 2019 23:33:35 +0000 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iCXpk-0007Tt-9D for pgsql-bugs@lists.postgresql.org; Mon, 23 Sep 2019 23:33:33 +0000 Received: by mail-ot1-x342.google.com with SMTP id 21so13695874otj.11 for ; Mon, 23 Sep 2019 16:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xzilla-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc :content-transfer-encoding; bh=VWBkpZQ+th3UyQXENsVCd+PvBiwmroQJnN+4FkA05xE=; b=rDesGsQ6JtJ5vgBlZgBsN8Zp9vZLMTtHj5KxD4fX7k+kW1fLMkD0TTOT/yDE7GyBi7 ywISJPAloJ/+PYuCE1gIwEt1fCiztM43w9Ndhf/7+eHjp/Sf7kg/WQoUXitWA722rCTE /oKKrGz7h87Wfbn2TNyIfp21pIvuWsjP4m/iAxmisYMBALTBE1suSz1nZo57p6M9luo7 +szOJCFUbF/T3DG4ewyk4J0QP5GFByocvqmEZT5/xxi8LVVumgfNv6Ndp2l9/sGczPwM U/nYDaAcW5xM0p3fyYL/WXlaKXQaa1gkGDzSL3MzHgWHAetb2LF+HgfSoKmeI3QZM5eQ R9xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:cc:content-transfer-encoding; bh=VWBkpZQ+th3UyQXENsVCd+PvBiwmroQJnN+4FkA05xE=; b=ZQEHeXDTj7VlzDCmgT12vNoV9wjrgYBSR3xU167Zu1UB/Jn4X+KxpKGtbOD7eiaBxJ A7FGdroxs4YkO8Bi5egFa0rZ02LmCsYbL6zZIE0ZL/sSMKzXNZlgD4uhDdwj6Byy8UF9 eXanJEVd6zDOrp0za6Vy8ETvNDFQawyCqt8Xq7gbrMSSAxk6x1oGnZ7yXt3GFw2CR/ir 0KjzmWTMXbuOblEUJpqi6mQas18WwvdVSPTaVF11sZM1huWcDU5/3xbj5qolSZ4iVMP5 SDt6zLlKAgwjP9iAazF6zLroOjgmusqHEAj2UiVkSdQazIR4/WvDcQk9oPsZcq/29tQZ 2NGQ== X-Gm-Message-State: APjAAAXhUuUTu8hJs9d4sAdFcTHcqzu6kSu/R8b/89/6njJvyEzEqfQT p+8+Ne7YfBnL+LL09Dv2xyIWzsxxMmXqBsJDEuxgW/sfzAM= X-Google-Smtp-Source: APXvYqwPBprJsBJiXAQ6rmSMhOlh7fCO59Uk2qdNGScGfqQLPzVLWEYpEidRLxkgdV1rGG1etp5lwW+9vRd+mESsBN4= X-Received: by 2002:a05:6830:1617:: with SMTP id g23mr166818otr.366.1569281611511; Mon, 23 Sep 2019 16:33:31 -0700 (PDT) MIME-Version: 1.0 References: <16018-e617465560d648c5@postgresql.org> In-Reply-To: From: Robert Treat Date: Mon, 23 Sep 2019 19:34:03 -0400 Message-ID: Subject: Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners Cc: PostgreSQL mailing lists Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Sep 23, 2019 at 6:34 PM David G. Johnston wrote: > > On Mon, Sep 23, 2019 at 2:46 PM PG Bug reporting form wrote: >> >> The following bug has been logged on the website: >> >> Bug reference: 16018 >> Logged by: Robert Treat >> Email address: rob@xzilla.net >> PostgreSQL version: 11.5 >> Operating system: osx >> Description: >> >> I think there is a bug of sorts with pg_sequence_last_value(), in that t= he >> security checks prevent a superuser (or owner) from seeing the last_valu= e of >> a sequence by way of this function. That seems like a use case that shou= ld >> be supported (and since it isn't, it causes problems for a lot of other = use >> cases). As an example: >> >> postgres@54321:pagila=3D# create sequence x; >> CREATE SEQUENCE >> >> postgres@54321:pagila=3D# select pg_sequence_last_value('x'::regclass); >> pg_sequence_last_value >> ------------------------ >> >> (1 row) >> > > From pg_sequences: > """ > last_value bigint The last sequence value written to disk. If caching is = used, this value can be greater than the last value handed out from the seq= uence. Null if the sequence has not been read from yet. Also, if the curren= t user does not have USAGE or SELECT privilege on the sequence, the value i= s null. > """ > Ah, I hadn't really been working with pg_sequences, and there is no documentation on pg_sequence_last_value, but since the former is implemented using the latter, I guess it is safe to assume those limitations would also apply to the underlying function. > The null in the example seems to be due to the first condition (not been = read from) not the second (privileges). > Ugh... the situation is further complicated in that setval seems to cause a read, but alter sequence restart does not. Fun. >> postgres@54321:pagila=3D# select * from x; >> last_value | log_cnt | is_called >> ------------+---------+----------- >> 1 | 0 | f >> (1 row) > > > The "last_value" on the sequence object has a different definition than t= he one on the relatively new pg_sequences catalog. > Any chance you have a pointer to documentation on the differences? I originally wanted to provide access to the information from the sequence object, but that idea has been fading quite quickly. > I'm not seeing where a bug has been shown to exist though I'll agree that= the quick reading of the documentation leaves some level of confusion. > This might still just be a case of my simplified example being deficient, but this gives me more to work with; hopefully enough to either solve my problem or come up with a better test scenario. Thanks for the response. Robert Treat https://xzilla.net