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 1sl9cJ-005awn-Lw for pgsql-general@arkaria.postgresql.org; Mon, 02 Sep 2024 16:09:24 +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 1sl9cI-00GSIN-NW for pgsql-general@arkaria.postgresql.org; Mon, 02 Sep 2024 16:09:22 +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 1sl9cI-00GSHc-9m for pgsql-general@lists.postgresql.org; Mon, 02 Sep 2024 16:09:22 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sl9cF-000Jis-VD for pgsql-general@lists.postgresql.org; Mon, 02 Sep 2024 16:09:21 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c255e3c327so1542989a12.1 for ; Mon, 02 Sep 2024 09:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725293358; x=1725898158; 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=yYweQ0+tpLeRI+MO8/fYpO0dKLWaSLceR5pBj34ea6s=; b=ZDoetTjnJJ/3maVYQfK0N2VFfHQdYjy/LeY5H5IzV0QB59X9fYrFUbjWuw1Ku6GG3X tLLn9lnfvrLY2fRTRMt4W7xPVdWv+Jr/rdG6yZhkrI2GouV8m7pXHhi8nEwgOyWVAjfl 2oo3TWtYlPp/CsIOxibGUe/fvL5btapy5tUha1Fv82BaB6wxJHKvAlhsLX5kSwj3Qvbz X1frfIDIRXVs7qC20XTFWEnmYVZI0k4Hq6GWs9KpED13h48aVD66O1stFoJaTgQkxpvF Sp44YFvwUwpYjJwCS4fdXvBnoc5c6DAZgqRArJjJrxxzv3YJaa6UFFn+wk3ya6aznbj1 X8pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725293358; x=1725898158; 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=yYweQ0+tpLeRI+MO8/fYpO0dKLWaSLceR5pBj34ea6s=; b=u+LH9OudMmijReUA+kpiF72Qyw4LlKGqLui/v7L7JHkPw6oOsGu/RNPIjReGfTykQZ /jOct2C4LjZY4S6A1qQAhukHl8pvMD9WegK+73OFUqkXiZoTZwXnClCAuQSP1GAmGELc Kk9WKwk8PHbqlnhzbIDgXlPzY39e5x0Q0GnxvB70CtES/8Q+oFuPTQVYhfCBMV8u2EON i1myBDyDPXIBPz5tPjlm+mslf+jxL6NdWJnRAdQXXG0XDjDpgZ8VVlW6SdX5PDCUBFKz KlMceqLAtwYtA094ezEFGCpajBNoHxuJDKAACjtoUsrHgrIHWmbVbyxBV3ApFPDI+3nK Flcg== X-Gm-Message-State: AOJu0Yxyjm+3QAcXq7zkBHsToLK0/zvFAGJjXNmIFoij09RsKio4cmMN 51fa/KrARI4Se2SX0pW7iZvjKso+1F6FPHMBoiNx0lLcGvrn1/C5BuPwyv+pOfwIw/+jSnVbxDh OsFmQ0zk3TdpAkiyv4geO/d3z7r0wGA== X-Google-Smtp-Source: AGHT+IFmgp8cRe5X8cpX/MF8+rk+hB+JkeG6TXU/InFaq5HBvd9e70IX5iJJZIDrrNkRaoigFyHSD0oW+AFhrw8bXk8= X-Received: by 2002:a17:907:9606:b0:a86:746a:dced with SMTP id a640c23a62f3a-a89fadc1166mr360327666b.19.1725293357580; Mon, 02 Sep 2024 09:09:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: veem v Date: Mon, 2 Sep 2024 21:39:06 +0530 Message-ID: Subject: Re: Partitioning and unique key To: Laurenz Albe Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000b6480206212529bc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b6480206212529bc Content-Type: text/plain; charset="UTF-8" On Mon, 2 Sept 2024 at 19:13, Laurenz Albe wrote: > On Sun, 2024-09-01 at 01:32 +0530, veem v wrote: > > due to postgres limitations we are unable to have this unique constraint > or primary key > > only on the transaction_id column, we have to include > transaction_timestamp with it as > > a composite key. So I want to understand from experts if there is any > possible way to > > satisfy both partitioning on transaction_timestamp column and unique key > or pk just on > > transaction_id only? > > No, you cannot have both. > > Usually the solution is to *not* create a primary key on the partitioned > table > and instead create a primary key on each partition. > > That won't guarantee global uniqueness (and there is no way to do that), > but it > goes a long way by ensuring that the column is unique within each > partition. > > Yours, > Laurenz Albe > Thank you so much. So it means in our case the existing PK on table level on column (txn_id and txn_timestamp), we should drop that and create a unique index on each partition level and also the same way the foreign key also maps to the parent table partitions. And in that case , can we follow this as best practices to not have the primary keys defined at the tabe level at all, but on the partition level only, or there exist any down side to it too? Please suggest. Also then what I see is, it will make the data load query fail which uses "insert on conflict" to insert data into the table and that requires the primary key on both the columns to have on table level. Also the partition maintenance job which uses partman extension uses the template table which in turn uses table level properties for creating new partitions and they will not have these unique indexes created for the new partitions as because the unique index property is not on the table level but partition level. Can you share your thoughts on these? --000000000000b6480206212529bc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, 2 Sept 2024 at 19:13, Laurenz Alb= e <laurenz.albe@cybertec.at<= /a>> wrote:


=
--000000000000b6480206212529bc--