Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnJox-00CfUg-J5 for pgsql-general@arkaria.postgresql.org; Thu, 21 Mar 2024 14:55:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rnJov-00E6Pe-Lm for pgsql-general@arkaria.postgresql.org; Thu, 21 Mar 2024 14:55:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnJov-00E6PW-9k for pgsql-general@lists.postgresql.org; Thu, 21 Mar 2024 14:55:05 +0000 Received: from smtp6-g21.free.fr ([2a01:e0c:1:1599::15]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnJos-005k2W-Eq for pgsql-general@lists.postgresql.org; Thu, 21 Mar 2024 14:55:05 +0000 Received: from zimbra-e1-02.priv.proxad.net (unknown [172.20.243.240]) by smtp6-g21.free.fr (Postfix) with ESMTP id 6DC44780371; Thu, 21 Mar 2024 15:54:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1711032897; bh=PLNwK3NFjcU1tFAuUXJWpsX8U/9wu7AEpTvGYjejt4Y=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=h8ypxug3kg+EjKx4OvrURpeVgstHIIGTWJ+AgYDf499Zv8pkMeG842j/MLDs7ub/L hkYsoKwE8wsrcI675dNzyjrhtXp3GWkbmOzaJ9fD0xr45aBjgnlPbTjxu4KuBP9U5S yLojanKJke8NZYnGWri1umuKoNTBevugL87VQSDkM8AvhNh/EgTGwBUlvq3ECKLZyR 8pK18Jbcn4K4fyTHKCO6GWOjObj+CVSmJ5MRYFmtpCtPWt1GzHVFMwKKLhxsAy6v6/ GtKR5qn33zUuXFceg9ylmvBsGK8vRgh79tzHgh58NyveI+hIswL2L6ilCbinZrLJrt W1yQJDMn1dbmA== Date: Thu, 21 Mar 2024 15:54:57 +0100 (CET) From: gparc@free.fr To: veem v Cc: pgsql-general , Laurenz Albe Message-ID: <1962146764.770571424.1711032897372.JavaMail.zimbra@free.fr> In-Reply-To: References: Subject: Re: Not able to purge partition MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [145.242.20.127] X-Mailer: Zimbra 9.0.0_GA_1337 (ZimbraWebClient - FF115 (Linux)/9.0.0_GA_1337) Thread-Topic: Not able to purge partition Thread-Index: gmtOcTTHlIQMegOcBRYi/Zel0iFRYQ== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----- Mail original ----- > De: "Laurenz Albe" > =C3=80: "veem v" , "pgsql-general" > Envoy=C3=A9: Jeudi 21 Mars 2024 13:48:19 > Objet: Re: Not able to purge partition > On Thu, 2024-03-21 at 11:07 +0530, veem v wrote: >> CREATE TABLE schema1.test_part_drop_parent >> ( >> =C2=A0c1 varchar(36) =C2=A0NOT NULL , >> =C2=A0c2_part_date timestamp with time zone =C2=A0NOT NULL , >> =C2=A0c3 =C2=A0numeric(12,0) =C2=A0NOT NULL , >> =C2=A0CONSTRAINT test_part_drop_parent_PK PRIMARY KEY (c1,c2_part_date) >> ) PARTITION BY RANGE (c2_part_date); >>=20 >> CREATE INDEX idx1_test_part_parent ON schema1.test_part_drop_parent( C3 = ASC); >>=20 >>=20 >> CREATE TABLE schema1.test_part_drop_child >> ( >> =C2=A0C1_child =C2=A0 varchar(36) =C2=A0NOT NULL , >> =C2=A0C1 =C2=A0 varchar(36) =C2=A0NOT NULL , >> =C2=A0c2_part_date timestamp with time zone =C2=A0NOT NULL , >> =C2=A0C3 =C2=A0numeric(12,0) =C2=A0NOT NULL , >> =C2=A0CONSTRAINT test_part_drop_child_PK PRIMARY KEY (C1_child,c2_part_d= ate), >> =C2=A0CONSTRAINT test_part_drop_child_FK1 FOREIGN KEY (C1,c2_part_date) = REFERENCES >> =C2=A0schema1.test_part_drop_parent(c1,c2_part_date) >> ) PARTITION BY RANGE (c2_part_date); >>=20 >> CREATE INDEX test_part_drop_child_fk ON schema1.test_part_drop_child( c1= , >> c2_part_date); >>=20 >> CREATE INDEX test_part_drop_child_idx ON schema1.test_part_drop_child( c= 1_child, >> c2_part_date); >> >> [create some partitions, then drop a partition of the referenced table] >> >=20 >> SQL Error [P0001]: ERROR: cannot drop table >> schema1.test_part_drop_parent_p2024_02_01 because other objects depend o= n it >> CONTEXT: SQL statement "DROP TABLE schema1.test_part_drop_parent_p2024_0= 2_01" >=20 > That's normal. If you create a foreign key constraint to a partitioned t= able, > you > can no longer drop a partition of the referenced table. >=20 > What you *can* do is detach the partition and then drop it, but detatchin= g will > be slow because PostgreSQL has to check for referencing rows. >=20 > The best solution is to create the foreign key *not* between the partitio= ned > tables, but between the individual table partitions. That should be easy= if > you have the same partition boundaries for both. > Then you can simply drop a partition from both tables at the same time. >=20 > Yours, > Laurenz Albe > -- > Cybertec | https://www.cybertec-postgresql.com Also, as an aside, test_part_drop_child_idx index is redundant with test_pa= rt_drop_child_pk index created for the primary key Regards Gilles