Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mPU74-0001K0-U4 for pgsql-general@arkaria.postgresql.org; Sun, 12 Sep 2021 18:21:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mPU73-0008BL-Nt for pgsql-general@arkaria.postgresql.org; Sun, 12 Sep 2021 18:21:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mPU73-0008BC-EL for pgsql-general@lists.postgresql.org; Sun, 12 Sep 2021 18:21:57 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mPU70-0006qn-3c for pgsql-general@lists.postgresql.org; Sun, 12 Sep 2021 18:21:56 +0000 Received: by mail-wr1-x42a.google.com with SMTP id g16so11090384wrb.3 for ; Sun, 12 Sep 2021 11:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=qMdW39Z08nLQ5rLPHnzew3pel7TscxC6YYSPT1SYXNw=; b=qrTq3oN4kXrjkkwkmrqYlYeCZUlgB/pVDPsXjNBN0IfJp2YFkEpc32mg4UBe0Lisme 0hvCMFCgNNadFXxVFcSYRRF2BOJyTBR5TYRBQti6ugeiOQH8kOami6Gi9Wv1KfVP7SMw T5vWAsIuhfY1EIshavVSQWF2tNSeQp85Gud5uXoIQM7IGA/EcO87gvGO4KBXet44Sgka 5nZZSNzi6rDaMXhwaggbb6n49cV5Bg2dqP0tgKdhCfY5Pz5AZw2Nh1za9fHULJkAIzZf mFsiM/wtF1lhUBRwNj4I61dPfFRHijsluyybqn9xjo3rJB+aVUwaAospD0T8c8sJLLCN Bk9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=qMdW39Z08nLQ5rLPHnzew3pel7TscxC6YYSPT1SYXNw=; b=btun0vNQVay3QZQ96xv/N8WdWF9Iv6FayjEC4xkBZzaY0NNRSsZsU15LVmMQliSlxX 7VzndVQ2b4h5G5qihTGQdAOQp173Y3Oc96VhvaVKlD+NVISzpzCmpUgWYCqDxTn/9+vK IUw+A9pTgSdnlJ7dS9WOqUwaYPzGBi7q4uhdYjvO0vmacfau+stEX0+QFHx9trvELprl mBBg023uoWY88JUVc+tSZBTrefVyXbqb1+VvvJq6spbHr3xSJiNuu0PFvYYWNeBdtjKQ jr5yong1MOP+HVgKsFniT1yEK6SZtkoEjYFnmZ2uSeqB1RKaEtOvV/WoyLg8hjtTGr+7 jHIw== X-Gm-Message-State: AOAM531jMGk/YjJ+BKPy3QYTzEa+hdW3GPI5tcShitwbCMA4bA4KzZLS g9c9J50HIFLuw1swY6uY9DDy9adhW6iAIQ== X-Google-Smtp-Source: ABdhPJwja73Qd5ZmY0/233ghs9hu80AM5GDXo7/SZXRpF6g2nCpO+pHKm5pLcdi2+k+7HD0QXOQpMg== X-Received: by 2002:a05:6000:14d:: with SMTP id r13mr5118845wrx.420.1631470913121; Sun, 12 Sep 2021 11:21:53 -0700 (PDT) Received: from localhost.localdomain (62-46-253-206.adsl.highway.telekom.at. [62.46.253.206]) by smtp.gmail.com with ESMTPSA id u27sm5379977wru.2.2021.09.12.11.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 11:21:52 -0700 (PDT) Message-ID: <5248678bf085a9c1593b46c8a440ec8dff0a8faf.camel@cybertec.at> Subject: Re: Unable to drop invalid TOAST indexes From: Laurenz Albe To: gabrielle , pgsql-general@lists.postgresql.org Date: Sun, 12 Sep 2021 20:21:52 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2021-09-10 at 17:50 -0700, gabrielle wrote: > I ran into an interesting situation last week. > > Discovered on RDS Postgres version 13. > Replicated on community Postgres version 13. > > A client wanted us to drop some invalid indexes, some of which turned out to be invalid indexes on TOAST tables. > > We don't know for sure how their database got this way; we suspect a failed 'REINDEX DATABASE CONCURRENTLY', possibly more than one. > > Attempts to drop the invalid index fail like so: >     testy=> drop index CONCURRENTLY pg_toast.pg_toast_14199_index_ccnew; >     ERROR:  permission denied for schema pg_toast > > This fails even when I'm logged in as the owner of the toast table's parent table;  I have to assume superuser privileges in order to drop them. > > On a hosted environment, this means a user could create an invalid index that they can't drop without provider intervention. > > Is this expected behavior? In order to rebuild the TOAST index on "sometable", run REINDEX TABLE CONCURRENTLY sometable; As the documentation says: "If the table has a secondary “TOAST” table, that is reindexed as well." You cannot drop the TOASE index, as that is required for PostgreSQL to function. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com