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 1phY6x-000321-6W for pgsql-general@arkaria.postgresql.org; Wed, 29 Mar 2023 15:53:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phY6v-0001oZ-IG for pgsql-general@arkaria.postgresql.org; Wed, 29 Mar 2023 15:53:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phY6v-0001ja-3l for pgsql-general@lists.postgresql.org; Wed, 29 Mar 2023 15:53:17 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1phY6p-0008Ig-SY for pgsql-general@lists.postgresql.org; Wed, 29 Mar 2023 15:53:15 +0000 Received: by mail-ed1-x533.google.com with SMTP id t10so65087978edd.12 for ; Wed, 29 Mar 2023 08:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; t=1680105190; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=COMOLMf0en6TcMvZVZD20WqBcEUljPEdc4xThCTdRXA=; b=0g//3UehMnLVfPJJ2YRsPt0Pej8BT4L+Kmm7dPVpk3lekWCJ+mdGmgkpfsxQ9126RM 0+R6YSj+13tt8gpB5aW3ECBursvtYS1ZzOXZmAcpUvyXqJaN9voi0zfS9syQhC3oTfrT akY6yEvOu67GEhe/wS0TEsgsPAWSf1otk5XbSH0eqt62ykzzq6kge/DeCjIAiiFiot62 rQ8rMj+ZBZkW7Rjm7tORSz+N4youQnE9xz0dT3ebacj4OE3Q/L3wchJQ9881w8HBp07/ mhcK6HIBbx8D5YTi/QP6jYhjZ9Dmfjg9mqAoBObRRUBj/uSMYy8Js5W7TNcMY+zkjiu7 3fAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680105190; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=COMOLMf0en6TcMvZVZD20WqBcEUljPEdc4xThCTdRXA=; b=Lubh5i8YmZBORxhrqrPQe6xrrBg/3+M1hz5nwuKYYo6kj+Q5wlnICCq0RhvGSs5t/b GZn9Sa8uJLWr3UcLwVv8f3LHPTl+spgX95Z3HdD0/QesHguXmBPq7DmarjPKD0eracuc ST5w5pFC/5JDsauKim/16h84zPBzADodBmCNAYQcUP2+/FNKsG24BcnKwnFTLp6a4vrQ H+RPIfjGp/y4s5jQzG4A+zWjbM5XKJ3kDrHy0cXF1aR08shh5zhVpMaKWtQ78wYmScJe IqVD7T9jlMJOq/DQbKSN3Q11M+SlWHTvQk45aJtpQP/uJpIzrT7nTFbfwslMD7wsJsf5 CZEg== X-Gm-Message-State: AAQBX9e2AEUXYs/Ab8Q99R20ccWNGgpNlrfFW2nXXl0RgIIYqG6hWsjy Tae3tJAyeuxOnieMbWgEJcZ3u4YaeiEiD1kCTRQ= X-Google-Smtp-Source: AKy350YmMDMC0vsuO8b6fvNf3q2ywovwaIxD5r9U4zCvTRgFlI1z20TFTU47NO2iA3Veo6x1qwRBag== X-Received: by 2002:a17:906:b15:b0:931:b4d3:fc7f with SMTP id u21-20020a1709060b1500b00931b4d3fc7fmr20088037ejg.30.1680105189729; Wed, 29 Mar 2023 08:53:09 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:ed2e:ab08:de54:20e:7f39]) by smtp.gmail.com with ESMTPSA id v8-20020a1709063bc800b0093341746105sm14833045ejf.117.2023.03.29.08.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 08:53:09 -0700 (PDT) Message-ID: Subject: Re: Using CTID system column as a "temporary" primary key From: Laurenz Albe To: Sebastien Flaesch , Kirk Wolak Cc: Geoff Winkless , pgsql-general Date: Wed, 29 Mar 2023 17:53:08 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2023-03-29 at 14:23 +0000, Sebastien Flaesch wrote: > From: Laurenz Albe > > It is safe to assume that the CTID is stable within a single transactio= n > > only if you use REPEATABLE READ or better transaction isolation level. > > > > With READ COMMITTED, you see updated rows (and consequently changed CTI= D) > > within a single transaction.=C2=A0 And if you use SELECT ... FOR UPDATE= , you > > could even see a changed CTID within a single statement. > > > > So don't use CTID to identify rows unless you use REPEATABLE READ or be= tter. > > Thanks for the advice about REPEATABLE READ isolation level! ... but that is only useful in a read-only scenario. If you try to UPDATE the row in a REPEATABLE READ transaction, you will get a serialization error if there was a concurrent update. In short: don't use the CTID to identify a row. Yours, Laurenz Albe