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.94.2) (envelope-from ) id 1tewBG-00GUjs-2P for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Feb 2025 13:08:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tewBF-00DnVU-7R for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Feb 2025 13:08:01 +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.94.2) (envelope-from ) id 1tewBE-00DnVM-SI for pgsql-hackers@lists.postgresql.org; Mon, 03 Feb 2025 13:08:00 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tewBB-0032Yp-2x for pgsql-hackers@postgresql.org; Mon, 03 Feb 2025 13:08:00 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5d3e9a88793so6953099a12.1 for ; Mon, 03 Feb 2025 05:07:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1738588077; x=1739192877; darn=postgresql.org; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to; bh=C3VpMsMVsEPyBxWPzqSPgDCGd4UjyOpHkuMOOE0C3Pg=; b=QfhkWPGwQAw4NtLo6WCZlkxGNA+850hGt+mPWNMQX+HGsxFcwCNwJ+lLiIJWXNGrTb lMogxjMVkvU9LCzMo69INlP8N5ANUqwPp9gOaDJsNq4wJXN6Kfu/s4R9dQuYCM/SnaiY 6b8Iw3146YXvEpApaM2GCKNFY6kr184eI6AUHFsfE3nYhlFD//yDfhoWPsVALfUX3VgK dvoqCiEFvGJica0Lv99dVkfqKdr9/paNk9FxybZ788vbgZowYqGCwp5UFvtqerf11bd/ faPJSNmZ5YfJZKShUGjR7Sb0MoLWITKiO/ImHpKYpRzeFJS81xdy+YDfX3DJAnAFuOUy dHZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738588077; x=1739192877; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=C3VpMsMVsEPyBxWPzqSPgDCGd4UjyOpHkuMOOE0C3Pg=; b=MmmvLr+GZ3E+xvBvDM0JtTzt1LFlFTZ+hFKHMCrYB+Ilh2VfdTKr441zGLJ1L4sXfV RKBWP8OzHhJSSj94h7qcog4OtjiVh8APDtnULzpYSJdsMXf7npTnGCPFiJzI7ehH9MbY p/hjIv3y/qGJMHVj5Mln3kq9wdNBi3iw9TM4UCJHpzFuteHXpGbdV/2rPv1iRtgFXuzP qDQ6wPCH+cwH/iGGPQ9w/LbyQXv4liX/ykFFwqPz85GGhU/SOddROPdowUXB+jOd1Sa0 hDu6ZyysPEm9Ta55xru94X6JQAPGbjdvHXZa44kaas6VkdPYSpm8e60gfpsJqWuEGTL9 15dw== X-Forwarded-Encrypted: i=1; AJvYcCVVPK8vk2nC/0HGbOkU+czZ7GSxD6gRZkKPq4zVDEShVEXiw7/Y1bXW84NkHSVQtchELwlEFagL78/Ypv+S@postgresql.org X-Gm-Message-State: AOJu0YyYtwMMWY/oWarHgApDw6VyaLqdo4tzFkAPxS3WHDXjs61TzWig LGp6mBoiOuQQZM6snBV1l8nU4f3XE1Yfux2nELr0XBPia+jdURMQAAw5v6VBTUg= X-Gm-Gg: ASbGncvBxA+ebgO5wVPzZhgBSSh/x50o9BB6gti5vzNOgmXjmvCG67BjPi1Rae24apw xSnxnyPNV5rPxwUkPKsjTudM2ay9dTwkrjUg40oHF6jXVugZejTEaDf8U6VoUygJHOjJuwskI5D 5n8COtHIm6YXaKAJ8s7RQD5a81vf83ZyoUzz05SzxLjMLwU1+wBm7NbbM2KmQA4BDjrhFM0CGlG CD8TXnqh8fQeh2WaL9T6OzRJbqaMZVLw1O7x3Q9ms1PkwLA+/Z3ZRwv4kIK7r45dnFJcL4nb+4s XrbZ/UlP2vXOtVZLiTc= X-Google-Smtp-Source: AGHT+IEiPUbYHfdh7MrYG5HdQtt1Q0jqVrDhS+mOyPob+TyH3zH5laa60unosxIvZONt5C3usTMp4w== X-Received: by 2002:a05:6402:34d3:b0:5d9:a62:32b with SMTP id 4fb4d7f45d1cf-5dc5efa2f11mr25654633a12.7.1738588076546; Mon, 03 Feb 2025 05:07:56 -0800 (PST) Received: from antos (109-81-174-36.rct.o2.cz. [109.81.174.36]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dc724be323sm7703614a12.65.2025.02.03.05.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 05:07:56 -0800 (PST) From: Antonin Houska To: Alvaro Herrera cc: Junwang Zhao , Kirill Reshke , Pavel Stehule , Michael Paquier , PostgreSQL Hackers Subject: Re: why there is not VACUUM FULL CONCURRENTLY? In-reply-to: <2879.1738566105@antos> References: <202502021321.6ul3axwpsklw@alvherre.pgsql> <2879.1738566105@antos> Comments: In-reply-to Antonin Houska message dated "Mon, 03 Feb 2025 08:01:45 +0100." 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: <20611.1738588075.1@antos> Content-Transfer-Encoding: quoted-printable Date: Mon, 03 Feb 2025 14:07:55 +0100 Message-ID: <20612.1738588075@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Antonin Houska wrote: > Alvaro Herrera wrote: > = > > = > > = > > > From bf2ec8c5d753de340140839f1b061044ec4c1149 Mon Sep 17 00:00:00 20= 01 > > > From: Antonin Houska > > > Date: Mon, 13 Jan 2025 14:29:54 +0100 > > > Subject: [PATCH 4/8] Add CONCURRENTLY option to both VACUUM FULL and= CLUSTER > > > commands. > > = > > > @@ -950,8 +1412,46 @@ copy_table_data(Relation NewHeap, Relation Old= Heap, Relation OldIndex, bool verb > > = > > > + if (concurrent) > > > + { > > > + PgBackendProgress progress; > > > + > > > + /* > > > + * Command progress reporting gets terminated at subtransaction > > > + * end. Save the status so it can be eventually restored. > > > + */ > > > + memcpy(&progress, &MyBEEntry->st_progress, > > > + sizeof(PgBackendProgress)); > > > + > > > + /* Release the locks by aborting the subtransaction. */ > > > + RollbackAndReleaseCurrentSubTransaction(); > > > + > > > + /* Restore the progress reporting status. */ > > > + pgstat_progress_restore_state(&progress); > > > + > > > + CurrentResourceOwner =3D oldowner; > > > + } > > = > > I was looking at 0002 to see if it'd make sense to commit it ahead of = a > > fuller review of the rest, and I find that the reason for that patch i= s > > this hunk you have here in copy_table_data -- you want to avoid a > > subtransaction abort (which you use to release planner lock) clobberin= g > > the status. I think this a bad idea. It might be better to handle th= is > > in a different way, for instance > > = > > 1) maybe have a flag that says "do not reset progress status during > > subtransaction abort"; REPACK would set that flag, so it'd be able to > > continue its business without having to memcpy the current status (whi= ch > > seems like quite a hack) or restoring it afterwards. > > = > > 2) maybe subtransaction abort is not the best way to release the > > planning locks anyway. I think it might be better to have a > > ResourceOwner that owns those locks, and we do ResourceOwnerRelease() > > which would release them. I think this would be a novel usage of > > ResourceOwner so it needs more research. But if this works, then we > > don't need the subtransaction at all, and therefore we don't need > > backend progress restore at all either. > = > If this needs change, I prefer 2) because it's less invasive: 1) still a= ffects > the progress monitoring code. I'll look at it. Below is what I suggest now. It resembles the use of PortalData.resowner i= n the sense that it's a resource owner separate from the resource owner of t= he transaction. Although it's better to use a resource owner than a subtransaction here, w= e still need to restore the progress state in cluster_decode_concurrent_changes() (see v07-0004-) because a subtransacti= on aborts that clear it can take place during the decoding. My preference would still be to save and restore the progress state in thi= s case (although a new function like pgstat_progress_save_state() would be better than memcpy()). What do you think? @@ -950,8 +1412,48 @@ copy_table_data(Relation NewHeap, Relation OldHeap, = Relation OldIndex, bool verb * provided, else plain seqscan. */ if (OldIndex !=3D NULL && OldIndex->rd_rel->relam =3D=3D BTREE_AM_OID) + { + ResourceOwner oldowner =3D NULL; + ResourceOwner resowner =3D NULL; + + /* + * In the CONCURRENT case, use a dedicated resource owner so we don't + * leave any additional locks behind us that we cannot release easily. + */ + if (concurrent) + { + Assert(CheckRelationLockedByMe(OldHeap, ShareUpdateExclusiveLock, + false)); + Assert(CheckRelationLockedByMe(OldIndex, ShareUpdateExclusiveLock, + false)); + + resowner =3D ResourceOwnerCreate(CurrentResourceOwner, + "plan_cluster_use_sort"); + oldowner =3D CurrentResourceOwner; + CurrentResourceOwner =3D resowner; + } + use_sort =3D plan_cluster_use_sort(RelationGetRelid(OldHeap), RelationGetRelid(OldIndex)); + + if (concurrent) + { + CurrentResourceOwner =3D oldowner; + + /* + * We are primarily concerned about locks, but if the planner + * happened to allocate any other resources, we should release + * them too because we're going to delete the whole resowner. + */ + ResourceOwnerRelease(resowner, RESOURCE_RELEASE_BEFORE_LOCKS, + false, false); + ResourceOwnerRelease(resowner, RESOURCE_RELEASE_LOCKS, + false, false); + ResourceOwnerRelease(resowner, RESOURCE_RELEASE_AFTER_LOCKS, + false, false); + ResourceOwnerDelete(resowner); + } + } else use_sort =3D false; = -- = Antonin Houska Web: https://www.cybertec-postgresql.com