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 1srgrO-003oDh-7L for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Sep 2024 16:51:59 +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 1srgrM-00A0Mm-7G for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Sep 2024 16:51:57 +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.94.2) (envelope-from ) id 1srgrL-00A0Lh-PD for pgsql-hackers@lists.postgresql.org; Fri, 20 Sep 2024 16:51:57 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1srgrK-000Cgf-GR for pgsql-hackers@lists.postgresql.org; Fri, 20 Sep 2024 16:51:55 +0000 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-82aa6be8457so75013339f.0 for ; Fri, 20 Sep 2024 09:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726851114; x=1727455914; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=bhLkzKDwHCocyEHG4ctjo1afJb8SjRoqKnZzDQGn7XY=; b=WCzlxEG+/Ba3SKppak0eBkmPiucvTHkPuk17mcTjm1oRdACOOINFaaU8wMbkhO/fhv TxVRDnlTxnLa9Z5rH7WoNQ91skOGHfZ/AfCNHEEdKxVhJepSiXtlBeL/+Cowik/wZ0LU f64WYy0Wl4+5yUsgaVT1Dc1tz4pV2LyBnZCjZ8vS5nYO9sJvWEws4Vv6jVGQCic/Lm5O uS7JZPG2EKA1TuBQXKFiVRsYXhsIa/7FUhiarNRKJLuVFuKLlcDHf7P/ZS8CcEruk0Ud OOwX63c+EfVLo5t2yDRDVT1jjHJNSmsIvzOkZ57XV10SEgsJxqAqFnlkMT/ew5S4zt8x IpnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726851114; x=1727455914; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bhLkzKDwHCocyEHG4ctjo1afJb8SjRoqKnZzDQGn7XY=; b=kVfzzc+bERiXX9e0mz0Mgts3SWdVMI35Wa3mmXUsHzw0dZtY+sPshnLFn3nmYdZMAF 6E9QsVy8/KJ8D+5ETE2TQyFhBBZMwmC3fodwJJyLVndwDNWiDvnUvMGgR0lDaFV2CQgT Esx06foZJwcNvDIMhI0MvXc0YgBpHjTWIDjQY9sL+kxGeV3D42e8tsbxg/skvQYlBUx3 eb7xi1/6OmWUoO8sBKZmokFrCQAewzCeR0Ictk+oOVzR5VNMUtGXzxSY9njgtFHNRDNv M0m0grDDqXelC4N7wLdHgrxkvBqHrDprx58fTO2Q9Ngw+2ZC0HyyUeddBfZN9vQQdRHY jx7A== X-Forwarded-Encrypted: i=1; AJvYcCW8BkyU1AKAhDUxESUcKCETLMjeNOjqwnbM2ImJ1stOSWtW/sLkmoZp1Jh56QH6ZqPDHqmrEdfvYNwgWVhm@lists.postgresql.org X-Gm-Message-State: AOJu0YxXhtoLeVSMgE/dMgDPqf2TTz33SiQiBz140QbdAh0cM3njiC5w BK4ww1eVhuyjjVsOpwHnQnKYcdqaLsCyRno6C6YAnKeC81KAuboW X-Google-Smtp-Source: AGHT+IFrBOG9uHWtYRQKj0E83Xd49M4e0h3nReJ3G8EBw8O7W+aU32OBkOvhnSA47mCaRc1BZg2xKQ== X-Received: by 2002:a05:6602:6216:b0:82c:f7c4:b093 with SMTP id ca18e2360f4ac-83209b41688mr277679839f.3.1726851113738; Fri, 20 Sep 2024 09:51:53 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-82d492694a5sm382643539f.11.2024.09.20.09.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 09:51:52 -0700 (PDT) Date: Fri, 20 Sep 2024 11:51:50 -0500 From: Nathan Bossart To: Alexander Lakhin Cc: Tom Lane , "Jonathan S. Katz" , PostgreSQL Hackers , Michael Paquier Subject: Re: Large expressions in indexes can't be stored (non-TOASTable) Message-ID: References: <1679756.1725476893@sss.pgh.pa.us> <1812111.1726671296@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ZoeJq66r+ghpMz3m" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ZoeJq66r+ghpMz3m Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, Sep 20, 2024 at 07:00:00AM +0300, Alexander Lakhin wrote: > I've found another two paths to reach that condition: > CREATE INDEX CONCURRENTLY ON def (vec_quantizer(id, :'b')); > ERROR:  cannot fetch toast data without an active snapshot > > REINDEX INDEX CONCURRENTLY def_vec_quantizer_idx; > (or REINDEX TABLE CONCURRENTLY def;) > TRAP: failed Assert("HaveRegisteredOrActiveSnapshot()"), File: "toast_internals.c", Line: 668, PID: 2934502 Here's a (probably naive) attempt at fixing these, too. I'll give each path a closer look once it feels like we've identified all the bugs. > Perhaps it would make sense to check all CatalogTupleUpdate(pg_index, ...) > calls (I've found 10 such instances, but haven't checked them yet). Indeed. -- nathan --ZoeJq66r+ghpMz3m Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-fix-failed-assertions-due-to-pg_index-s-TOAST-tab.patch" From b7432c42c0cea9c1aadba7c72f9ce2ba6e6407d2 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 20 Sep 2024 11:48:52 -0500 Subject: [PATCH v2 1/1] fix failed assertions due to pg_index's TOAST table --- src/backend/catalog/index.c | 5 +++++ src/backend/commands/indexcmds.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index b2b3ecb524..2e378ef4ef 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -2255,6 +2255,7 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode) PopActiveSnapshot(); CommitTransactionCommand(); StartTransactionCommand(); + PushActiveSnapshot(GetTransactionSnapshot()); /* * Now we must wait until no running transaction could be using the @@ -2283,8 +2284,10 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode) * Again, commit the transaction to make the pg_index update visible * to other sessions. */ + PopActiveSnapshot(); CommitTransactionCommand(); StartTransactionCommand(); + PushActiveSnapshot(GetTransactionSnapshot()); /* * Wait till every transaction that saw the old index state has @@ -2387,6 +2390,8 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode) { UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock); UnlockRelationIdForSession(&indexrelid, ShareUpdateExclusiveLock); + + PopActiveSnapshot(); } } diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index f99c2d2dee..36318c81ea 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1798,11 +1798,15 @@ DefineIndex(Oid tableId, PROGRESS_CREATEIDX_PHASE_WAIT_3); WaitForOlderSnapshots(limitXmin, true); + PushActiveSnapshot(GetTransactionSnapshot()); + /* * Index can now be marked valid -- update its pg_index entry */ index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); + PopActiveSnapshot(); + /* * The pg_index update will cause backends (including this one) to update * relcache entries for the index itself, but we should also send a @@ -4236,6 +4240,8 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein */ set_indexsafe_procflags(); + PushActiveSnapshot(GetTransactionSnapshot()); + forboth(lc, indexIds, lc2, newIndexIds) { ReindexIndexInfo *oldidx = lfirst(lc); @@ -4280,8 +4286,10 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein } /* Commit this transaction and make index swaps visible */ + PopActiveSnapshot(); CommitTransactionCommand(); StartTransactionCommand(); + PushActiveSnapshot(GetTransactionSnapshot()); /* * While we could set PROC_IN_SAFE_IC if all indexes qualified, there's no @@ -4316,6 +4324,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein } /* Commit this transaction to make the updates visible. */ + PopActiveSnapshot(); CommitTransactionCommand(); StartTransactionCommand(); -- 2.39.5 (Apple Git-154) --ZoeJq66r+ghpMz3m--