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 1rrO1f-000JTd-BF for pgsql-general@arkaria.postgresql.org; Mon, 01 Apr 2024 20:13:03 +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 1rrO0f-001NM9-Ng for pgsql-general@arkaria.postgresql.org; Mon, 01 Apr 2024 20:12:02 +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 1rrO0f-001NM1-CY for pgsql-general@lists.postgresql.org; Mon, 01 Apr 2024 20:12:02 +0000 Received: from mail-ua1-x931.google.com ([2607:f8b0:4864:20::931]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rrO0Z-0002Fw-3T for pgsql-general@lists.postgresql.org; Mon, 01 Apr 2024 20:12:01 +0000 Received: by mail-ua1-x931.google.com with SMTP id a1e0cc1a2514c-7e05d68723dso1071091241.1 for ; Mon, 01 Apr 2024 13:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712002313; x=1712607113; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YAtKfJPQzkvf2G8JoqtB9LyfuyGH2ABfGcnknmNhgzo=; b=VU7A/eEjSLW6k4jt0eWYf3FEEFobgFI+VTUFMYRN6OQBc4fOx2Twrn8XfLz0OBINL9 RWvH8AL5lUdE4TdGgO/CC89kTRmF9WEm90hzwkMKzruOlltRrJM/G2yAUkdRLAjuJm1q bXD3Q3ifDv9aNhncI6EbQKRdK9+gZbQZ2XZ9CC75DrQjiKhGTgw2Uk9pIDa6nigcmCrs n/HrmOuo02O3Sy4Z+S0oHY8uma1GioA5QaTfw1YYPNtx7Heayqsn6TiFabGSOR6GgyK+ aTevFJwi6GdL6qnDFycvjQ0KcmMAdn9sL5kFARm+MoMWeU48ImC64edisBzagC1w8zaO LUaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712002313; x=1712607113; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YAtKfJPQzkvf2G8JoqtB9LyfuyGH2ABfGcnknmNhgzo=; b=MMOdWDLQm7+BfYyrdJoXCAa1d0N5VRGtkaERHpEygVa6nUIn06j24O2EwiCieFcT8n EQAHKSCqLgdFeO8WkvrhyfMdIvc/01Y8fIL8sqbh5vy7C5iNHM61090zx/dT0ZSvI+W4 zx3v91UC6VAvJLK21zT1wdnfxW/fz/t5IwSPmBwxVZGlaAAGRiVg3EtldYXDOaG9mHLf bX7qnW/0J6F8sBkhijpJLWK4oIWjlKDBq8Le9vKxiB4UFPzyxJ785RtGKGYK+MdTAvQ1 xPB8IrjTvk7i7Kf+aNpG4Afx86hosc/FdcJt5oBW/u+Mnsk/fnH37sQX443l2B5DAzVc DKVA== X-Forwarded-Encrypted: i=1; AJvYcCWB7W95nmcrZQD2rpZmQfW/pQD2L/OiBw6cmgLY5pFX0e8T2DLEBdnvx/U2YI4HUvkThErMBkjHs4kX3+/2eyeOxfCl03ThVjm64h3LnHQTRC08 X-Gm-Message-State: AOJu0Yxv9MXLlScyWmlvyE6m8EDy+J770VMzzsXxhnE5Z0Wx+6QWIYlm GYUnGDh2j4lfuAj/aRXCSGMwYqbSxc3FzXKnyG+dlBS9SmdcnfAS156iCryQbqovwwetTigqHch U0vbK2NTnMeZfit2nKjmQbz0W/K8= X-Google-Smtp-Source: AGHT+IErV6SOS26CBpjyJHyxGmrp+ZXj/VO/quh5lJvlx37yyCLc9/AXRacYXycw2ulSMj+F5dBTXXUS2CbzwCsE8xk= X-Received: by 2002:a67:fdc4:0:b0:478:8191:7e9b with SMTP id l4-20020a67fdc4000000b0047881917e9bmr2510870vsq.17.1712002313361; Mon, 01 Apr 2024 13:11:53 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: sud Date: Tue, 2 Apr 2024 01:41:40 +0530 Message-ID: Subject: Re: Not able to purge partition To: Laurenz Albe Cc: veem v , pgsql-general Content-Type: multipart/alternative; boundary="000000000000be238d06150e9987" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000be238d06150e9987 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 21, 2024 at 6:18=E2=80=AFPM Laurenz Albe wrote: > > > [create some partitions, then drop a partition of the referenced table] > > > > > SQL Error [P0001]: ERROR: cannot drop table > schema1.test_part_drop_parent_p2024_02_01 because other objects depend on= it > > CONTEXT: SQL statement "DROP TABLE > schema1.test_part_drop_parent_p2024_02_01" > > That's normal. If you create a foreign key constraint to a partitioned > table, you > can no longer drop a partition of the referenced table. > > 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. > *The best solution is to create the foreign key *not* between the partitioned* *tables, but between the individual table partitions. * Interesting, even my thought was that the detach+drop parent partition will only look into the specific child partition but not the whole child table. However, out of curiosity, does this default foreign key setup i.e. foreign keys between the table (but not between the partitions) also make the data load into the child partitions slower ( as it must be then looking and validating the presence of the keys across all the partitions of the parent table)? --000000000000be238d06150e9987 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, Mar 21, 2024 at 6:18=E2=80=AFPM L= aurenz Albe <laurenz.albe@cy= bertec.at> wrote:

> [create some partitions, then drop a partition of the referenced table= ]
>

> SQL Error [P0001]: ERROR: cannot drop table schema1.test_part_drop_par= ent_p2024_02_01 because other objects depend on it
> CONTEXT: SQL statement "DROP TABLE schema1.test_part_drop_parent_= p2024_02_01"

That's normal.=C2=A0 If you create a foreign key constraint to a partit= ioned table, you
can no longer drop a partition of the referenced table.

What you *can* do is detach the partition and then drop it, but detatching = will=C2=A0
be= slow because PostgreSQL has to check for referencing rows.

The best solution is to create the foreign key *n= ot* between the partitioned
tables, but between the individu= al table partitions.=C2=A0=C2=A0=C2=A0
=C2=A0
Inter= esting, even my thought was that the detach+drop parent partition will only= look into the specific child partition but not the whole child table.

However, out of curiosity, does this default foreign k= ey setup i.e. foreign keys between the table (but not between the partition= s) also make the data load into the child partitions slower ( as it must be= then looking and validating the presence of the keys across all the partit= ions of the parent table)?
=C2=A0
--000000000000be238d06150e9987--