1

This weekend I had to rebuild my laptop which had Postgres running. For some reason, I forgot to dump the data but I did make a complete copy of the original hard drive.

Is it possible to recover data from the original data files to transfer to another instance of Postgres?

1
  • Old and new PostgreSQL versions and host operating systems? Apr 9, 2013 at 0:35

1 Answer 1

4

Yes, it's fairly simple. You need to copy the database from the old disk image to a directory in the new host then start it using the same major version of PostgreSQL compiled with the same options (integer datetimes on/off, etc).

You can start the DB with a command like PGPORT=5433 pg_ctl -D /path/to/copy/of/old/database start. You must use the same PostgreSQL major version that the DB was created with before. If you're not sure what that was, check the PG_VERSION file in old data directory.

Once you've started a server with the old database you can then pg_dump the databases(s) and pg_dumpall --globals-only the users, etc, and load them into the new database.

Do not try to start the database directly on the old disk image, make a copy and start the copy.

You haven't provided details about versions, operating systems, how you installed Pg on the old and new machines, etc, so it's hard to provide more detail.

1
  • Craig, Thank you for your help. I will work on this later today. Thank you again. Ray
    – Ray
    Apr 9, 2013 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.