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 1jF5Hp-0000mt-S2 for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 00:13:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jF5Ho-0002g5-Kc for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 00:13:16 +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 1jF5Hn-0002ca-Eh for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 00:13:16 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jF5Hi-00056I-Ve for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 00:13:14 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BDCB15C019D; Thu, 19 Mar 2020 20:13:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 19 Mar 2020 20:13:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=m h6p7wYzpQQZNoBpPLHl4Z9lLj9jlosYCLmWsMJ7c6Q=; b=DHtMwi7pK3avG5Nn7 xheh0Cc2zN26PEfouhfWCd4Q6i0nHqAS/09XNpqKPRs0bwQq86N0CoqaDEMJiLG6 mcYcKnCr+ilBlKGhw42xIMWGEGXthh1oxucvxsQVZ62rcNJ+uy8dlXGACxsBHtUj LXjleUxXKlAsqbADwswxkmKJp+Q4L0fhJny6xhaWthVrLy/VmlsaB11Auz+QIifl +4PHWw0//I2kMMwqrGNGwQMG+RFqYSkWc57ZEpszFcYzeO4UfUjfKfBX4uSbSAqe 2VJkN4DZyUN8/+wwYjRGTnX+iFv+2IHKCL+cXHC4yizVw8a8ZgWVXH4Ey4OWRw93 SsIDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=mh6p7wYzpQQZNoBpPLHl4Z9lLj9jlosYCLmWsMJ7c 6Q=; b=2qBVs0Ry5/hly1Dffd/8QOVM4fvjkqkoQPMc2+p3YBYyYNxQynnV1FvVp rHuhqhLrBNwuLsd8c2v3BSgQsYrFZK1D6gVdlkNc8t1zZ/ODrrJrAUU9075cyUqT Wqr6sR2AZ6E8pS7tFKWnVnImIJ1xS1xiw+FOK82JLAczdecyPbOFfY0ywBc4Fwfw GdKkPGszHyGqDh4+3RRNYJINz00VTM9F6kTsGb4jWyzOSlPO59HW7ngv0UiFSdKc dCo/1cubbxECsSD/88i3SE5dl2kcX57iUeMRFhpw2omgrX4nmWEyMSzqsXXJ9bS1 7NjH+PpLIO6c1bA3T44Ua8OCJEkUw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudegtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepshhtrggtkhhovhgvrhhflhhofidrtghomhenucfkphepjedu rddvuddvrdduvdelrdduleefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id CE846328005D; Thu, 19 Mar 2020 20:13:07 -0400 (EDT) Subject: Re: Could postgres12 support millions of sequences? (like 10 million) To: pabloa98 , Rob Sargent Cc: "pgsql-generallists.postgresql.org" References: <7CF69CD4-AE4A-4C2B-9621-4462B4AE1726@gmail.com> From: Adrian Klaver Message-ID: Date: Thu, 19 Mar 2020 17:13:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/19/20 3:32 PM, pabloa98 wrote: > > > On Thu, Mar 19, 2020 at 3:17 PM Rob Sargent > wrote: > > > >> On Mar 19, 2020, at 4:13 PM, pabloa98 > > wrote: >> >> >> >> On Thu, Mar 19, 2020 at 2:50 PM Rob Sargent > > wrote: >> >> >> >> > On Mar 19, 2020, at 3:36 PM, pabloa98 > > wrote: >> > >> > Hello, >> > >> > My schema requires a counter for each combination of 2 >> values. Something like: >> > >> > CREATE TABLE counter( >> > group INT NOT NULL, >> > element INT NOT NULL, >> > seq_number INT NOT NULL default 0, >> > CONSTRAINT PRIMARY KEY (group, element) >> > ); >> > >> > For each entry in counter, aka for each (group, element) >> pair, the model requires a seq_number. >> > >> > If I use a table "counter", I could still have counter >> collisions between 2 transactions. I need truly sequence >> behavior. Is that possible by using a table like "counter" >> table, where the counter could be increased out of the >> transaction so it performs as a sequence without having race >> conditions between concurrent transactions? >> > >> > The other option is to create sequences for each new pair of >> (group, element) using triggers. There are millions of pairs. >> So this approach will generate millions of sequences. >> > >> > How a PostgreSQL database would behave having millions of >> sequences in a schema? Would it degrade its performance? Is >> there any negative impact? >> > >> > Regards >> > >> > Pablo >> > >> >> To clarify, are you hoping for consecutive numbers as the each >> row is added to the table, i.e. “serial”? >> >> What is the intension of “seq_number”? >> > >> > >> >> >> the idea is to have like a serial sequence, but for each pair of >> (group, element). >> >> so that when we insert rows in another table, we could have >> something like: >> >> >> group, element, event_id, ... >> 1, 1, 1 >> 1, 1, 2 >> 1, 1, 3 >> 2, 1, 1 >> 1, 1, 4 >> 1, 3, 1 >> 1, 1, 5 >> 1, 3, 2 >> 2, 1, 2 >> 2, 1, 3 >> >> The 3rd column is the sequence number we get from the appropriate >> sequence created by the trigger. >> I want to implement a variation of >> https://stackoverflow.com/a/30204854 and that will generate >> millions of sequences. >> >> > Then I don’t thing group/element can be a PRIMARY KEY > > > Thank you for your answer. Let me explain: > > Table "counter" will have triggers that will create a sequence with a > new row is inserted called counter_1_1_seq, counter_2_1_seq, > counter_1_3_seq, etc that will be used to insert values in **another** > table. It will be used for nothing else. When we insert millions of > pairs group/element, the trigger in that table will generate millions of > sequences. This has train wreck written all over it. If you are going to have a trigger for each combination of (group, element) I gotta believe the table will fall over before you run into sequence issues. Not sure why there can't be serial column that has supplies the sequence numbers and therefore only one sequence in play. From what I see all you care about is that: group, element, event_id has an increasing event_id for (group, element) pairs. > > My question is how PostgreSQL will behave. Could it deal with millions > of sequences? What about system operations as vacuum, etc? > > Pablo -- Adrian Klaver adrian.klaver@aklaver.com