How to detect corrupted indexes in PostgreSQL?

When I pull data from a column with primary key attribute in a table with where condition, it brings incomplete results. Likewise, when I sort with order by in the relevant column, the data is missing. When you dump the table and press it to another database or transfer the table to another table by changing its name, the data comes back healthy. In this case I suspect the primary key is corrupt. What do I need to do to scan the whole database for corrupt primary keys.

  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community
    Aug 23, 2022 at 13:41
  • I edited it, can you review it again?
    – emreyanik
    Aug 24, 2022 at 7:08

1 Answer 1


Run the bt_index_parent_check function from the amcheck extension. That can detect most cases of data corruption in a given index.

  • thank you, i will try
    – emreyanik
    Aug 24, 2022 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.