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 1lRtso-0001JL-JU for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 09:44:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lRtsn-0000T2-Fx for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 09:44:57 +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 1lRdgH-0003qo-Ee for pgsql-general@lists.postgresql.org; Wed, 31 Mar 2021 16:26:57 +0000 Received: from smtprelay08.ispgateway.de ([134.119.228.98]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRdgE-0003r8-S9 for pgsql-general@lists.postgresql.org; Wed, 31 Mar 2021 16:26:57 +0000 Received: from [93.230.171.118] (helo=mojn.fritz.box) by smtprelay08.ispgateway.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lRdg9-00052S-Ru for pgsql-general@lists.postgresql.org; Wed, 31 Mar 2021 18:26:49 +0200 From: Marc-Olaf Jaschke Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: concurrent creation of sequences Message-Id: Date: Wed, 31 Mar 2021 18:26:52 +0200 To: pgsql-general@lists.postgresql.org X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Df-Sender: bWFyYy1vbGFmLmphc2Noa2VAZHNoYXJlLmRl List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, =20 I have a use case where I need to create sequences concurrently. I use = sequences instead of a table with counters to keep lock contention for = incrementing the id low. The creation of new sequences rarely occurs = during normal application operation. I check via information_schema.sequences if a sequence already exists = and catch errors that occur with concurrent access if the corresponding = sequence already exists. =20 I wrote a stress test that simulates the behavior with heavy = concurrency. I get the following three different error codes: 42P07 42710 23505 I would have expected only 42710 (duplicate_object). =20 Is this behavior intentional? Are there possibly other error codes that the stress test did not = uncover and that I should consider? =20 "create sequence if not exists ..." does not prevent errors with = concurrency. =20 =20 Tested with "PostgreSQL 12.6 on x86_64-apple-darwin16.7.0, compiled by = Apple LLVM version 8.1.0 (clang-802.0.42), 64-bit" =20 =20 Best regards, Marc-Olaf Jaschke=