Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtL04-0008U3-Aj for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2013 16:29:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TtL03-0003Zq-Fa for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2013 16:29:03 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtL02-0003Zk-2m for pgsql-bugs@postgresql.org; Thu, 10 Jan 2013 16:29:02 +0000 Received: from smtp.technocon.com ([213.206.227.133]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtKzz-0002KI-66 for pgsql-bugs@postgresql.org; Thu, 10 Jan 2013 16:29:01 +0000 Received: from mail.technocon.com (meel.technocon.local [10.2.0.2]) by smtp.technocon.com (Postfix) with ESMTP id B0ABAA0E78; Thu, 10 Jan 2013 17:28:54 +0100 (CET) Received: from meel (localhost [127.0.0.1]) by mail.technocon.com (Postfix) with ESMTP id A5ADF33A2B5; Thu, 10 Jan 2013 17:28:54 +0100 (CET) Received: from localhost ([127.0.0.1]) by meel with SMTP ID 646; Thu, 10 Jan 2013 17:28:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.technocon.com (Postfix) with ESMTP id 754C733A2B6; Thu, 10 Jan 2013 17:28:54 +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 V0BNhiuhz9O8; Thu, 10 Jan 2013 17:28:51 +0100 (CET) Received: from meel.technocon.local (localhost [127.0.0.1]) by mail.technocon.com (Postfix) with ESMTP id B7A7933A2B5; Thu, 10 Jan 2013 17:28:51 +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:28:51 +0100 Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=_3NKXRaiSjAptBVaBzzmhlYgWPKiT5j+n46HLs45u4lg5sdb3" 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. --=_3NKXRaiSjAptBVaBzzmhlYgWPKiT5j+n46HLs45u4lg5sdb3 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Tom,=0D=0A=0D=0A=C2=A0=0D=0AThanks for the answer. I will try to fix t= he problem via the catalog. As for how I did this.. I hope I can give you= a full walkthough:=0D=0A=0D=0A=C2=A0=0D=0A- We've had a paritioned table= with 1 primary key, and two foreign keys (one of them has in index). The= re were about three partions (all made via a trigger on the mother table=0D= =0A=0D=0A- We wanted to de-parition this table, so I did:=0D=0A=0D=0ASELE= CT * INTO new_table FROM old_table=0D=0A=0D=0A- then made the new primary= key,=0D=0A=0D=0A- made it use the old sequence of old_table,=0D=0A=0D=0A= - created a new index of the foreign keys=0D=0A=0D=0A- renamed old_table = to old_table_tmp=0D=0A=0D=0A- renamed new_table to old_table=0D=0A=0D=0A-= removed the paritions of old_table_tmp (previously old_table)=0D=0A=0D=0A= - tried removing old_table_tmp=0D=0A=0D=0A=C2=A0=0D=0AAnd then I tied all= the things I described earlier. I hope this helps. As I said, I did this= in a similar way for another table without problems, but I'm not sure if= I did everything in the exact same order.=0D=0A=0D=0A=C2=A0=0D=0AKind re= gards,=0D=0A=0D=0A=C2=A0=0D=0AChristiaan=0D=0A=0D=0A=C2=A0=0D=0A-----Orig= inal message-----=0D=0AFrom:Tom Lane =0D=0ASent:Thu 10= -01-2013 17:10=0D=0ASubject:Re: [BUGS] BUG #7802: Cannot drop table becau= se of dependant sequence, but there is link to sequence=0D=0ATo:Christiaa= n Willemsen ;=20=0D=0ACC:pgsql-bugs@postgresql.= org;=20=0D=0Acwillemsen@technocon.com writes:=0D=0A> I have a table 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..=20=0D=0A= =0D=0A> So, now when I drop the table is sais:=0D=0A=0D=0A> ERROR: =C2=A0= cannot drop table old_table because other objects depend on it=0D=0A> DET= AIL: =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 de= pendent objects too.=0D=0A=0D=0A> But clearly, that is not the case... Th= is was however the case. This table=0D=0A> was a partitioned table. I mad= e a copy of the table to de-partition it, and=0D=0A> reused the old seque= nce of the new table, then removed the sequence from the=0D=0A> old table= id. So for some reason Postgresql still thinks that the DEFAULT of=0D=0A= > this id is still connected to the sequence. I already tried changing th= e=0D=0A> DEFAULT, truncate the table, drop all other columns, remove cons= traints and=0D=0A> indexes, vacuum full, basically all I could 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 def= initely a bug that you ended up with a=0D=0Abogus dependency, but without= a clearer understanding of the process=0D=0AI don't think we can find th= e bug.=0D=0A=0D=0AAs for getting out of the problem, what you need to do = is manually=0D=0Aremove the appropriate item in the pg_depend catalog. =C2= =A0To do that,=0D=0Afirst find out the OID of the pg_attrdef entry for ta= ble 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 that row. =C2=A0(To= be totally correct,=0D=0Athis recipe would need to also check classid an= d refclassid, but=0D=0Athe odds of collisions on both OIDs 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 carefully.)=0D=0A=0D=0A= The first part of that would go like this:=0D=0Aselect oid from pg_attrde= f where adrelid =3D 'old_table'::regclass;=0D=0A(you should 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'r= e doing here, take a=0D=0Alook at the descriptions of these catalogs in=0D= =0Ahttp://www.postgresql.org/docs/9.1/static/catalogs.html=0D=0A=0D=0AIf = this all sounds too scary, a dump-and-restore would get rid of=0D=0Athe p= roblem too.=0D=0A=0D=0Aregards, tom lane=0D=0A --=_3NKXRaiSjAptBVaBzzmhlYgWPKiT5j+n46HLs45u4lg5sdb3 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,

 

Thank= s for the answer. I will try to fix the problem via the catalog. As for h= ow I did this.. I hope I can give you a full walkthough:

 

=

- We've had a paritioned table with 1 primary key, and two foreign= keys (one of them has in index). There were about three partions (all ma= de via a trigger on the mother table

- We wanted to de-parition thi= s table, so I did:

SELECT * INTO new_t= able FROM old_table

- then made the new primary key,

- made i= t use the old sequence of old_table,

- created a new index of the f= oreign keys

- renamed old_table to old_table_tmp

- renamed ne= w_table to old_table

- removed the paritions of old_table_tmp (prev= iously old_table)

- tried removing old_table_tmp

 

And then I tied all the things I described earlier. I hope this helps. A= s I said, I did this in a similar way for another table without problems,= but I'm not sure if I did everything in the exact same order.

=  

Kind regards,

 

Christiaan

 

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

> CREATE TABLE old_table
> (
= >   id bigint DEFAULT 0
> )

> Thats's i= t..

> So, now when I drop the table is sais:

&g= t; ERROR:  cannot drop table old_table because other objects depend = on it
> DETAIL:  default for table old_table column id depen= ds on sequence
> old_table_id_seq
> HINT:  Use DROP = =2E.. CASCADE to drop the dependent objects too.

> But clea= rly, that is not the case... This was however the case. This table
&= gt; was a partitioned table. I made a copy of the table to de-partition i= t, and
> reused the old sequence of the new table, then removed t= he sequence from the
> old table id. So for some reason Postgresq= l still thinks that the DEFAULT of
> this id is still connected t= o the sequence. I already tried changing the
> DEFAULT, truncate = the table, drop all other columns, remove constraints and
> index= es, 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's definitely a bug that y= ou ended up with a
bogus dependency, but without a clearer understan= ding of the process
I don't think we can find the bug.

As for getting out of the problem, what you need to do is manually
remove the appropriate item in the pg_depend catalog.  To do that,<= br />first find out the OID of the pg_attrdef entry for table old_tablecolumn id, then find out the OID of the sequence, then look for
= a pg_depend entry with objid =3D first OID and refobjid =3D second OID.Then, as superuser, manually DELETE that row.  (To be totally co= rrect,
this recipe would need to also check 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_depend entry that seems to fit th= e
bill, then you need to tread more carefully.)

The first= part of that would go like this:
=09select oid from pg_attrdef wher= e adrelid =3D 'old_table'::regclass;
(you should get only on= e hit, if there's only one column left with
a default; otherwise= look at adnum as well).  The second part is
=09select 'old= _table_id_seq'::regclass::oid;

If you'd like to unders= tand what it is you're doing here, take a
look at the descriptio= ns of these catalogs in
http://www.postgresql.org/docs/9.1/static/ca= talogs.html

If this all sounds too scary, a dump-and-restore w= ould get rid of
the problem too.

=09=09=09regards, tom la= ne
=0A=0A --=_3NKXRaiSjAptBVaBzzmhlYgWPKiT5j+n46HLs45u4lg5sdb3--