pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Lewis <mlewis@entrata.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pabloa98 <pabloa98@gmail.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Could postgres12 support millions of sequences? (like 10 million)
Date: Thu, 19 Mar 2020 22:56:14 -0400
Message-ID: <10838.1584672974@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHOFxGqsZJM5s9x3ELVtq_qRQj1odZ_L-SNKqdYyyBbd=1+_nw@mail.gmail.com>
References: <CAEjudX5UdEYJwSTYir07rUX10u3AdEyht_K=GWk_CyOChSFguQ@mail.gmail.com>
	<B6FC3723-FF9D-4E5E-8506-3BF9421825DF@gmail.com>
	<CAEjudX5T5E_two14i_i19uGMkSs_mT4JG4hhXWoY3Z5M+GaXRQ@mail.gmail.com>
	<7CF69CD4-AE4A-4C2B-9621-4462B4AE1726@gmail.com>
	<CAEjudX5=jxdxZmuSXgBCM+nHNhR=0OAcZGB5UaRB1JZe1YRNtA@mail.gmail.com>
	<CAKFQuwZ==ri5_m2geFA-GPOdfnVggmJRu3zEi+1EwJdJA=9AeQ@mail.gmail.com>
	<CAHOFxGqsZJM5s9x3ELVtq_qRQj1odZ_L-SNKqdYyyBbd=1+_nw@mail.gmail.com>

Michael Lewis <mlewis@entrata.com> writes:
> On Thu, Mar 19, 2020, 5:48 PM David G. Johnston <david.g.johnston@gmail.com>
> wrote:
>> However, one other consideration with sequences: do you care that
>> PostgreSQL will cache/pin (i.e., no release) every single sequence you
>> touch for the lifetime of the session? (I do not think DISCARD matters here
>> but I'm just guessing)

> Would you expand on this point or is there someplace specific in the
> documentation on this?

I think what David is worried about is that a sequence object is a
one-row table in PG's implementation.  Thus

(1) each sequence requires a dozen or two rows in assorted system
catalogs (not sure exactly how many offhand).

(2) each sequence uses up 8KB on disk for its table file.

(3) each sequence you actually access within a particular session
results in creation of relcache and catcache entries in that
session's local memory.  I'm not sure offhand how big those are
either, but a few KB per sequence would be a reasonable guess.

(4) each sequence competes for space in the shared-buffer arena,
since its 8K block has to be swapped into there whenever you try
to access/increment the sequence's value.

This is all mighty inefficient of course, and there's been talk
of trying to reduce the per-sequence overhead; but I don't know
of anyone actively working on that.  As things stand, I think
having millions of sequences would be quite painful performance-
wise, especially if your workload were actively hitting a lot
of them concurrently.  It would work, for some value of "work",
but it wouldn't perform very well.

Also, as multiple people mentioned already, this still wouldn't
guarantee gap-free sequences of ID values.

			regards, tom lane





view thread (58+ messages)  latest in thread

Message-ID: <10838.1584672974@sss.pgh.pa.us>
Permalink:  ../10838.1584672974@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10838.1584672974@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, mlewis@entrata.com, david.g.johnston@gmail.com, pabloa98@gmail.com, robjsargent@gmail.com
  Subject: Re: Could postgres12 support millions of sequences? (like 10 million)
  In-Reply-To: <10838.1584672974@sss.pgh.pa.us>
  References: <CAEjudX5UdEYJwSTYir07rUX10u3AdEyht_K=GWk_CyOChSFguQ@mail.gmail.com> <B6FC3723-FF9D-4E5E-8506-3BF9421825DF@gmail.com> <CAEjudX5T5E_two14i_i19uGMkSs_mT4JG4hhXWoY3Z5M+GaXRQ@mail.gmail.com> <7CF69CD4-AE4A-4C2B-9621-4462B4AE1726@gmail.com> <CAEjudX5=jxdxZmuSXgBCM+nHNhR=0OAcZGB5UaRB1JZe1YRNtA@mail.gmail.com> <CAKFQuwZ==ri5_m2geFA-GPOdfnVggmJRu3zEi+1EwJdJA=9AeQ@mail.gmail.com> <CAHOFxGqsZJM5s9x3ELVtq_qRQj1odZ_L-SNKqdYyyBbd=1+_nw@mail.gmail.com> <10838.1584672974@sss.pgh.pa.us>

* 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