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 1tIt3e-00HGqh-UU for pgsql-general@arkaria.postgresql.org; Wed, 04 Dec 2024 17:21: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 1tIt3c-001jq8-Ae for pgsql-general@arkaria.postgresql.org; Wed, 04 Dec 2024 17:21:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIt3b-001jq0-Uy for pgsql-general@lists.postgresql.org; Wed, 04 Dec 2024 17:21:01 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tIt3a-0012e0-72 for pgsql-general@postgresql.org; Wed, 04 Dec 2024 17:20:59 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-aa53ebdf3caso576484966b.2 for ; Wed, 04 Dec 2024 09:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1733332856; x=1733937656; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=HaRm5kGIqeqlwVztylRlETAJhjXSy2fOkgejjZxPa7g=; b=ELerqP+iV9CEXuCBhVpAVR3ge5iQYT0vwRnZJn5erJ5lnZ+A8qcraK+3twi/wAPNS/ MRoCswIwts/oF2EqMfWVVtTgHN5pojs+AATpXdFHhfLHteOIbbnZoDKZz81Pu8lYGGcs Fhqez3N5thyqG0hKEob9+nJ2aWAqmCG/zeruJstiOLNRFouIId3RfOoi8WYG8457s+sl awGx7edJzB1sVdAZnv6HENZcTf/4sd5RcU5QXDyMoOd36/QIOE+cRG3v0SAIBCCLeYYu hbY/6hNVvCACgtlun8vbMgl7gvGTpZGm1ir/Bzxble4mFP7qAGoSZ2m6pN346yTjoQd3 BAWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733332856; x=1733937656; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HaRm5kGIqeqlwVztylRlETAJhjXSy2fOkgejjZxPa7g=; b=NwrbPGG7jsIlcPSInZNQLJuusB50pupezgThcXtb+tqW9Ivgr5uUCndIIKgm0YOy5a DmNWh5Z7ZgWJjWcXY16NyLsfR5U3KHGtzqptejah+oQRvZOJy2D9sbAhbZuM6O3C6kZE iR/i7WiMYIpRMEYdjJVJdiSztYBdWQ/YY9fvYxB+ExITH0nlhueY1jAvpI9fs1wLK7Q0 vP14MZeQfLWIOLwVSZlPtn2sp6ChvGnPz63y6cxedLryaLvs1gSZ3+DIkNW6/fsZFB2m ymJsOfJVwNNyAISKWLZic1yrx1AAwK4SxDQ8t6F/0B7BebBHceLvPIEU4McdJLrA1vP3 A34A== X-Forwarded-Encrypted: i=1; AJvYcCUYSlG3GaXwac4YInQuNXjIczoLxtfLB0MyRdUhTmQJckzf7fZehXnYUcqZgoAj8/229e9GswPOMRDMAeed@postgresql.org X-Gm-Message-State: AOJu0Yxkgs+YPeoAids96Ydp4gi5/YorxlzFS3NSVh11DHyOTNlteW2Z 1NFW8dFnSHZPCKj5TiLY1pTCTu8T5hMj61Y+1XxFcTicUpEqIkC2l8iPTBRdzKwCPZ70xKNok7M MGtA= X-Gm-Gg: ASbGnctyYHFvJLPpJRzg1h3c6zLOg8pnrzI8ON5t5E48EmrFfS9P7mbzZhyYjrgcSta t2Avbm/qrtrDM7xbjMlQXYPhmFP5UfbRNtoR4yidwOP3dVMa5lrATpMo6YW8XKoAKVHGkN63P6C gCxvj/UWLg4sNjTpA1T0ztqa9gKN2nhY+YViMjbKInRlFsFuL8saBt+HkN1fFoMBu2vMA8YUojz Wp2Mj8PorZs9xp3m2+2h+QaN/Nlbjt9Ok69+G7nu7X3znDOER9q7YHbNnZPQlamg05e45kANeUB g/6KiGDi+fr+Tm77vi0bW2hHPzW+RGpKbUV/VSlJDFV9fKFtQg== X-Google-Smtp-Source: AGHT+IE7OW72QCUmLshmY/U5VUyJ/bDAY8IuNdPAbJb2bkwUIylxUUALe8buAUkGLlegIY405hHSeg== X-Received: by 2002:a17:906:9a95:b0:aa6:c55:739a with SMTP id a640c23a62f3a-aa60c5574a7mr306970066b.50.1733332856391; Wed, 04 Dec 2024 09:20:56 -0800 (PST) Received: from localhost.localdomain (dslb-002-200-202-108.002.200.pools.vodafone-ip.de. [2.200.202.108]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa599905c61sm756030266b.146.2024.12.04.09.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 09:20:55 -0800 (PST) Message-ID: <928c165be24ee307c2fbaa29a2c6360eb8a00e02.camel@cybertec.at> Subject: Re: Clarification of behaviour when dropping partitions From: Laurenz Albe To: Bolaji Wahab , pgsql-general@postgresql.org Date: Wed, 04 Dec 2024 18:20:55 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-2.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2024-12-04 at 14:22 +0100, Bolaji Wahab wrote: > I have these two partitioned tables, with=C2=A0referential integrity. The= tables > are structured=C2=A0in such=C2=A0a way that we have 1 to 1 mapping betwee= n their > partitions. This is achieved with a foreign key. >=20 > CREATE TABLE parent ( > =C2=A0 =C2=A0 partition_date date NOT NULL, > =C2=A0 =C2=A0 id uuid NOT NULL, > =C2=A0 =C2=A0 external_transaction_id uuid NOT NULL, >=20 > =C2=A0 =C2=A0 CONSTRAINT parent_pkey > =C2=A0 =C2=A0 =C2=A0 =C2=A0 PRIMARY KEY (id, partition_date), >=20 > =C2=A0 =C2=A0 CONSTRAINT parent_external_transaction_id_key > =C2=A0 =C2=A0 =C2=A0 =C2=A0 UNIQUE (external_transaction_id, partition_da= te) > ) PARTITION BY RANGE (partition_date); >=20 > CREATE TABLE parent_2024_12_01 > =C2=A0 =C2=A0 PARTITION OF public.parent > =C2=A0 =C2=A0 FOR VALUES FROM ('2024-12-01') TO ('2024-12-02'); >=20 > CREATE TABLE parent_2024_12_02 > =C2=A0 =C2=A0 PARTITION OF public.parent > =C2=A0 =C2=A0 FOR VALUES FROM ('2024-12-02') TO ('2024-12-03'); >=20 > [...] >=20 > CREATE TABLE child ( > =C2=A0 =C2=A0 partition_date date NOT NULL, > =C2=A0 =C2=A0 transaction_id uuid NOT NULL, > =C2=A0 =C2=A0 key =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0text NOT NULL, > =C2=A0 =C2=A0 value =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0text NOT NULL, >=20 > =C2=A0 =C2=A0 CONSTRAINT child_pkey > =C2=A0 =C2=A0 =C2=A0 =C2=A0 PRIMARY KEY (transaction_id, key, partition_d= ate), >=20 > =C2=A0 =C2=A0 CONSTRAINT child_transaction_id_fkey > =C2=A0 =C2=A0 =C2=A0 =C2=A0 FOREIGN KEY (transaction_id, partition_date) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 REFERENCES parent (id, partition_date) > ) PARTITION BY RANGE (partition_date); >=20 > CREATE TABLE child_2024_12_01 > =C2=A0 =C2=A0 PARTITION OF child > =C2=A0 =C2=A0 FOR VALUES FROM ('2024-12-01') TO ('2024-12-02'); >=20 > CREATE TABLE child_2024_12_02 > =C2=A0 =C2=A0 PARTITION OF public.child > =C2=A0 =C2=A0 FOR VALUES FROM ('2024-12-02') TO ('2024-12-03'); I recommend that you don't create the foreign key constraint between the partitioned tables, but between the individual partitions. That will make detaching and dropping partitions easier, and you will have the same integrity guarantees. Yours, Laurenz Albe