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 1vDlSI-00FNqP-9s for pgsql-general@arkaria.postgresql.org; Tue, 28 Oct 2025 15:17:49 +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 1vDlSH-00DZIH-0P for pgsql-general@arkaria.postgresql.org; Tue, 28 Oct 2025 15:17:48 +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 1vDlSG-00DZI8-0l for pgsql-general@lists.postgresql.org; Tue, 28 Oct 2025 15:17:47 +0000 Received: from fhigh-a1-smtp.messagingengine.com ([103.168.172.152]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vDlSC-004E3P-1v for pgsql-general@lists.postgresql.org; Tue, 28 Oct 2025 15:17:46 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 73B5E1400159; Tue, 28 Oct 2025 11:17:43 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 28 Oct 2025 11:17:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1761664663; x=1761751063; bh=Ex7mSbdQ7Qys7AKC8yi1RrtR9lf8Ntn8OOtpm20ZszU=; b= kolX29lkvTnUSz8Za2pZkU/76dzrxa6lKOtJRCWDU8F2GnaswEwQANE0AZhbi5RV Cj6k0SZ2/oQn/rFP9X4d84hKw/h+5KytfHo1iRUUVCcei/jULTUOscQoSOKeJnIe AloC41kAxD4km/GxNY+XuYj/SPWVKC14GmKABI2kQ5PmFyGhma4KKFaTt3nLDARt 0+WbqK60drnF3PQcCaeuWXsYZNzIa5OnMryIbOkuwTVB/OAuMdQAL4NVI96ZbvQS 7NVT8zOLshiGAqmStM1eNzeiKLGwkCcj4MJKceQ7CMuKddQNAtRWDfdrdxQOv4mQ Zl2Ej2JUiCPk/TCb/b4WLQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1761664663; x= 1761751063; bh=Ex7mSbdQ7Qys7AKC8yi1RrtR9lf8Ntn8OOtpm20ZszU=; b=0 R85MgllpCayG9gLi9vhuwoW8p57DOCNKNsX3Dx9ELHUQVuSgp3Zte64B0fIUqnqW nRO5A2++d/liK4zrfoZsnO54DBH03t9pYrheOiMwwoiriROkg/aL0/FM5RunemE/ em2gTw4J6llQ/oH6E/94neDJGSCBeTEHEaELoR+HgKyuw7kQqadSNC0RxDluLDrT 1zm5woM5l02qSs37AQ6kGMAawpWkb41f1do+JYEBo6ZlDNvTIsQ5Zyq7LS3QNxJj F0o1ze7gftiSIGaJyDQpCXYiiCp5QyUrQcKo2xOqbqAX6xjzCY0JzPSmXOSyEPVk Mi35iGjEtbU9uH1ejGRtw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduieduudelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnheptddtuedvueekudekkeejtdefgfetgfelveduhfekgeev ueehgfdtteegueffhffgnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghdpkh gstgdrsggvpdgtrhhunhgthhihuggrthgrrdgtohhmpdhksggtrdgtohhmnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklh grvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepfihimhdrrhhouhhquhgrrhhtsehksggtrdgsvgdprh gtphhtthhopehhthgrmhhfihgushesghhmrghilhdrtghomhdprhgtphhtthhopehpghhs qhhlqdhgvghnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Oct 2025 11:17:42 -0400 (EDT) Message-ID: Date: Tue, 28 Oct 2025 08:17:41 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Index (primary key) corrupt? To: Wim Rouquart , Greg Sabino Mullane Cc: "pgsql-general@lists.postgresql.org" References: <1bfa0b6b-11a8-458f-a3f3-3f86574abc1d@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/28/25 03:25, Wim Rouquart wrote: > Internal > > > I used the output from DBeaver, guess it acted up. Here’s the output > from psql: 1) As side note, find a different client to use then DBeaver. I have seen many Postgres questions on Stack Overflow where the answer was, use something other then DBeaver. 2) Where and when was the query below run, on the original instance before the pg_dump or on the new instance after the restore and index rebuild? 3) From this post: https://www.postgresql.org/message-id/AS2PR05MB107548567EEDAAB3AF74A6C59EF11A%40AS2PR05MB10754.eurprd05.prod.outlook.com " It is in neither, that’s why I'm sure it doesn't get exported. After a REINDEX statement it is." From here: https://www.postgresql.org/docs/current/sql-reindex.html "REINDEX rebuilds an index using the data stored in the index's table, replacing the old copy of the index." The question then is, how does a REINDEX work on an index that supposedly does not exist? When you do the original restore and before the REINDEX, in psql, what does the below return?: \d bcf_work_type > > select * from pg_index where indexrelid  = 'idx_376814_primary'::regclass; > > -[ RECORD 1 ]-------+-------- > > indexrelid          | 2006873 > > indrelid            | 1998823 > > indnatts            | 1 > > indnkeyatts         | 1 > > indisunique         | t > > indnullsnotdistinct | f > > indisprimary        | t > > indisexclusion      | f > > indimmediate        | t > > indisclustered      | f > > indisvalid          | t > > indcheckxmin        | f > > indisready          | t > > indislive           | t > > indisreplident      | f > > indkey              | 1 > > indcollation        | 0 > > indclass            | 3124 > > indoption           | 0 > > indexprs            | > > indpred             | > > The steps that show the index is missing is an export of the database > while the index is ‘corrupt’, and then importing it. The import fails on > foreign keys that are pointing to this index because it is indeed not > created. > > Checking the export file shows the create statement from the index is > indeed missing (I know it can show up lower in the file, a search was > done on the index name, it’s not in there, you’re going to have to trust > me on this). > > After  doing a reindex like this: > > REINDEX INDEX idx_376814_primary; > > the export import story works just fine, the index is in there and is > created. > > Cheers, > > Wim. > > On Sat, Sep 20, 2025 at 5:07 AM Wim Rouquart > wrote: > > Name               |Value  | > -------------------+-------+ > indexrelid         |2006873| > indrelid           |1998823| > indnatts           |1      | > indnkeyatts        |1      | > > ... > > indclass           |{}     | > > Hold on, that makes no sense at all. The indkey/indclass columns cannot > be empty, especially as indnkeyatts is 1, as it should be. As a matter > of fact, pg_dump would completely choke on a broken table like this and > not even be able to dump it. But that output is clearly not from psql, > so I think whatever client application you are using is not able to > reliably output array columns. Any chance you can run that select > command using psql? As the rest of the columns look sane, I'm going to > guess those are as well, they just don't show up correctly, and the > system catalogs are uncorrupted. > > until I do the rebuild and then the issue is fixed > > Could you show us exactly the steps that show the index is missing, and > that it is then fixed? > > (ponders) Keep in mind that although you declared the primary key in > your create table statement, pg_dump is going to separate the table > creation from the primary key creation by a lot of lines. So you will > see in the pg_dump output: > > CREATE TABLE public.bcf_work_type ( >     id bigint NOT NULL, >     aml_score bigint NOT NULL > ); > > and then much later on: > > ALTER TABLE ONLY public.bcf_work_type >     ADD CONSTRAINT idx_376814_primary PRIMARY KEY (id); > > Also be aware that if you are using the --section argument, the table > will appear in the 'pre-data' section but the primary key will appear in > the 'post-data' section. > > Cheers, > > Greg > > -- > > Crunchy Data - https://altered.secure4u.kbc.be/https:// > www.crunchydata.com www.crunchydata.com> > > Enterprise Postgres Software Products & Tech Support > > > Disclaimer -- Adrian Klaver adrian.klaver@aklaver.com