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 1jFQbP-0004H4-NQ for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 22:58:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jFQbO-0005n7-7E for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 22:58:54 +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 1jFQbN-0005mz-QU for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 22:58:53 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jFQbH-00066W-Ry for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 22:58:51 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id DDBE9297A; Fri, 20 Mar 2020 23:58:42 +0100 (CET) Date: Fri, 20 Mar 2020 23:58:42 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Could postgres12 support millions of sequences? (like 10 million) Message-ID: <20200320225842.GA18976@hjp.at> References: <7CF69CD4-AE4A-4C2B-9621-4462B4AE1726@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9amGYk9869ThD9tj" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --9amGYk9869ThD9tj Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-03-19 16:48:19 -0700, David G. Johnston wrote: > First, it sounds like you care about there being no gaps in the records y= ou end > up saving.=A0 If that is the case then sequences will not work for you. I think (but I would love to be proven wrong), that *nothing* will work reliably, if 1) you need gapless numbers which are strictly allocated in sequence 2) you have transactions 3) you don't want to block Rationale: Regardless of how you get the next number, the following scenario is always possible: Session1: get next number Session2: get next nummber Session1: rollback Session2: commit At this point you have a gap. If you can afford to block, I think a simple approach like create table s(id int, counter int); ... begin; ... update s set counter =3D counter + 1 where id =3D $whatever returning c= ounter; -- use counter commit; should work. But that effectively serializes your transactions and may cause some to be aborted to prevent deadlocks. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --9amGYk9869ThD9tj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl51Sp0ACgkQ8g5IURL+ KF3ahxAAse0g/jm0SU9MtUOjqH/Ah+x+vKyDjSM5SKNM36r/QC+pr0OLtDOE6aNS ER++VJEIlxUxIFJt8Uw8UzAeRAeeqOZvWjAUgUacZ0ZJGy9iAh9ZpdcTpojrqOBE vjZN8C2zN9xAUO9nh90+TwmMFn6GPsfGFd2lXjQg9LpzClIv2B4NNcPxnnYsuHnJ qbyP/iiHwV4cnJWbNzrgAw+gU5eJ2uyUh6vnrB5t+dL9jmerPMskESdgZX73AGBq b0+kJOzWcEbw5R+OBiYo6A58l99oyqgjc5ik8kv9O0JWJeQNxh2nAAlz7mMnzVHp ND2AhAgvy1POFpjMJYomLPb2nkVVUOgCPXe827OflaPwZTb3b7cBHC6RgBo2OliO KgtWX/e111IBg2DhUXffI6HdMKnhYGozhvgvasWhw1N1tuzE+xwnmBaeH0ei3227 iR8RPNLNmW59SsnSHMEDhSUjyhib4RHFAoIW8v7nuPgE3DY3QkX5UKGriGPwm4La A6+aJE/o7kDpXMlmZmoDxwllHC3/BaJsDOjM6RvpdysGtgVARKRmrCAnFSpo0umW /hGYPFYwVNl5tWh7/EDbMk5BAYNcrGWKeXOn5vmlsJS1SnWtQcJtI+U4feS5Xg7f 6etrC2X3vhKI0Qk0jqjmlGcfFKiWwPbGcAP/ngsRF80oyC+RPOw= =00X5 -----END PGP SIGNATURE----- --9amGYk9869ThD9tj--