5

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

user3016665
  • 139
  • 2
  • 8
  • I have the same issue (see https://superuser.com/questions/1664462/recover-old-postgresql-database-after-reinstalling-windows?noredirect=1#comment2551966_1664462). Did you figure it out? – MSC Aug 24 '21 at 12:13

2 Answers2

2

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

semaphore
  • 59
  • 4
1

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.

Richard Huxton
  • 21,516
  • 3
  • 39
  • 51
  • 0. Make a copy and save it off as a backup. – Kuberchaun Jul 21 '14 at 15:51
  • 1
    Ok. So I re-copied the folder C:\Program Files\PostgreSQL\9.3\data. The version of postgresql on the old and new computer are the same according to the text file "version" in postgresql>9.3. I opened then pgAdmin but the database did not appear. Where do you check that the permissions are right? I did not understood what you meant by "just point the configuration at it (data_directory)" because I do not find where to specify the directory. – user3016665 Jul 22 '14 at 13:24
  • pgAdmin is not the database server. Stop the server. Make sure it is stopped by checking the logs and that pgadmin cannot connect. Check/update your postgresql.conf, start the server, check the logs for error messages and then see if pgAdmin can connect. – Richard Huxton Jul 22 '14 at 22:14
  • I'm quite novice as you can see... I thought by closing all applications using postgresql it would close it.But finally, I managed to close the server using pg_ctl.exe. The logs in postgresql.conf file turned off and pgAmin could not connect. However I do not manage to reconnect the server either using pg_ctl.exe or via the terminal using: \bin\pg_ctl.exe start \data. I got an error message saying "pg_ctl is not recognized as an internal or external command".Moreover,when I try to open pgAdmin I got a message saying "pgadmin password authentication failed for user postgres"... Any suggestions? – user3016665 Jul 23 '14 at 17:31
  • It is almost certainly registered as a service. You should be able to contol it from there. – Richard Huxton Jul 23 '14 at 17:40