From: Daniel Verite <daniel@manitou-mail.org>
To: pabloa98 <pabloa98@gmail.com>
Cc: Christopher Browne <cbbrowne@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: Peter J. Holzer <hjp-pgsql@hjp.at>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Could postgres12 support millions of sequences? (like 10 million)
Date: Mon, 23 Mar 2020 17:58:51 +0100
Message-ID: <1e2dcebd-a522-4743-a2ea-b7ed78725404@manitou-mail.org> (raw)
In-Reply-To: <CAEjudX4Y-ZvdGvpag9-fxaV3oQwAYxiwAxoibYVXLbPKt410pw@mail.gmail.com>
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)=(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,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
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: daniel@manitou-mail.org, pabloa98@gmail.com, cbbrowne@gmail.com, adrian.klaver@aklaver.com, robjsargent@gmail.com, hjp-pgsql@hjp.at
Subject: Re: Could postgres12 support millions of sequences? (like 10 million)
In-Reply-To: <1e2dcebd-a522-4743-a2ea-b7ed78725404@manitou-mail.org>
References: <CAEjudX4Y-ZvdGvpag9-fxaV3oQwAYxiwAxoibYVXLbPKt410pw@mail.gmail.com> <1e2dcebd-a522-4743-a2ea-b7ed78725404@manitou-mail.org>
* 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