Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transfer postgres database from an old hard drive

I am pretty new with postgresql and pgAdmin and I made a beginner error. I changed the hard drive of my computer and unfortunately (and stupidly I really admit) I have not make a backup of my database in pgAdmin3 before. Is there anyway I can manage to transfer it back from my old hard drive to the new one? I tried to copy the file "Data" of pgAdmin from the old hard drive to the new one but it did not succeed. Is there any hidden file that would retain information of my database still on the old hard drive? If I re-install the old hard drive, would I be able to access the database back?

if anyone have any idea I would be really glad, thanks

like image 498
user3016665 Avatar asked Oct 20 '22 04:10

user3016665


2 Answers

Do as "Richard Huxton" suggested, then On Windows you need may need to set PG as a Service

Run the following on the command line (as adminstrator):

pg_ctl.exe register -N postgres -D  "C:\Program Files\PostgreSQL\9.6\data"

Start the service

answer from: Register and run PostgreSQL 9.0 as Windows Service

like image 85
semaphore Avatar answered Oct 23 '22 04:10

semaphore


Three steps are required:

  1. Copy everything in the data folder (base, global, ... pg_xlog, ...)
  2. Make sure the permissions are right
  3. Make sure you have the same version of the PostgreSQL binaries installed.

Then just point the configuration at it (data_directory) and start it up. If there are any problems, check the logs for details - it'll probably be permissions.

Sometimes it's convenient to do all this in a virtual machine if you have that sort of stuff set up already.

like image 39
Richard Huxton Avatar answered Oct 23 '22 04:10

Richard Huxton