Subject: RE: Index (primary key) corrupt?

From: Wim Rouquart <[email-masked]>
Date: Fri, 19 Sep 2025 09:29:57 +0000

Internal

Hello,

When doing a pg_dump of one of our databases one of the tables primary keys doesn’t get exported. Pg_dump just skips this index, without any warning whatsoever (verbose mode was used to doublecheck).

When doing a REINDEX the issue is fixed.

As this seems to me to be some form of index corruption, I tried using amcheck (bt_index_check and bt_index_parent_check) to verify for corruption but both resulted with no issues (the index is a btree).

I would expect the corruption to show up when using amcheck, am I hitting some kind of bug here?

>> Does this problem keep happening, or has it only happened once?

It is consistent on this database/index, haven’t noticed it anywhere else yet luckily. Seems to be a one-off.

Are there any other ways to doublecheck for corruption (without enabling checksum upfront)?

>> pg_checksums is available in PG 15.

It is indeed, so to test I enabled checksums, and did a checksum test, no errors, and yes, the file containing the index is mentioned in the checks…

This concerns a PostgreSQL version 15 btw.

>> Are you at the current patch level?

Yes.

Disclaimer <https://www.kbc.com/KBCmailDisclaimer>

---

From: Adrian Klaver <[email-masked]>
Date: Sat, 20 Sep 2025 08:00:37 -0700

> else yet luckily. Seems to be a one-off.

The above is not clear to me. One-off as for this database/index only 
and repeatable across dumps or that it only happen in one dump.

>>> Are you at the current patch level?

Please specify the actual version, current is a relative term. It 
matters for folks using this thread for researching an issue in the future.

-- 
Adrian Klaver
[email-masked]

---

From: "David G. Johnston" <[email-masked]>
Date: Sat, 20 Sep 2025 08:23:54 -0700

> yet luckily. Seems to be a one-off.
So the problem goes away once you’ve reindexed yet you claim it’s
consistent? What are you doing to get the problem to recur after you’ve
done reindex to make it work?

David J.

---

From: Rob Sargent <[email-masked]>
Date: Sat, 20 Sep 2025 09:26:55 -0700

> So the problem goes away once you’ve reindexed yet you claim it’s consistent? What are you doing to get the problem to recur after you’ve done reindex to make it work?
> 
> David 

I was assuming the OP has  a dump of the affected condition and is restoring (and perhaps re-fixing).  No?

---

From: Adrian Klaver <[email-masked]>
Date: Sat, 20 Sep 2025 09:58:02 -0700

> I was assuming the OP has  a dump of the affected condition and is restoring (and perhaps re-fixing).  No?

 From this post:

https://www.postgresql.org/message-id/AS2PR05MB107548567EEDAAB3AF74A6C59EF11A%40AS2PR05MB10754.eurprd05.prod.outlook.com

"
 > Is the PK definition in the pg_dump file? For plain text format can 
you grep/find it?

It is in neither, that’s why I'm sure it doesn't get exported. After a 
REINDEX statement it is.

 >How is the dump file being restored?

As the code to generate the index is not in the dumpfile this seems 
irrelevant to me.
"

Make of that what you will.