From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | DROP OWNED BY doesn't work |
Date: | 2006-08-19 22:13:42 |
Message-ID: | 12807.1156025622@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
So I was fooling with making serial sequences be auto rather than internal
dependencies of their columns, and the regression tests blew up on me:
*** ./expected/dependency.out Mon Nov 21 07:49:33 2005
--- ./results/dependency.out Sat Aug 19 17:46:55 2006
***************
*** 109,113 ****
--- 109,117 ----
DROP USER regression_user2;
ERROR: role "regression_user2" cannot be dropped because some objects depend on it
DROP OWNED BY regression_user2, regression_user0;
+ NOTICE: default for table deptest column a depends on sequence deptest_a_seq
+ ERROR: cannot drop sequence deptest_a_seq because other objects depend on it
DROP USER regression_user2;
+ ERROR: role "regression_user2" cannot be dropped because some objects depend on it
DROP USER regression_user0;
+ ERROR: role "regression_user0" cannot be dropped because some objects depend on it
On investigation I find that DROP OWNED BY tries to drop objects in the
more-or-less-random order that they appear in pg_shdepend. This doesn't
work, at least not without CASCADE. I think people should be able to
assume that DROP OWNED BY RESTRICT will drop all the target users'
objects so long as there are not objects owned by other users that
depend on them.
There's a hack in there now that tries to special-case this for INTERNAL
dependencies, but I think it's misguided. You can run into the problem
without any internal or auto dependencies:
regression=# create user foo;
CREATE ROLE
regression=# \c - foo
You are now connected to database "regression" as user "foo".
regression=> create table tt1 (f1 int);
CREATE TABLE
regression=> create table tt2 (f1 int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "tt2_pkey" for table "tt2"
CREATE TABLE
regression=> alter table tt1 add foreign key (f1) references tt2;
ALTER TABLE
regression=> drop owned by foo;
NOTICE: constraint tt1_f1_fkey on table tt1 depends on table tt2
ERROR: cannot drop table tt2 because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too.
regression=>
I think a correct solution probably requires making a list of all
objects to delete by scanning pg_shdepend and then starting to
delete 'em, using the list as "oktodelete" context similar to the
way that dependency.c handles auto/internal objects.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2006-08-19 22:41:49 | Re: BugTracker (Was: Re: 8.2 features status) |
Previous Message | Tom Lane | 2006-08-19 20:01:21 | Re: pg_dump versus SERIAL, round N |
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2006-08-19 22:57:31 | Re: DROP OWNED BY doesn't work |
Previous Message | Tom Lane | 2006-08-19 12:50:41 | Re: [PATCHES] selecting large result sets in psql using |