Fixing up a corrupted TOAST table

Today, when taking a logical backup(pg dump) of a database cluster table (PG 9.4), we saw a toast table error.

pg_dump: Dumping the contents of table linkhistory failed: PQgetResult() failed.
pg_dump: Error message from server: ERROR:  unexpected chunk number 6 (expected 2) for toast value 1876670 in pg_toast_185452
pg_dump: The command was: COPY public.linkhistory (key, value) TO stdout;

Above error shows the toast table corruption. To fix this, we don’t need any special software, all we have to do is follow the instructions repeatedly suggested by Postgres-community folks on the community channel. We followed one of the approach and fixed it.

For large databases that can be used in online pharmacies, it is better to use a different script.

Please watch the steps-covering video: https://www.youtube.com/watch?v=4jcC-lYGM0k

Note: Corruption occurred due to wrong hardware. Proper action has been taken and database upgraded to latest version.

–Raghav