Postgresql – Getting vacuumdb :invalid page header in block error while vacuuming

postgresql

I am newbie to PostgreSQL and using version 9.2.Disk space for data folder is full causing DB to stop. When i am trying to perform a vacuum to reclaim space, i am getting below error.

vacuumdb: vacuuming of database "mcfdb3" failed: ERROR: invalid page header in block 15871 of relation base/17148/30976

Can anybody help?

Best Answer

The error you pasted indicates that there has been corruption in your database. The best approach to dealing with this kind of corruption is to shut down the database, make a complete copy of all of the files, and then restore them to another system where forensics can be performed.

If you have a complete copy of your database, such that you can retrieve any valid data from it, then you can use the "zero_damaged_pages" configuration parameter in PostgreSQL to have invalid or damaged pages wiped out entirely, allowing the database to progress even in the face of corrupt or invalid data. Note that this option will cause you to lose valid data, as the entire page will be completely wiped out if any piece of it is deemed to be damaged or invalid.

Depending on the specific corruption which has occurred in this database, it may be possible to retrieve some of the data. This retrieval is extremely time consuming and requires expertise knowledge of the database system and is generally only sensible when the data is extremely valuable.