pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedDROP CASCADE transitive dependencies
5+ messages / 4 participants
[nested] [flat]
* DROP CASCADE transitive dependencies
@ 2018-12-03 18:13 C GG <cgg0007@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: C GG @ 2018-12-03 18:13 UTC (permalink / raw)
To: pgsql-general
...PostgreSQL 9.5...
`DROP SCHEMA blah;` reports all the dependent objects and advises to `DROP
SCHEMA blah CASCADE;` ...
Will DROP ... CASCADE traverse the entire dependency tree for each of the
dependent objects (potentially dropping something unintended), or will it
stop at the first level and balk at any new transitive dependencies?
All the dependent objects listed by `DROP SCHEMA blah` are fair game to be
dropped, but if I add CASCADE I don't necessarily want to have it go beyond
that initial list without my say-so.
The alternative is to drop each one in the list individually without
CASCADE-- a tedious task I'd rather short-cut, but in a non-reckless manner
;) ...
CG
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: DROP CASCADE transitive dependencies
@ 2018-12-03 18:26 Tom Lane <tgl@sss.pgh.pa.us>
parent: C GG <cgg0007@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2018-12-03 18:26 UTC (permalink / raw)
To: C GG <cgg0007@gmail.com>; +Cc: pgsql-general
C GG <cgg0007@gmail.com> writes:
> ...PostgreSQL 9.5...
> `DROP SCHEMA blah;` reports all the dependent objects and advises to `DROP
> SCHEMA blah CASCADE;` ...
> Will DROP ... CASCADE traverse the entire dependency tree for each of the
> dependent objects (potentially dropping something unintended), or will it
> stop at the first level and balk at any new transitive dependencies?
The former. However, the list of dependencies it's showing you as
potentially dropped already includes transitive dependencies; there
aren't going to be "new" ones unless somebody is adding things
concurrently.
If you're feeling paranoid, you could always do
begin;
drop ... cascade;
and then look at the reported list of objects before deciding whether
to commit or roll back.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: DROP CASCADE transitive dependencies
@ 2018-12-03 19:07 C GG <cgg0007@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 5+ messages in thread
From: C GG @ 2018-12-03 19:07 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
On Mon, Dec 3, 2018 at 1:26 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> C GG <cgg0007@gmail.com> writes:
> > ...PostgreSQL 9.5...
> > `DROP SCHEMA blah;` reports all the dependent objects and advises to
> `DROP
> > SCHEMA blah CASCADE;` ...
>
> > Will DROP ... CASCADE traverse the entire dependency tree for each of the
> > dependent objects (potentially dropping something unintended), or will it
> > stop at the first level and balk at any new transitive dependencies?
>
> The former. However, the list of dependencies it's showing you as
> potentially dropped already includes transitive dependencies; there
> aren't going to be "new" ones unless somebody is adding things
> concurrently.
>
That's good news!
>
> If you're feeling paranoid, you could always do
>
> begin;
> drop ... cascade;
>
> and then look at the reported list of objects before deciding whether
> to commit or roll back.
>
Me, paranoid? Yes. Yes I am.
So I did that--
data=# begin;
BEGIN
data=# DROP SCHEMA blah CASCADE;
NOTICE: drop cascades to 278 other objects
DETAIL: drop cascades to type blah.timeclock_compute_hours_type
...
and 178 other objects (see server log for list)
data=# rollback;
ROLLBACK
data=#
and I can't see any of the other 178 objects in the server log. I did see
all the deadlock reports because I had left the transaction hanging open
while I went rubbernecking. ;) Maybe my log level isn't detailed enough.
Also-- it is interesting to note that the list that I was shown when I
executed `DROP SCHEMA blah;` is only 100 objects long. So that tells me
that there's 178 other entries I'm not seeing. Where's that tin-foil hat?
Any suggestions for getting the names of the other 178 dependent objects?
>
> regards, tom lane
>
Thanks Tom. I don't say it enough: I _really_ appreciate you and your
consistent excellent contributions to PostgreSQL and to the PostgreSQL
community.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: DROP CASCADE transitive dependencies
@ 2018-12-03 19:38 Pavel Stehule <pavel.stehule@gmail.com>
parent: C GG <cgg0007@gmail.com>
1 sibling, 0 replies; 5+ messages in thread
From: Pavel Stehule @ 2018-12-03 19:38 UTC (permalink / raw)
To: cgg0007@gmail.com; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
po 3. 12. 2018 v 20:07 odesílatel C GG <cgg0007@gmail.com> napsal:
>
>
> On Mon, Dec 3, 2018 at 1:26 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
>> C GG <cgg0007@gmail.com> writes:
>> > ...PostgreSQL 9.5...
>> > `DROP SCHEMA blah;` reports all the dependent objects and advises to
>> `DROP
>> > SCHEMA blah CASCADE;` ...
>>
>> > Will DROP ... CASCADE traverse the entire dependency tree for each of
>> the
>> > dependent objects (potentially dropping something unintended), or will
>> it
>> > stop at the first level and balk at any new transitive dependencies?
>>
>> The former. However, the list of dependencies it's showing you as
>> potentially dropped already includes transitive dependencies; there
>> aren't going to be "new" ones unless somebody is adding things
>> concurrently.
>>
>
> That's good news!
>
>
>>
>> If you're feeling paranoid, you could always do
>>
>> begin;
>> drop ... cascade;
>>
>> and then look at the reported list of objects before deciding whether
>> to commit or roll back.
>>
>
> Me, paranoid? Yes. Yes I am.
>
> So I did that--
>
> data=# begin;
> BEGIN
> data=# DROP SCHEMA blah CASCADE;
> NOTICE: drop cascades to 278 other objects
> DETAIL: drop cascades to type blah.timeclock_compute_hours_type
> ...
> and 178 other objects (see server log for list)
> data=# rollback;
> ROLLBACK
> data=#
>
> and I can't see any of the other 178 objects in the server log. I did see
> all the deadlock reports because I had left the transaction hanging open
> while I went rubbernecking. ;) Maybe my log level isn't detailed enough.
>
> Also-- it is interesting to note that the list that I was shown when I
> executed `DROP SCHEMA blah;` is only 100 objects long. So that tells me
> that there's 178 other entries I'm not seeing. Where's that tin-foil hat?
>
> Any suggestions for getting the names of the other 178 dependent objects?
>
you can use some of mentioned queries
https://wiki.postgresql.org/wiki/Pg_depend_display
https://dba.stackexchange.com/questions/78301/postgresql-dependencies-on-a-schema
dependency is stored in pg_depend query - so you just to iterate over this
table.
Regards
Pavel
>
>>
>> regards, tom lane
>>
>
> Thanks Tom. I don't say it enough: I _really_ appreciate you and your
> consistent excellent contributions to PostgreSQL and to the PostgreSQL
> community.
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: DROP CASCADE transitive dependencies
@ 2018-12-03 20:32 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: C GG <cgg0007@gmail.com>
1 sibling, 0 replies; 5+ messages in thread
From: Alvaro Herrera @ 2018-12-03 20:32 UTC (permalink / raw)
To: C GG <cgg0007@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
On 2018-Dec-03, C GG wrote:
> data=# begin;
> BEGIN
> data=# DROP SCHEMA blah CASCADE;
> NOTICE: drop cascades to 278 other objects
> DETAIL: drop cascades to type blah.timeclock_compute_hours_type
> ...
> and 178 other objects (see server log for list)
> data=# rollback;
> ROLLBACK
> data=#
>
> and I can't see any of the other 178 objects in the server log. I did see
> all the deadlock reports because I had left the transaction hanging open
> while I went rubbernecking. ;) Maybe my log level isn't detailed enough.
If you do DROP without cascade, the objects are going to be listed
in the DETAIL field of the ERROR, so you need to have
log_error_verbosity set to verbose or default; if you have it as terse,
they won't appear in the server log.
If you DROP with CASCADE, the objects would appear in a NOTICE message,
which may be below your log_min_messages. Try with
SET LOCAL log_min_messages TO notice;
in the same transaction, just before the drop.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2018-12-03 20:32 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 18:13 DROP CASCADE transitive dependencies C GG <cgg0007@gmail.com>
2018-12-03 18:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-12-03 19:07 ` C GG <cgg0007@gmail.com>
2018-12-03 19:38 ` Pavel Stehule <pavel.stehule@gmail.com>
2018-12-03 20:32 ` Alvaro Herrera <alvherre@2ndquadrant.com>
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