Recovery of a dropped/damaged table
You may drop or even damage a table in some way. Tables could be damaged for physical reasons, such as disk corruption, or they could also be damaged by running poorly specified UPDATE
or DELETE
commands, which update too many rows or overwrite critical data.
Recovering from this backup situation is a common request.
How to do it…
The methods to this approach differ, depending on the type of backup you have available. If you have multiple types of backup, you have a choice.
Logical – from the custom dump taken with pg_dump -F c
If you've taken a logical backup using the pg_dump
utility in a custom file, then you can simply extract the table you want from the dumpfile
, like so:
pg_restore -t mydroppedtable dumpfile | psql
Alternatively, you can directly connect to the database using -d
. If you use this option, then you can allow multiple jobs in parallel...