Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jGQPj-0003Xw-OR for pgsql-general@arkaria.postgresql.org; Mon, 23 Mar 2020 16:58:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGQPi-00079t-Ia for pgsql-general@arkaria.postgresql.org; Mon, 23 Mar 2020 16:58:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jGQPi-00079m-5U for pgsql-general@lists.postgresql.org; Mon, 23 Mar 2020 16:58:58 +0000 Received: from mail.verite.pro ([185.16.44.216]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGQPf-0002qb-Ss for pgsql-general@lists.postgresql.org; Mon, 23 Mar 2020 16:58:57 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id B09A28C00DA; Mon, 23 Mar 2020 17:50:52 +0100 (CET) Received: by genius-map.net (Postfix, from userid 1001) id 194CF38A0EB6; Mon, 23 Mar 2020 17:58:54 +0100 (CET) Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: Could postgres12 support millions of sequences? (like 10 million) From: "Daniel Verite" To: "pabloa98" Cc: "Christopher Browne" ,"Adrian Klaver" ,"Rob Sargent" ,"Peter J. Holzer" ,"pgsql-generallists.postgresql.org" In-Reply-To: Date: Mon, 23 Mar 2020 17:58:51 +0100 Message-Id: <1e2dcebd-a522-4743-a2ea-b7ed78725404@manitou-mail.org> X-Mailer: Manitou v1.7.3 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk pabloa98 wrote: > When I have a medium number of sequence I will report how it behaves. It > will take some time though. Be aware that creating the sequences on the fly has the kind of race condition that you wanted to avoid in the first place. For instance consider this execution in two concurrent sessions: S1: BEGIN; S1: CREATE SEQUENCE seq1 IF NOT EXISTS; S2: BEGIN; S2: CREATE SEQUENCE seq1 IF NOT EXISTS; S2: (now blocked waiting for S1) S1: COMMIT; S2: ERROR: duplicate key value violates unique constraint "pg_type_typname_nsp_index" DETAIL : Key (typname, typnamespace)=3D(seq1, 36434) already exists. The client could catch these errors and retry, but then it could also do that with serializable transactions on serialization failures (SQLSTATE 40001), and you'd get the guarantee of consecutive numbering without creating all these sequences, not to mention the protection against other potential concurrency anomalies. See https://www.postgresql.org/docs/current/transaction-iso.html Best regards, --=20 Daniel V=E9rit=E9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite