Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Overview of this book

Table of Contents (19 chapters)
PostgreSQL 9 Administration Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Recovery of a dropped/damaged tablespace


Recovering a complete tablespace is also required sometimes. It's actually a lot easier than recovering a single table.

How to do it…

The methods 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 pg_dump in a custom file, then you can simply extract the tables you want from the dumpfile, like the following:

pg_restore -t mytab1 -t mytab2 …  dumpfile | psql

Alternatively, you can directly connect to the database using –d.

Of course, you may have difficulty remembering exactly which tables were there. So, you may need to proceed like this:

  1. Find a suitable server, or create a new virtual server.

  2. Reload the dump in full, using four parallel tasks, as follows:

    pg_restore -d mydatabase -j 4 dumpfile
    
  3. Once the restore is complete, you can dump the tables in the tablespace by following the Hot logical backup...