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.96) (envelope-from ) id 1w5DVv-0031EE-0I for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 01:58:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5DVt-00APUQ-1t for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 01:58:30 +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.96) (envelope-from ) id 1w5DTd-00ALs9-0j for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 01:56:09 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5DTa-00000000yqq-3JET for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 01:56:09 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2b04e6a989eso12082665ad.3 for ; Tue, 24 Mar 2026 18:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774403765; x=1775008565; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TKygWOE+UMqDnxAm1BQEYbTAqEKuPEAG9SGqak7kQTc=; b=YmpP7em9agoMBpwE3a7cgDSaj+w1M/YNexwIOGCxHcDO8MnihxduOXulmyrale2D/T uH6LfWUWTam1tjuAlyHD84O7XkclraheGz/WIKpbV/vE3ttlM1DCgAbCPWNop8UNEYLH fAQ0PpMxk8lL9sHeT/X6inX/3UBNxBzMxYms7DtQz+540OxEaCjIr3y7zlqsFZYAOWra d76JmpxOovGm8LSnTDuhTwK1hGARJ8E+F8WxnVqdfkioxaO70Jz5PFh6BXg1NmrCuv7Y 3w/Qtg3lOPNYk2eTgPhhXbWzPmC4UQV0PgYbVOD8HqoLmnMLRybeyOn7tAY0bs2iVOX4 PCng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774403765; x=1775008565; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TKygWOE+UMqDnxAm1BQEYbTAqEKuPEAG9SGqak7kQTc=; b=aOu0VV4zzU+QnB7t+oNq6bfEykLJap9Npr9+lZjo3bq4pExduseSg0pdxUYbU8IiaE LwipwcBpSm3lM1LMj47dH7MF+5iVOcfw826uK8S3Rys5FMrGW/h6DQ4ETUAcuLbYwW8C Hm41J+jYQfA7hWaxMo6yg7aiAEUCmsQUI9JtbBBabZR9P0nLkHh+/aEjG+p0iw6pRWwf i/5rc1ORD6TzYionipA6r1wJFWT2pJP4xxQuOqYWOLJog0Tvw27RY/xaRuofZko99VRI QK6nhbGq/fd/8QAvle4ObqH7j4AenaQR5a7aMtWrxavltKf+fpPl8305kR0CKhQJaMur zIQw== X-Gm-Message-State: AOJu0YznRstSL/WubQOZ7R7YtPje+KCXQ8dZNWhR8GLQ8vOsL3ITOAnM BV2g5cFi5xfVb9lGQ3pUi40LnnScXL2e+L4k5UcPTeGS2FcF/S3zFLNQ X-Gm-Gg: ATEYQzz/fifsZ88CxpSONcJufOuhX875Z+YVC8NJXHphtsuFPaPkpbd/dGlVfQt+5X4 0VBfTprppFD/2QTs9rkZF4J5/35adexLA5H53wvYRZanf62RZgro3mfjRXe1hY91FwwandaGMlM BnTmYqrZ6EICcjv/qqJgq9Of84VKgMEIRr8+GB/csHnGXPPzipKzyjj1WYXRHWSNONOsvxMgMAS UxNDagKs74XcBKjH094E6JVvz4OcVxvHRWcGLPZtZmcvuSCnnuo10Bhnvlu7YJaUYx4/SjxFx/d nEjy3I38gHleJecEUq83xKlaJ6sr6RqM5jI/pdAXqMaZkvjsB1GBzxdcLQKp6B07WDl2+SGvH0Y 8WzJn2KjDhs30D470izxLOtOLHaDzCQwk6IB8fcKwwQf5MQx0szgyeEqQe9d4Wr8ZqDamH+KmQE JFx6jVRbxzoEK5n5EBbMZjrgfj7Icti3k= X-Received: by 2002:a17:903:f84:b0:2b0:6d56:8d29 with SMTP id d9443c01a7336-2b0b0a75058mr19887215ad.32.1774403765180; Tue, 24 Mar 2026 18:56:05 -0700 (PDT) Received: from smtpclient.apple ([103.62.49.186]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b083655b45sm218418865ad.42.2026.03.24.18.56.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2026 18:56:04 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: VACUUM FULL, CLUSTER, and REPACK block on other sessions' temp tables From: Chao Li In-Reply-To: <0b555318-2bf2-46df-9377-09629a2a59db@uni-muenster.de> Date: Wed, 25 Mar 2026 09:55:29 +0800 Cc: PostgreSQL Hackers , Antonin Houska Content-Transfer-Encoding: quoted-printable Message-Id: <97B93CF6-109D-46B4-AD50-8908DD4BE6E4@gmail.com> References: <0b555318-2bf2-46df-9377-09629a2a59db@uni-muenster.de> To: Jim Jones X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 24, 2026, at 23:35, Jim Jones = wrote: >=20 > Hi, >=20 > While testing another patch [1], I noticed that REPACK is blocked when = a > temporary table is locked in another session. It also turns out that = the > same behaviour occurs with VACUUM FULL and CLUSTER: >=20 > =3D=3D session 1 =3D=3D >=20 > $ psql postgres > psql (19devel) > Type "help" for help. >=20 > postgres=3D# CREATE TEMPORARY TABLE tmp (id int); > CREATE TABLE > postgres=3D# BEGIN; > LOCK TABLE tmp IN SHARE MODE; > BEGIN > LOCK TABLE > postgres=3D*# >=20 > =3D=3D session 2 =3D=3D >=20 > $ psql postgres > psql (19devel) > Type "help" for help. >=20 > postgres=3D# REPACK; > ^CCancel request sent > ERROR: canceling statement due to user request > CONTEXT: waiting for AccessExclusiveLock on relation 38458 of = database 5 > postgres=3D# VACUUM FULL; > ^CCancel request sent > ERROR: canceling statement due to user request > CONTEXT: waiting for AccessExclusiveLock on relation 38458 of = database 5 >=20 > Skipping temporary relations in get_tables_to_repack() and > get_all_vacuum_rels() before they're appended to the list seems to do > the trick -- see attached draft. >=20 > I can reproduce the same behaviour with CLUSTER and VACUUM FULL in > PG14-PG18. I took a quick look at the code in PG17 and PG18 and the = fix > appears to be straightforward, but before I start working on it, I'd > like to hear your thoughts. Is it worth the effort? >=20 > Best, Jim >=20 > 1 - = https://www.postgresql.org/message-id/13637.1774342137%40localhost I think skipping temp tables of another session is reasonable, because = anyway they are not accessible from the current session, though visible = via pg_class. Looking at the patch: ``` + /* Skip temp relations belonging to other = sessions */ + if (class->relpersistence =3D=3D = RELPERSISTENCE_TEMP && + = isOtherTempNamespace(class->relnamespace)) ``` It uses isOtherTempNamespace(), but I noticed that the header comment of = the function says: ``` * isOtherTempNamespace - is the given namespace some other backend's * temporary-table namespace (including temporary-toast-table = namespaces)? * * Note: for most purposes in the C code, this function is obsolete. Use * RELATION_IS_OTHER_TEMP() instead to detect non-local temp relations. ``` Then looking at RELATION_IS_OTHER_TEMP(): ``` #define RELATION_IS_OTHER_TEMP(relation) \ ((relation)->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP = && \ !(relation)->rd_islocaltemp) ``` It takes a relation as parameter and check relation->rd_islocaltemp, = however in the context of this patch, we have only Form_pg_class. Then checking how rd_islocaltemp is set: ``` case RELPERSISTENCE_TEMP: if = (isTempOrTempToastNamespace(relation->rd_rel->relnamespace)) { relation->rd_backend =3D = ProcNumberForTempRelations(); relation->rd_islocaltemp =3D true; } else { /* * If it's a temp table, but not one of = ours, we have to use * the slow, grotty method to figure out = the owning backend. * * Note: it's possible that rd_backend = gets set to * MyProcNumber here, in case we are = looking at a pg_class * entry left over from a crashed = backend that coincidentally * had the same ProcNumber we're using. = We should *not* * consider such a table to be "ours"; = this is why we need the * separate rd_islocaltemp flag. The = pg_class entry will get * flushed if/when we clean out the = corresponding temp table * namespace in preparation for using = it. */ relation->rd_backend =3D = GetTempNamespaceProcNumber(relation->rd_rel->relnamespace); Assert(relation->rd_backend !=3D = INVALID_PROC_NUMBER); relation->rd_islocaltemp =3D false; } break; ``` It uses isTempOrTempToastNamespace(relation->rd_rel->relnamespace) to = decide relation->rd_islocaltemp. So, I think this patch should also use = "!isTempOrTempToastNamespace(classForm->relnamespace)" instead of = isOtherTempNamespace(class->relnamespace). I tried that locally, and it = works for me. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/