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 1skWbf-000neq-Rf for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2024 22:30: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 1skWaf-004Uo1-22 for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2024 22:29:05 +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 1skWad-004Ui1-EJ for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2024 22:29:04 +0000 Received: from fout7-smtp.messagingengine.com ([103.168.172.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1skWaZ-00034E-3O for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2024 22:29:02 +0000 Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 616B813801C4; Sat, 31 Aug 2024 18:28:56 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sat, 31 Aug 2024 18:28:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1725143336; x=1725229736; bh=m0N5N99Gx6GRT7MpaOIDLP2FY/XmQE+xndHem49uAK8=; b= Xmk/APPK0ZQdaDeUPAmIQRjeXr9cwr+2XwxczAPHlzS6OegntTHkeHiRLIRyTeK+ aLyKUT83cT84fTleD3Y7zMkiqWSVEhAXDjxq1PTwKIi0z6Rq22h3V/BJI/0EqEqr 2rjj9td5QAV6g3bTbzIaW7jQKcBe25Abh9hEcWLUjNCVNj0bSip6D7jH/U4189kG y2nolcbOybPRy54/n5qV7+dfW/wcq6DtvRM17H7l36htHeHe70LAEpN0oEuG32OA DfTbhN8D9b2tBRPNT+UnjTvY+ge8HIpPwGeMgRaP60Of6+wwAUsOUUm2P6ixk4SA A2RZ3ie2MIzxXUfJH+Ujyg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725143336; x= 1725229736; bh=m0N5N99Gx6GRT7MpaOIDLP2FY/XmQE+xndHem49uAK8=; b=W s+saF+Zlbo1PzpONLWI3GHGarlpDs7w6wEsJqTJdZB3ra795/RiLO68Qeze5cLtv 0l4kCazViRbRi0JOEVhiOs30dqrWlCjxM35GoRHxqet9TfF3wzKxv/3m8ypdHmz8 dBSfjt0NEwtDIWgZ1qClEF7d+69l/EeErix/2eV8GHUK1YN3ILbVgjQpDtOEI2el 9DylAkJtK1JjJ/g8JF7ACltDzaSLXuOBzVDLOFm6RLtAGWndmHBupBKQURicXuJp zJbSp6KitWHlzlpsnjJoLUgNKCt8l6ne8HEc89g5+lgJ1qVbWjp1HPC9mg61GUoj 6PYghukvF+58hCIlVQqKg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefledgudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvfhfhjggtgfesthejredttddvjeen ucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeeivdfhieehheegueeileej ieettdejhedugeefleekvdelkeehtdfgiefffeekudenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehvvggvmhgrtddttddtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhg shhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 31 Aug 2024 18:28:55 -0400 (EDT) Message-ID: <7fa81130-0b33-4e53-bb32-39d84f06c680@aklaver.com> Date: Sat, 31 Aug 2024 15:28:54 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Partitioning and unique key To: veem v , pgsql-general References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/31/24 13:02, veem v wrote: > Hello, > > We have our transaction tables daily range partitioned based on > transaction_timestamp column which is timestamptz data type and these > are having composite primary key on (transaction_id, > transaction_timestamp). And we were using an "insert on conflict" for > loading data to our system , which means if another record comes to the > system with the same transaction_id and transaction_timestamp, it will > get updated. This way we already have 60 days worth of data stored in > our system with approx. 70 million transactions per day. > > But we just got to know from business thatthe data should be unique by > only transaction_id but not transaction_timestamp. Any incoming data > with the same transaction_id(even different transaction_timestamp) > should get updated but not inserted. > > Also these daily partitions are going to hold 400million rows in future > and will be queried on the transaction_timestamp filter so we can't > really avoid the partitioning option here considering future growth. > > But 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 _trans_action_id only? The model is at odds with itself and untenable. If the tables hold multiple rows for a given transaction_id then you cannot have a PK/Unique constraint on that column. Seems there is a decided lack of any planning. The only way I can see this happening is consolidating all the duplicate transaction_id rows into a single row for each transaction_id. That then leads to the question of how to do that and retain the 'correct' information from the selection of rows for each transaction_id. > > Note-its 15.4 postgres database. > > > Regards > > Veem > -- Adrian Klaver adrian.klaver@aklaver.com