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.89) (envelope-from ) id 1hC6lU-0007oG-5d for pgsql-general@arkaria.postgresql.org; Thu, 04 Apr 2019 18:07:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hC6lS-0000vx-Qp for pgsql-general@arkaria.postgresql.org; Thu, 04 Apr 2019 18:07:02 +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 1hC6lQ-0000oj-Uv for pgsql-general@lists.postgresql.org; Thu, 04 Apr 2019 18:07:02 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hC6lN-0007Ru-JJ for pgsql-general@lists.postgresql.org; Thu, 04 Apr 2019 18:06:59 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E7C516242; Thu, 4 Apr 2019 14:06:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 04 Apr 2019 14:06:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=m ChcHAyw3uQ6jJsQWGLYw3RgyYCR4t2ak25O3QbVYfE=; b=C90daBKRzDhLRFNDi INcFpRzDYYJFe0Cx3jo/3ln3GoCAaduKY/WUqEpoIGP7p8dZNIaP/NbPcsjX7Bzc 8JU9pcB85mDlY/WtFSPtVcQ6Pb5XMMtVFrHkW9RwMba2nWSsoLn90XM/aDCORzxT W2tf7dgVNqLNJ0QbMZ/miPqNNHT7mj8KG6Yy1k5asa1rarUqXJRj6YrIv7RCBwJW E+SweI9OpynQQ+lT/su7N0YaD16B+wGPrrTtCdNhFZQzqAcxrNA1I6P7aC7CtXYB DF/4K2YcvJBduqB+YQ3sKtIc5kBahuuybRGQA03LC5Wsbwak3fncNyaGB78w7uS0 Myd+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=mChcHAyw3uQ6jJsQWGLYw3RgyYCR4t2ak25O3QbVY fE=; b=gP/p97ZsXKjEcVx+9DSLOI8XrCjSBl9k/vH3DfmceZXfNVPIoB1VREUNF 9MMTvBMPUdoRznV3fMn3e67na3C9PrMCUXdH9NxCqWa8iGFt2TJJZlV48+onb0yq hejBFk6Nx+ILdS2jrtFSQPgjk6MBnXfqxAnmXn8u8BBMB5TDeTsd7sXLx5bs1JdC 2qwio+uhT63NUAOSjsUrCj8gezJQ4HK+6bYxIUya/vU5q2XhnwXfnup5C2NAyGcV 0GJILKVnJAj/uTiPshLiZ4WWPrdXaxtLqqXHRA1883s6RbMUxQMDCEcKNPAfv8Nx N9AwddfMKzPTWltN+W1dkIoJizLCQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrtdehgdduudelucdltddurdeguddtrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffgggjggtgfesthekredttdef jeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdho rhhgnecukfhppeejgedrleefrddutdehrddukeeinecurfgrrhgrmhepmhgrihhlfhhroh hmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgv rhfuihiivgeptd X-ME-Proxy: Received: from ranger.suse (74-93-105-186-washington.hfc.comcastbusiness.net [74.93.105.186]) by mail.messagingengine.com (Postfix) with ESMTPA id 31375E40D0; Thu, 4 Apr 2019 14:06:54 -0400 (EDT) Subject: Re: How serial primary key numbers are assigned To: Rich Shepard , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Thu, 4 Apr 2019 11:06:53 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 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 4/4/19 11:04 AM, Rich Shepard wrote: > Just out of curiosity, how does postgres assign serial primary key > identifiers when rows are inserted in multiple, separate working sessions? > > I'm populating tables using INSERT INTO statements in separate working > sessions and see that the assigned id numbers are sequential in each > session, but have large gaps from one session to the next. I don't care > what > id numbers are assigned yet would like to know how the starting number for > each session is determined, just because I expected the numbers to be > continuous. See: https://www.postgresql.org/docs/11/sql-createsequence.html The relevant part: "Unexpected results might be obtained if a cache setting greater than one is used for a sequence object that will be used concurrently by multiple sessions. Each session will allocate and cache successive sequence values during one access to the sequence object and increase the sequence object's last_value accordingly. Then, the next cache-1 uses of nextval within that session simply return the preallocated values without touching the sequence object. So, any numbers allocated but not used within a session will be lost when that session ends, resulting in “holes” in the sequence." > > Regards, > > Rich > > > -- Adrian Klaver adrian.klaver@aklaver.com