pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marc-Olaf Jaschke <moj@dshare.de>
To: pgsql-general@lists.postgresql.org
Subject: concurrent creation of sequences
Date: Wed, 31 Mar 2021 18:26:52 +0200
Message-ID: <F385393C-7ADD-45D6-855A-767DFD245006@dshare.de> (raw)

Hi,

 
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.
 
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).
 
Is this behavior intentional?
Are there possibly other error codes that the stress test did not uncover and that I should consider?
 
"create sequence if not exists ..." does not prevent errors with concurrency.
 
 
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"
 
 
Best regards,
Marc-Olaf Jaschke




Message-ID: <F385393C-7ADD-45D6-855A-767DFD245006@dshare.de>
Permalink:  ../F385393C-7ADD-45D6-855A-767DFD245006@dshare.de/
Also on:    postgresql.org/message-id/F385393C-7ADD-45D6-855A-767DFD245006@dshare.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: moj@dshare.de
  Subject: Re: concurrent creation of sequences
  In-Reply-To: <F385393C-7ADD-45D6-855A-767DFD245006@dshare.de>
  References: <F385393C-7ADD-45D6-855A-767DFD245006@dshare.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox