Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtLCN-0000GH-2t for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2013 16:41:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TtLCM-0006H5-Fy for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2013 16:41:46 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtLCL-0006H0-Qk for pgsql-bugs@postgresql.org; Thu, 10 Jan 2013 16:41:45 +0000 Received: from smtp.technocon.com ([213.206.227.133]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtLCF-0003Gn-4m for pgsql-bugs@postgresql.org; Thu, 10 Jan 2013 16:41:45 +0000 Received: from mail.technocon.com (meel.technocon.local [10.2.0.2]) by smtp.technocon.com (Postfix) with ESMTP id 78D7CA0E92; Thu, 10 Jan 2013 17:41:38 +0100 (CET) Received: from meel (localhost [127.0.0.1]) by mail.technocon.com (Postfix) with ESMTP id 6B63533A2B5; Thu, 10 Jan 2013 17:41:38 +0100 (CET) Received: from localhost ([127.0.0.1]) by meel with SMTP ID 875; Thu, 10 Jan 2013 17:41:38 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.technocon.com (Postfix) with ESMTP id 3ACBD33A2B6; Thu, 10 Jan 2013 17:41:38 +0100 (CET) Received: from mail.technocon.com ([127.0.0.1]) by localhost (meel.technocon.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CpaQtghSvIME; Thu, 10 Jan 2013 17:41:31 +0100 (CET) Received: from meel.technocon.local (localhost [127.0.0.1]) by mail.technocon.com (Postfix) with ESMTP id C431933A2B5; Thu, 10 Jan 2013 17:41:31 +0100 (CET) Subject: Re: BUG #7802: Cannot drop table because of dependant sequence, but there is link to sequence From: =?utf-8?Q?Christiaan_Willemsen?= To: =?utf-8?Q?Tom_Lane?= Cc: =?utf-8?Q?pgsql-bugs=40postgresql=2Eorg?= Date: Thu, 10 Jan 2013 17:41:31 +0100 Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=_XYKXZF0Dci9tkd7Nc+UrlEpiPyJ85+cM3W8yRF3hjttmBEUh" X-Priority: 3 (Normal) X-Mailer: Zarafa 7.0.5-31880 Message-Id: X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. Your mail reader does not understand MIME message format. --=_XYKXZF0Dci9tkd7Nc+UrlEpiPyJ85+cM3W8yRF3hjttmBEUh Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Tom,=0D=0A=0D=0A=C2=A0=0D=0ABack again ;) I just checked pg_depend, an= d according to it there is no relation between in de table and the sequen= ce... There is however a relation between the new table and the old seque= nce (as expected). So this is sill a mistery.=0D=0A=0D=0A=C2=A0=0D=0A=20=0D= =0ABy the way, I can't to a dump restore, it would take hours and this is= a production system. Otherwise I might try dropping the sequence, droppi= ng the old_table, and the just recreate the sequence. But that's somethin= g I would not like to do if it can be avoided.=0D=0A=0D=0A=C2=A0=0D=0A=C2= =A0=0D=0AKind regards,=0D=0A=0D=0A=C2=A0=0D=0AChristiaan=0D=0A=C2=A0=0D=0A= -----Original message-----=0D=0AFrom:Tom Lane =0D=0ASe= nt:Thu 10-01-2013 17:10=0D=0ASubject:Re: [BUGS] BUG #7802: Cannot drop ta= ble because of dependant sequence, but there is link to sequence=0D=0ATo:= Christiaan Willemsen ;=20=0D=0ACC:pgsql-bugs@po= stgresql.org;=20=0D=0Acwillemsen@technocon.com writes:=0D=0A> I have a ta= ble that currently looks like this:=0D=0A=0D=0A> CREATE TABLE old_table=0D= =0A> (=0D=0A> =C2=A0 id bigint DEFAULT 0=0D=0A> )=0D=0A=0D=0A> Thats's it= =2E.=20=0D=0A=0D=0A> So, now when I drop the table is sais:=0D=0A=0D=0A> = ERROR: =C2=A0cannot drop table old_table because other objects depend on = it=0D=0A> DETAIL: =C2=A0default for table old_table column id depends on = sequence=0D=0A> old_table_id_seq=0D=0A> HINT: =C2=A0Use DROP ... CASCADE = to drop the dependent objects too.=0D=0A=0D=0A> But clearly, that is not = the case... This was however the case. This table=0D=0A> was a partitione= d table. I made a copy of the table to de-partition it, and=0D=0A> reused= the old sequence of the new table, then removed the sequence from the=0D= =0A> old table id. So for some reason Postgresql still thinks that the DE= FAULT of=0D=0A> this id is still connected to the sequence. I already tri= ed changing the=0D=0A> DEFAULT, truncate the table, drop all other column= s, remove constraints and=0D=0A> indexes, vacuum full, basically all I co= uld think of. Still, it wont work.=0D=0A=0D=0ACan you reconstruct exactly= what you did there=3F =C2=A0If it was all supported=0D=0AALTER commands,= then it's definitely a bug that you ended up with a=0D=0Abogus dependenc= y, but without a clearer understanding of the process=0D=0AI don't think = we can find the bug.=0D=0A=0D=0AAs for getting out of the problem, what y= ou need to do is manually=0D=0Aremove the appropriate item in the pg_depe= nd catalog. =C2=A0To do that,=0D=0Afirst find out the OID of the pg_attrd= ef entry for table old_table=0D=0Acolumn id, then find out the OID of the= sequence, then look for=0D=0Aa pg_depend entry with objid =3D first OID = and refobjid =3D second OID.=0D=0AThen, as superuser, manually DELETE tha= t row. =C2=A0(To be totally correct,=0D=0Athis recipe would need to also = check classid and refclassid, but=0D=0Athe odds of collisions on both OID= s are so low I'm omitting that.=0D=0AIf you find more than one pg_depend = entry that seems to fit the=0D=0Abill, then you need to tread more carefu= lly.)=0D=0A=0D=0AThe first part of that would go like this:=0D=0Aselect o= id from pg_attrdef where adrelid =3D 'old_table'::regclass;=0D=0A(you sho= uld get only one hit, if there's only one column left with=0D=0Aa default= ; otherwise look at adnum as well). =C2=A0The second part is=0D=0Aselect = 'old_table_id_seq'::regclass::oid;=0D=0A=0D=0AIf you'd like to understand= what it is you're doing here, take a=0D=0Alook at the descriptions of th= ese catalogs in=0D=0Ahttp://www.postgresql.org/docs/9.1/static/catalogs.h= tml=0D=0A=0D=0AIf this all sounds too scary, a dump-and-restore would get= rid of=0D=0Athe problem too.=0D=0A=0D=0Aregards, tom lane=0D=0A --=_XYKXZF0Dci9tkd7Nc+UrlEpiPyJ85+cM3W8yRF3hjttmBEUh Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable =0A=0A =0A =0A RE: [BUGS] BU= G #7802: Cannot drop table because of dependant sequence, but there is li= nk to sequence=0A =0A=0A=0A

Hi Tom,

 

Back = again ;) I just checked pg_depend, and according to it there is no relati= on between in de table and the sequence... There is however a relation be= tween the new table and the old sequence (as expected). So this is sill a= mistery.

 

By the way, I can't to a dump restore, it wo= uld take hours and this is a production system. Otherwise I might try dro= pping the sequence, dropping the old_table, and the just recreate the seq= uence. But that's something I would not like to do if it can be avoid= ed.

 

 

Kind regards,

 

Christiaan
 

-----Original message-----=
From:=09Tom Lane <tgl@sss.pgh.pa.us>
Sent:=09Thu 10-01-2013 17:10
Subject:=09Re: [BUGS] BUG #7802: Cannot drop table because of dependant sequence= , but there is link to sequence
To:=09Christiaan Wi= llemsen <cwillemsen@technocon.com>;
CC:=09pg= sql-bugs@postgresql.org;
cwillemsen@technocon.com writes:
>= I have a table that currently looks like this:

> CREATE TA= BLE old_table
> (
>   id bigint DEFAULT 0
> = )

> Thats's it..

> So, now when I drop t= he table is sais:

> ERROR:  cannot drop table old_tabl= e because other objects depend on it
> DETAIL:  default for = table old_table column id depends on sequence
> old_table_id_seq<= br />> HINT:  Use DROP ... CASCADE to drop the dependent objects = too.

> But clearly, that is not the case... This was howeve= r the case. This table
> was a partitioned table. I made a copy o= f the table to de-partition it, and
> reused the old sequence of = the new table, then removed the sequence from the
> old table id.= So for some reason Postgresql still thinks that the DEFAULT of
>= this id is still connected to the sequence. I already tried changing the=
> DEFAULT, truncate the table, drop all other columns, remove co= nstraints and
> indexes, vacuum full, basically all I could think= of. Still, it wont work.

Can you reconstruct exactly what you= did there=3F  If it was all supported
ALTER commands, then it&= #39;s definitely a bug that you ended up with a
bogus dependency, bu= t without a clearer understanding of the process
I don't think w= e can find the bug.

As for getting out of the problem, what yo= u need to do is manually
remove the appropriate item in the pg_depen= d catalog.  To do that,
first find out the OID of the pg_attrde= f entry for table old_table
column id, then find out the OID of the = sequence, then look for
a pg_depend entry with objid =3D first OID a= nd refobjid =3D second OID.
Then, as superuser, manually DELETE that= row.  (To be totally correct,
this recipe would need to also c= heck classid and refclassid, but
the odds of collisions on both OIDs= are so low I'm omitting that.
If you find more than one pg_depe= nd entry that seems to fit the
bill, then you need to tread more car= efully.)

The first part of that would go like this:
=09se= lect oid from pg_attrdef where adrelid =3D 'old_table'::regclass;=
(you should get only one hit, if there's only one column left w= ith
a default; otherwise look at adnum as well).  The second pa= rt is
=09select 'old_table_id_seq'::regclass::oid;

If you'd like to understand what it is you're doing here, take = a
look at the descriptions of these catalogs in
http://www.post= gresql.org/docs/9.1/static/catalogs.html

If this all sounds to= o scary, a dump-and-restore would get rid of
the problem too.
<= br />=09=09=09regards, tom lane
=0A=0A --=_XYKXZF0Dci9tkd7Nc+UrlEpiPyJ85+cM3W8yRF3hjttmBEUh--