Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLADH-0000wB-FG for pgsql-general@arkaria.postgresql.org; Thu, 26 Jan 2023 21:55:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pLADF-0004UV-SC for pgsql-general@arkaria.postgresql.org; Thu, 26 Jan 2023 21:55:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLADF-0004SZ-HT for pgsql-general@lists.postgresql.org; Thu, 26 Jan 2023 21:55:17 +0000 Received: from mout-u-107.mailbox.org ([2001:67c:2050:101:465::107]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLADC-0005Nm-T1 for pgsql-general@lists.postgresql.org; Thu, 26 Jan 2023 21:55:17 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4P2vdT4M7Sz9sW5; Thu, 26 Jan 2023 22:55:09 +0100 (CET) Date: Thu, 26 Jan 2023 22:55:09 +0100 (CET) From: Erik Wienhold To: veem v , pgsql-general@lists.postgresql.org Message-ID: <214765350.744944.1674770109151@office.mailbox.org> In-Reply-To: References: Subject: Re: Sequence vs UUID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 26/01/2023 20:17 CET veem v wrote: > > Hello, We were trying to understand whether we should use UUID or Sequenc= e in > general for primary keys. In many of the blogs (one is below) across mult= iple > databases, I saw over the internet and all are mostly stating the sequenc= e is > better as compared to UUID. But I think in the case of concurrent data lo= ad > scenarios UUID will spread the contention point whereas sequence can be a > single point of contention. > > So we want to understand from experts here, if there are any clear rules > available or if we have any pros vs cons list available for each of those= to > understand the exact scenario in which we should go for one over other? > Basically I wanted to see if we can perform some test on sample data to s= ee > the percentage of overhead on read and write performances of the query in > presence of UUID VS Sequence to draw some conclusion in general? And also > considering open source postgres=C2=A0as the base for many databases like= redshift > etc, so the results which apply to progress=C2=A0would=C2=A0apply to othe= rs as well. > > https://www.percona.com/blog/2019/11/22/uuids-are-popular-but-bad-for-per= formance-lets-discuss/ I think that[1] provides a good summary. Performance consideration is just= one aspect. Is there a technical requirement for using UUID over sequential va= lues? If there's a single generator of primary keys use bigint sequences. In cas= e of multiple generators (multi-master replication, sharding, clients generating= IDs) consider UUID. There are arguments against sequential PK, e.g. they give away too much inf= o and allow attacks such as forced browsing[2]. The first I can understand: you = may not want to reveal the number of users or customers. But access control sh= ould prevent forced browsing. [1] https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-= for-postgresql-auto-generated-primary-keys/ [2] https://owasp.org/www-community/attacks/Forced_browsing -- Erik