Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtR5s-0006TG-BP for pgsql-general@arkaria.postgresql.org; Thu, 09 Jul 2020 07:35:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jtR5L-0001kb-PI for pgsql-general@arkaria.postgresql.org; Thu, 09 Jul 2020 07:35:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtR5L-0001kR-Bl for pgsql-general@lists.postgresql.org; Thu, 09 Jul 2020 07:35:11 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jtR5E-0000w3-9h for pgsql-general@lists.postgresql.org; Thu, 09 Jul 2020 07:35:10 +0000 Received: by mail-wr1-x443.google.com with SMTP id j4so1204836wrp.10 for ; Thu, 09 Jul 2020 00:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=r+eaMb1amwgTxBlvY3mtEK94WsQtsbS7r/qpnuqGXtY=; b=nIEMmN+wOSln20ltejncVjcfiD0j+If85eFBOzx5InK+23v9rpZWVOhqH3Lm/9MIug /VaiZlxgRcWKMc/nmLJVdWe1iT+AOTC9p7kJLCv+UsmaErTkXQICkmXUvWRqdNjc75/4 sErpU4wl6h88TgbLefFZqgAq+ifFi5JNYK12Aq9Ix79D6utOAE+9JbQlpgnfTQMrgOIt r89wSl0ta3+lqr8Y/gcI2i/nY3QPAegEIXptWN0az+EDk7pWu5yZq084vr7YQhV8dL8/ vrQa8TJxlE4scUQFtns1dUJx55P/QPtFcN47G1YHLjfBsKu4JzXXaPOmtrB4Z/kEYIR7 yjIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=r+eaMb1amwgTxBlvY3mtEK94WsQtsbS7r/qpnuqGXtY=; b=CJLWQxyWoZ31vbPdbMnBYuSBIRh1WiJ5ph2A0/GuFbvHEIHEhMDOREEA7gm9WhumYl yya152lRKFW5/FvRgMB8s8MENFileJepgbS/qf5STDriGAGhsMTusG9TLSN/CCfth0Ui hQnIWdSQbgligaQwxcT22L6TzAGdi6Kfo04T0DJtoI1SPRHDHR6wiPzNa51PVtmkHSa3 HKlsVR+hrl/tq0+u1PwZGGCynma1M07/ScUiOP/frXcDYnGRxwovKDgiOytIbn31UG3i awIst+RkAYcRchyFvNJ4IxwE/Oe1hbWvXk294FFCEDb1einPXS6hCcnILUjDS96yzBxX 1a7w== X-Gm-Message-State: AOAM533Eo6BziCAgyWUIbvtUQYftCwfqcKmhFUXawLB/LTU+mTT9uPBI DebpSQfrwDN29sW2v5QA3IVKyg== X-Google-Smtp-Source: ABdhPJz0lzEudNZN6AIITYh2lUfdYMten17VF3kUeMBRvfa8ZFT4qjhHNAZAKXklVOaZO4RJ+Ev+Jw== X-Received: by 2002:adf:e701:: with SMTP id c1mr63364418wrm.350.1594280102952; Thu, 09 Jul 2020 00:35:02 -0700 (PDT) Received: from localhost.localdomain ([212.186.219.234]) by smtp.gmail.com with ESMTPSA id q188sm3432859wma.46.2020.07.09.00.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 00:35:02 -0700 (PDT) Message-ID: <47559cf2b1efa2904ea3d86749c3d87f1a3993c8.camel@cybertec.at> Subject: Re: BigSerial and txid issuance From: Laurenz Albe To: "Yorwerth, Adam" , "pgsql-general@lists.postgresql.org" Cc: "Cianciaruso, Lorenzo" Date: Thu, 09 Jul 2020 09:35:01 +0200 In-Reply-To: <4478EF79-0699-4FBA-B7C1-95561EF1DB5E@tesco.com> References: <4478EF79-0699-4FBA-B7C1-95561EF1DB5E@tesco.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2020-07-08 at 14:09 +0000, Yorwerth, Adam wrote: > We’re trying to solve a problem that relies on BigSerial and txid (as returned by txid_current() ) values being issued consistently. > > Is it possible for two transactions to interleave their issuance of these two variables? > > For example: > > Schema: > > CREATE TABLE EXAMPLE( > offset bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY NOT NULL, > txid BIGINT NOT NULL DEFAULT 1 > ); > > Insert statement: > > "INSERT INTO EVENTS (txid) VALUES (txid_current());"; > > Prior to transactions executing offset is 10 and txid is 1000. > > Transaction 1 and 2 occur concurrently. > > Is it possible for transaction 1 to be issued txid 1001 and offset 12 and transaction 2 to be issued txid 1002 and offset 11? Sure. Transaction IDs are assigned when a transaction is about to modify data, and for identity columns you get the next value when the backing sequence is called. There is no guarantee that both have to happen in the same order? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com