We have faced different levels of corruption related to databases in PostgreSQL. Our colleague has written multiple blogs on the subject; please refer to the below links for more:

In this blog, we will be discussing the scenario where a data file related to a table goes missing, maybe due to OS (hardware problem) or due to human interruption, which causes the deletion of some data file unintentionally at the OS level. Though it is not at all recommended to touch the /data/base/ directory and go through files under this /var/lib/postgresql/14/main/base/, however, sometimes it happens.

Our current database was running fine with the below structure:

Somehow we are getting the below error message in PostgreSQL logs:

Upon checking, we found it was due to one file ( base/16384/16391) being removed. So we need to check whether this base/16384/16391  file is available in /base location.

Also, we can check at the DB level by using this SQL Query:

From the above, we have identified that the file for the table “test” with relid 16391 got deleted. We need to identify whether it was deleted manually by mistake or was due to hardware failure. 

In case of hardware failure, first, we need to fix the hardware issue or migrate our database to new hardware and then perform a restore, as mentioned below.

To restore, we can follow either of below approaches:

  1. If the standby server is there and the issue does not persist on that, then we can fix the issue by taking logical backup from the standby server, dropping the table on primary, and recreating it using the backup taken.
  2. Perform PITR if we have backup configured with proper archive backup.
  3. Restore database “percona” if we have proper backup configured using pgBackRest backup.
  4. If we have a table-level logical backup, then we can restore the “test” table backup, and our database will be in good shape.

Percona Distribution for PostgreSQL provides the best and most critical enterprise components from the open-source community in a single distribution, designed and tested to work together.

 

Download Percona Distribution for PostgreSQL Today!

 

Abdul Sayeed co-authored this article.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments