Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x9PkJ-00000001zA4-2i6L for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Sep 2026 16:23:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x9PkI-00000006MBP-0Jix for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Sep 2026 16:22:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x9PkH-00000006MBH-3C1n for pgsql-hackers@lists.postgresql.org; Wed, 23 Sep 2026 16:22:57 +0000 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x9PkE-00000000uMM-3sKn for pgsql-hackers@lists.postgresql.org; Wed, 23 Sep 2026 16:22:57 +0000 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ccfd61ecaso9094335e9.3 for ; Wed, 23 Sep 2026 09:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1790180572; x=1790785372; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to:content-type; bh=YteAfKk0yblaQruYGN2yj/b0tPRwu2zJZRPxlhu9Et4=; b=UI7rSb/RO90JIf6m+xMO5MntYX3nxeJ9TDW+YoV6cJi7jx4NysA46EvkbqbrzMOERh l55Ft0uK1gk9wHQK8zGQ3kWgLNfwN62rKqb5fA2l5U3WRPTjZeqlCcOs2gvBfpe0/595 SQValD21iYvVmcZrdre8xXJk7dv94Nl66X41Yl60Dl8GJ1/DtWl33dEpPemzAcc2VJo6 2oOzoqkcy5j9h+NCJO2c0CbkkUSwP6RpXmnFaq/6lWnoEbLm0knG0HgNtcEcAd3ePScP vFWCqwxpDs7nu1PhM2eOKDcIAhEo/w+fm3O5cY5dTwmnQ62zm5DYbjPrALgA1R5vJKHT aq6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790180572; x=1790785372; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=YteAfKk0yblaQruYGN2yj/b0tPRwu2zJZRPxlhu9Et4=; b=HmWZtuQ7Z0htv0i+Yc/z/ooZKjnx9kt4DHSkUVe94IKSXcKPxjaTIOLlDRt+/IWKVz 9pyWpKhSbi+wfJ2lY8QcgY5EZLwxYsZ5LJGC1aYnoiyJiz+fcn2BrALGFUDsCmZKmoP/ 9tGuIeBcQIXeFQEXM/1CVJsi+bBV0Tdt4FROupF3CEdFU8c7ZS06M0prU6/Fp/9PvCzl iQqF42rkdjmHZtae1VlZWT7CLICBpHnoTvUhju432bf9g7x38JZ3DuEwk7gzqnAYiDcQ +uKzEdtedHPgzXfOLXi//8F8trZr9KWGFKE4ZYuC7rhf2NTV2RQA8d2febcHnjAwSwpg cvbg== X-Forwarded-Encrypted: i=1; AKwUvBwfjsN8ooAuVFW9ZipAmPxY1GmtjayAsFFYaCzLpTnPNqe1VWo/AH5uege19qbfrTLuPTbhSrglM1vvt8wH@lists.postgresql.org X-Gm-Message-State: AFuF++ku1PrTj4I/y0fESNxxfJViq/fp6COfiyF3Z3ktc4QsAw+9+nGw YaKwvx3cQlaxJv2Dyv5nGAAnysALaLg/Cn6/kxGEljnWX2cdYIp2qHkiNObSObgs/TY= X-Gm-Gg: AYBFou28/02U1SFDs5mHKirjhv5ZFgpJvrhNN4Xrg/IDoJWgEHSxyqD8rRBoNpSS/be f5A/3ft5mwYFUQgeW+GVWLGfUZoRv/tRGWHt8Hn/+W6NfqMtI0RTi8wvn09zDe3J5S8dB1/HMET UVDlyaEwtBrDJzGUexi2bLnSAh50KuewvzPqoDFeWwsTknZji0ETYOh2Nv7xG9olc6EdcwAblKz Kf2XnqhkwaqzHhMaD3t7L8BwNnfiygQJjnb22sfy21qdDRiINJMja1x8pb6Hn9eDenKRCM0yfNM m08vIsTjqF5QoqtxZJCAQhQ6IlqhfzxxPnOvdQb8Sw8cmJitKY5kRjDY40zpOe7WzfL5IGENSBk Gz+YyDeU45xoK4YmwM7ExdzGR8dcAImp2CBnWhG97jprLa5N7F0M8s0s7+WLmlLx/dJe9X0H6n3 UdY9WuwafUP8xJZX2R9C94SkN6bSfi+aZ03Si4BQFi8J+2DHB9Fpe3P8YX+Dh35k46UYfEuYpTQ /xrrHJjckQ= X-Received: by 2002:a05:600c:6304:b0:49e:8418:3858 with SMTP id 5b1f17b1804b1-49fdeffdfd6mr44036995e9.9.1790180572397; Wed, 23 Sep 2026 09:22:52 -0700 (PDT) Received: from localhost (109-81-170-16.rct.o2.cz. [109.81.170.16]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe3d7916asm29986125e9.15.2026.09.23.09.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 09:22:52 -0700 (PDT) From: Antonin Houska To: shihao zhong cc: Manu , Thom Brown , pgsql-hackers@lists.postgresql.org Subject: Re: REPACK (CONCURRENTLY) can silently lose updates when the toast table is rewritten In-reply-to: References: <179012413951.1850281.5077495683381671561@gmail.com> Comments: In-reply-to shihao zhong message dated "Wed, 23 Sep 2026 01:09:48 -0400." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <47478.1790180571.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Wed, 23 Sep 2026 18:22:51 +0200 Message-ID: <47479.1790180571@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk shihao zhong wrote: > > or whether the relfilenode should be re-checked after the snapshot is = built > = > Holding the toast lock from the start deadlocks. A session that asks for > AccessExclusiveLock gets an XID before it waits, and the decoding worker > waits for all XIDs while it sets up. The same (supposedly low) deadlock risk already exists for the main table,= see this comment in rebuild_relation(): /* * Start the worker that decodes data changes applied while we're * copying the table contents. * * Note that the worker has to wait for all transactions with XID * already assigned to finish. If some of those transactions is * waiting for a lock conflicting with ShareUpdateExclusiveLock on our * table (e.g. it runs CREATE INDEX), we can end up in a deadlock. * Not sure this risk is worth unlocking/locking the table (and its * clustering index) and checking again if it's still eligible for * REPACK CONCURRENTLY. */ start_repack_decoding_worker(tableOid); I'm not sure if locking the TOAST relation earlier would make the situatio= n worse. The reason TOAST relation is not locked until copy_table_data() does so is that CLUSTER / VACUUM FULL in v18 did it this way (not sure what the reaso= n for such design was). I haven't changed that for REPACK exactly because I failed to envision this stale relfilenode issue. -- = Antonin Houska Web: https://www.cybertec-postgresql.com