From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Robert Haas <robertmhaas@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Jason Petersen <jason@citusdata.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: Concurrent ALTER SEQUENCE RESTART Regression
Date: Tue, 13 Jun 2017 15:04:35 -0400
Message-ID: <bbb46016-21f4-6cc3-ae2a-eefed97da2d2@2ndquadrant.com> (raw)
In-Reply-To: <CA+TgmoZne41kmc7bT3LH8r4M2hmxzqK33nPXGhXQmfh9ar4ZZQ@mail.gmail.com>
References: <CAB7nPqRUXMvo5xy9cLFyhuHErN9WVCckuKaUbJpxPGBzxqVFdw@mail.gmail.com>
<CAB7nPqRev_wK4k39hQBpQZRQ17v29guxfobnnmTYT_-hUU67BA@mail.gmail.com>
<16ed823b-44e4-dc51-3da9-a3d66b71ed5c@2ndquadrant.com>
<CAB7nPqSDhVn6+yrteh+K4Z58F93dQd-S40N5HL6HQsFMYccL6w@mail.gmail.com>
<9240bf94-44a8-671a-27bd-500eb868226a@2ndquadrant.com>
<20170426174813.slaq6mka7v6xohap@alap3.anarazel.de>
<CAB7nPqR_K5pSnP9WUyvgn_76Qurz7BtJZgF6tL1+3cFwxwj68w@mail.gmail.com>
<99a009ea-1797-5b82-f3d3-eb4a5a8eb5dc@2ndquadrant.com>
<20170427011258.2tpv55b6leqe2uva@alap3.anarazel.de>
<1e5bb916-fd58-3995-851b-6875c6dd73eb@2ndquadrant.com>
<20170427055211.jc5tblpguawbeqjq@alap3.anarazel.de>
<CA+TgmoZne41kmc7bT3LH8r4M2hmxzqK33nPXGhXQmfh9ar4ZZQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 5/2/17 12:45, Robert Haas wrote:
> Another thing that doesn't look so good about AlterSequence is that it
> uses RangeVarGetRelid() instead of RangeVarGetsRelidExtended() with
> RangeVarCallbackOwnsRelation or some derivative thereof. That of
> course means you can obstruct access to a sequence you don't own.
Here is a patch for this. Note that this is old code, but it seems
worth fixing now while we're at it.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:0001-Use-RangeVarGetRelidExtended-in-AlterSequence.patch (text/plain, 3.0K) download
From ec6884c189849a10b39d2ea953a962dce34a23fa Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 13 Jun 2017 14:58:17 -0400
Subject: [PATCH] Use RangeVarGetRelidExtended() in AlterSequence()
This allows us to combine the opening and the ownership check.
Reported-by: Robert Haas <robertmhaas@gmail.com>
---
src/backend/commands/sequence.c | 16 +++++++---------
src/test/regress/expected/sequence.out | 4 ++--
src/test/regress/sql/sequence.sql | 2 +-
3 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.cindex 2d820e5ceb..031bbc874d 100644--- a/src/backend/commands/sequence.c+++ b/src/backend/commands/sequence.c@@ -429,10 +429,13 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
HeapTuple seqtuple;
HeapTuple newdatatuple;
- /* Open and lock sequence. */- relid = RangeVarGetRelid(stmt->sequence,- ShareRowExclusiveLock,- stmt->missing_ok);+ /* Open and lock sequence, and check for ownership along the way. */+ relid = RangeVarGetRelidExtended(stmt->sequence,+ ShareRowExclusiveLock,+ stmt->missing_ok,+ false,+ RangeVarCallbackOwnsRelation,+ NULL);
if (relid == InvalidOid)
{
ereport(NOTICE,
@@ -443,11 +446,6 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
init_sequence(relid, &elm, &seqrel);
- /* allow ALTER to sequence owner only */- if (!pg_class_ownercheck(relid, GetUserId()))- aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,- stmt->sequence->relname);-
rel = heap_open(SequenceRelationId, RowExclusiveLock);
seqtuple = SearchSysCacheCopy1(SEQRELID,
ObjectIdGetDatum(relid));
diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.outindex 16c12f3434..a43b52cfc1 100644--- a/src/test/regress/expected/sequence.out+++ b/src/test/regress/expected/sequence.out@@ -307,8 +307,8 @@ DROP SEQUENCE myseq2;
ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
NOTICE: relation "sequence_test2" does not exist, skipping
-ALTER SEQUENCE pg_class CYCLE; -- error, not a sequence-ERROR: "pg_class" is not a sequence+ALTER SEQUENCE serialTest1 CYCLE; -- error, not a sequence+ERROR: "serialtest1" is not a sequence
CREATE SEQUENCE sequence_test2 START WITH 32;
CREATE SEQUENCE sequence_test4 INCREMENT BY -1;
SELECT nextval('sequence_test2');
diff --git a/src/test/regress/sql/sequence.sql b/src/test/regress/sql/sequence.sqlindex d53e33d779..b41c5a753d 100644--- a/src/test/regress/sql/sequence.sql+++ b/src/test/regress/sql/sequence.sql@@ -172,7 +172,7 @@ CREATE TEMP TABLE t1 (
ALTER SEQUENCE IF EXISTS sequence_test2 RESTART WITH 24
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
-ALTER SEQUENCE pg_class CYCLE; -- error, not a sequence+ALTER SEQUENCE serialTest1 CYCLE; -- error, not a sequence
CREATE SEQUENCE sequence_test2 START WITH 32;
CREATE SEQUENCE sequence_test4 INCREMENT BY -1;
--
2.13.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: peter.eisentraut@2ndquadrant.com, robertmhaas@gmail.com, andres@anarazel.de, michael.paquier@gmail.com, jason@citusdata.com
Subject: Re: Concurrent ALTER SEQUENCE RESTART Regression
In-Reply-To: <bbb46016-21f4-6cc3-ae2a-eefed97da2d2@2ndquadrant.com>
References: <CAB7nPqRUXMvo5xy9cLFyhuHErN9WVCckuKaUbJpxPGBzxqVFdw@mail.gmail.com> <CAB7nPqRev_wK4k39hQBpQZRQ17v29guxfobnnmTYT_-hUU67BA@mail.gmail.com> <16ed823b-44e4-dc51-3da9-a3d66b71ed5c@2ndquadrant.com> <CAB7nPqSDhVn6+yrteh+K4Z58F93dQd-S40N5HL6HQsFMYccL6w@mail.gmail.com> <9240bf94-44a8-671a-27bd-500eb868226a@2ndquadrant.com> <20170426174813.slaq6mka7v6xohap@alap3.anarazel.de> <CAB7nPqR_K5pSnP9WUyvgn_76Qurz7BtJZgF6tL1+3cFwxwj68w@mail.gmail.com> <99a009ea-1797-5b82-f3d3-eb4a5a8eb5dc@2ndquadrant.com> <20170427011258.2tpv55b6leqe2uva@alap3.anarazel.de> <1e5bb916-fd58-3995-851b-6875c6dd73eb@2ndquadrant.com> <20170427055211.jc5tblpguawbeqjq@alap3.anarazel.de> <CA+TgmoZne41kmc7bT3LH8r4M2hmxzqK33nPXGhXQmfh9ar4ZZQ@mail.gmail.com> <bbb46016-21f4-6cc3-ae2a-eefed97da2d2@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox