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 1jFR5C-0005c1-RG for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 23:29:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jFR5A-0007qD-5g for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 23:29:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jFR59-0007q6-Rm for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 23:29:39 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jFR51-0008Hi-8Z for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 23:29:39 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 4287C245D; Sat, 21 Mar 2020 00:29:29 +0100 (CET) Date: Sat, 21 Mar 2020 00:29:29 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Could postgres12 support millions of sequences? (like 10 million) Message-ID: <20200320232929.GA22868@hjp.at> References: <20200320225842.GA18976@hjp.at> <0D8F2D62-C0E4-4D6C-B77C-9A2FEB78898C@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline In-Reply-To: <0D8F2D62-C0E4-4D6C-B77C-9A2FEB78898C@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-03-20 17:11:42 -0600, Rob Sargent wrote: > On Mar 20, 2020, at 4:59 PM, Peter J. Holzer wrote: > > 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 record= s you end > >> up saving. If that is the case then sequences will not work for you. > >=20 > > I think (but I would love to be proven wrong), that *nothing* will work > > reliably, if > >=20 > > 1) you need gapless numbers which are strictly allocated in sequence > > 2) you have transactions > > 3) you don't want to block > >=20 > > Rationale: > >=20 > > Regardless of how you get the next number, the following scenario is > > always possible: [...] > > At this point you have a gap. > >=20 > > If you can afford to block, I think a simple approach like [...] > > should work. But that effectively serializes your transactions and may > > cause some to be aborted to prevent deadlocks. >=20 > OP has said small gaps are ok. Yes. This wasn't a response to the OP's requirements, but to David's (rather knee-jerk, IMHO) "don't use sequences" response. Very often the requirements which would preclude sequences also preclude any other solution. (In the case of the OP's problem, I'd agree that sequences are probably a bad idea for the reasons he anticipates) > To me that says the requirement Which requirement? The OP's or the one I posed here? > is capricious but we haven=E2=80=99t heard the rationale for the requirem= ent > yet (or I missed it) The OP gave a rationale: He has to fit the counter into an 8-digit field, and a global counter would overflow that. So he needs per-element counters. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --VbJkn9YxBvnuCH5J Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl51UdQACgkQ8g5IURL+ KF1vAw/+O93rlu4rmIFI5ZegLl/vu2pmk2ZEBkgGwm4TiZcurRb4AusyG0oXcvKh NIlUwQcm5W88mluNG3MxVo8o0M22x7DA0RYVW2wPzQKkZaZYcVQuGNEPCgYSbvli v71DOo2QsbKpWW9ijl+MC3Op3f4ckwE3U44+NKsPxqY78LH4N/7E81I/3027G6Ki YqlUMfOKRNckoYgdmZYwQzslro1cJ8xsFwbTtySho4/nF6n1dM+s6dLztNorQ5eT JXNCNNt0tMcY+zUEqFAODzZK7sPWSnKayrYj44O3lrrNPZ+2jv8WYtrNeHJ7LCEc 3mUek4EjIVAHCoBO6l8icttsYYrl/X7ZeEuMixCt2dFxjF0zNTPxG4rNYvA0dUJ+ PuBRAbvcSLuGpE+9+zqAjBOyDjRN4fFevvXxJ6pBxwTw+9CaYAGOBF3RPzTsfDbf xbY1Y9Z1aLYGxCuWmJgR/W7ZSjqN5GDtlQO+wgb7yoB1NRGi+lwku1iwlSuIlnhg gMDER+wtOELBVPR8bMXe2rDG1xU7ep2IemFBfanujOhnVewUFC1I3Gf7BWi8nugx 0vxa8622QN2eDCzUp5tMGEWaa1u9mAg4zzTv4OGeoB6/P7dIktN0/4M22geV9N6e B7FTw3AZIzdpEkbGZPLNQ/0DIq/S3T5eZWzF3Nqgbbg4npPF1Yw= =U/Sz -----END PGP SIGNATURE----- --VbJkn9YxBvnuCH5J--