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 1x9h6x-00000002AjY-23gQ for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Sep 2026 10:55:31 +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 1x9h6u-0000000B99D-3sPU for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Sep 2026 10:55:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x9h6u-0000000B995-1vrq for pgsql-hackers@lists.postgresql.org; Thu, 24 Sep 2026 10:55:28 +0000 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x9h6r-000000010wm-1NZA for pgsql-hackers@lists.postgresql.org; Thu, 24 Sep 2026 10:55:27 +0000 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49d097b4939so10492415e9.0 for ; Thu, 24 Sep 2026 03:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1790247324; x=1790852124; 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=+wT7TVF4T0YZ68hM1aqOBqhhFhLKJY42VgFTkS+grJw=; b=Idq9thLdlUHWm9CHKR1ZVtL/Dpa0Ijw5QSfYyT8o8my3vuruvhbRLy+ej+/NLt+CtR LjJlmtx4ZucBv8rDYP2GG75p9X+05blM4ALgTsfvm/io2OhuqhjMGm7Bj+XXvLyht/pd 3wAm0jzRWyXZ+ARKkBlpymXOq71yYCFf/CbtvSsKXMx0uwIwNsZnrwoy1y12n3Irp1oZ 7mdnA4nv5Ru5DLjn9hYvhqNZeU+1ZH7sqFVUPZ4woGDIySz+sd8ZYg932ytVGPXseu9F cywQFw08ps6xn0lPr6eIlKqBXgiEaoO+SDJsxB85/RqPakvD0zA7PbnjCvbGMgC5UBJn haFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790247324; x=1790852124; 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=+wT7TVF4T0YZ68hM1aqOBqhhFhLKJY42VgFTkS+grJw=; b=qtqnHSrkX4o1ECFC1T6UXA7AjlQiAEFKph2sqyc57HJKYEFolgi3JVDH+IzlJtp78M cndXkBig8ZEuxsW/enRZ0uUsBwKuou07IO2BAZzU4Kn3p2qAXzTcmsHGuGZd+oKggJhr 24d/I8fhu+rFv9Sjuoh+ijOiV4yQNA1YswK8VuYNjIRvM1M2jbkkxMx7qWSdELOc1l9W KkoFhOdZVNLEE6wRJIBlnf/MJn5wbq3k67lLLkQ+PIVl9xBYYkDXzfNVvL2/vh2+pNCA aQazKmxamxBNHcGTxBBNFptWATNViS5otOW3mJbjzMqOQYO0M2gFSzaaRiLNrq6bvKUa NgWg== X-Gm-Message-State: AFuF++nz/Tg+jGRTlHoFc9C6QwSujKA2rUXfNHTwIS3lkmbCN9348OIP VebJ0MnGuV8rsGoXpuf3j5rBI8cszB961y9HtFdCY8Kpd3A2JJZSIgXDygh5WYzTn9E= X-Gm-Gg: AYBFou3NI6f57mHyjDHdjyBDuBF0btMRvENA+DLpCZfK7QFTdpKiQUwL8EBZY8LO3qf h36GrXVY69yevjX8K4wFkF6Y7AlZ7pvZw6t2mu36lKdpu638hueXv8VQngdBBeS54Lz8gcRsQNO PFbIehPjZWlnvvk2HJNwZQtkxH4rilJIWnpCAh/HKG2loU0ez4bd3qt7yajfj+D2ByAqr3UC3Bh 3ND/CmY+cwIIByuFiC4G7kZ4Foi3ukt0Fc7nnZcSVBdMIQxwJCFyoVJxtK+RsJ44tDGg3JhbR/A oW2xKR5v+1MAGmVgfzoEwFlLSkPZSU62hJ7BNgQtWGJZwzNyOwiOV+Yx6coHh/vKt+ufPKB5KSo LaO4ZZX+FRCVyban4Xis7WYfkjLHGXIiQu2Pu97SX+jvArorVZPmr6F+COXehY54FZdDMEuX73C KoAc5Cph3cVNzWJYxBlqg4b7kWFEUlzI3q4abNAD0Zvx3R8sBFbzvl3LFRLEPouWrytCsHvWRmK dkNJmCvgw== X-Received: by 2002:a05:600c:4e53:b0:49e:6861:50f7 with SMTP id 5b1f17b1804b1-49fe66c8921mr32025245e9.5.1790247324221; Thu, 24 Sep 2026 03:55:24 -0700 (PDT) Received: from localhost (109-81-170-16.rct.o2.cz. [109.81.170.16]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe5df44f9sm54577085e9.11.2026.09.24.03.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 03:55:23 -0700 (PDT) From: Antonin Houska To: Manu cc: pgsql-hackers@lists.postgresql.org Subject: Re: REPACK enhancements In-reply-to: <179017302006.2626644.6788432141295311288@gmail.com> References: <28303.1790158015@localhost> <179017302006.2626644.6788432141295311288@gmail.com> Comments: In-reply-to Manu message dated "Wed, 23 Sep 2026 11:17:00 -0300." 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: <18679.1790247323.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Thu, 24 Sep 2026 12:55:23 +0200 Message-ID: <18680.1790247323@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Manu wrote: > Antonin Houska wrote: > = > > > 3. 0008: assertion failure in compute_new_xmax_infomask() > > > > I don't know at the moment when the XID could get assigned. I need to > > do some investigation. > = > I measured it, so you don't have to. gdb attached to the backend > running REPACK, breakpoint on AssignTransactionId(), backtrace on every > hit (script attached). In a whole REPACK (CONCURRENTLY) run there is > exactly one hit, and it is this one: > = > #0 AssignTransactionId (xact.c:644) > #1 GetCurrentTransactionId (xact.c:461) > #2 LogAccessExclusiveLockPrepare (standby.c:1465) > #3 LockAcquireExtended (lock.c:1008) lockmode=3D8 > #4 LockRelationOid (lmgr.c:115) relid of the new heap > #5 heap_create_with_catalog (heap.c:1294) "pg_temp_16384" > #6 make_new_heap (repack.c:1709) > #7 make_new_heap_for_repack (repack.c:1389) > #8 rebuild_relation (repack.c:1230) If this was the reason, the assertion would be pretty easy to reproduce. > ... > That makes the Assert unsatisfiable from that side: by the time the > replay calls heap_update() for a change whose xmax belongs to another > transaction, GetTopTransactionIdIfAny() is necessarily valid. It is > not that the XID is assigned too early by accident - there is nowhere > later to move it, short of creating the new heap in a separate > transaction. This XID assignment is fine - make_new_heap_for_repack() eventually starts= a new transaction, and the reason for it is exactly to get rid of the XID. > > > 4. Progress reporting > > ... > > Do you mean that we should add variants of WRITE_NEW_HEAP and > > REBUILD_INDEX specifically for the auxiliary table? > = > Not necessarily - I think there are two separate things in there, and > only the second one is a design question. > = > The first is a plain reporting bug: build_new_index() sets the phase > for indexes that are not the table's own - the identity index of the > empty new heap This one *is* the table's own. Admittedly, if the table is empty, it's not really index rebuild. Although reporting rebuild for pretty short time is probably not a serious problem (the user can hardly notice this waiting), = we might want to skip updating the REPACK progress in this case altogether. Moreover, we can skip the actual build, as an existing comment= in make_new_heap_for_repack() indicates: * XXX NewHeap is empty - should we pass INDEX_CREATE_SKIP_BUILD? However, I don't know if REPACK_INDEX_REBUILD_COUNT should then be increme= nted or not. If we increment it, we still consider buidling an empty index a "rebuild". If we don't, the final value of the counter will be wrong. Mayb= e increment the counter when the data copying is done, but that seems unnecessarily complicated. > and the indexes of the auxiliary table. This might be worth a separate phase: if we report the phase REPACK_PHASE_REBUILD_INDEX, we should probably also increment the REPACK_INDEX_REBUILD_COUNT counter. And if indexes on the auxiliary table = are included in the counter, user might be confused to see more index builds t= han the number of indexes on his table. > That alone is what makes "rebuilding index" appear before "seq scanning > heap", and twice with USING INDEX. Not setting the phase for those inte= rnal > builds fixes the order without touching the catalog or the docs. I concur with [1] that order is not a problem. > The second is what the auxiliary table's work should be reported as, > and there I would rather not add new values. Today, with v03 and > USING INDEX, SORT_TUPLES and WRITE_NEW_HEAP are never reported at all, > while the "REPACK Phases" table in monitoring.sgml still says > "REPACK is currently sorting tuples" and "REPACK is currently writing > the new heap". A user watching pg_stat_progress_repack on v19 and on > v20 would see two documented phases disappear. WRITE_NEW_HEAP should be used in process_auxiliary_table() - I'll fix that= , thanks. Regarding SORT_TUPLES, the actual "sorting" is implemented as an i= ndex build and scan, so there's no need to report this phase. And no, the phase will not disappear from the documentation because REPACK w/o CONCURRENTLY = will still use it. > > With the auxiliary table, sorting IMO hapens in two phases: 1) build > > the clustering index and 2) scan the index and insert the output into > > the new heap. As long as each phase is reported on its own, I don't > > see room for SORT_TUPLES. > = > Your two phases map onto the two existing values, I think: (1) is > where the tuplesort actually runs, so that is SORT_TUPLES, and (2) is > WRITE_NEW_HEAP. That is the room for SORT_TUPLES - the sort is the > index build. It keeps the documented set of phases intact and needs > no catversion bump. I see your point now, but not sure this is a good idea. If the user sees t= hat sorting takes too much time, and if he's familiar with PG internals, he's likely to conclude that increased maintenance_work_mem will help. However,= in this special case it will not because the tuplesort engine is not involved= . [1] https://www.postgresql.org/message-id/CAN12%2BYKo-vjvdPQts6QnHoB3ET5A2= or137oN_FGMviQdtYLN6Q%40mail.gmail.com -- = Antonin Houska Web: https://www.cybertec-postgresql.com