I have had to delete PostgreSQL for an issue and reinstall it, however before uninstalling I did not execute the command pg_dump. I still have the data directory from this instance. After reinstalling PostgreSQL, I receive all the same tables and schemas from my prior database, but not the same data. The data directories are two separate, but I want to combine the previous data directory into the new one. How would I go about such a process, if possible?

1 Answer 1



I'm assuming you have two instances each one with a different data directory but with the same schema for the same version of postgres installed. I'm also assuming when the server starts is using your newly created, possibly empty, instance

What to do

You should try to start a new instance of the server pointing to your backup data directory...
Somenthing like

pg_ctl -D /path/to/backup/dir -l /path/to/log start -o "-p 5433"

If this works, your backup instance is running on port 5433.
Check if everything is in place and the data is consistent.

If so then you could simply make arrangements for your server to always start pointing to your backup directory and safely delete your newly created data directory.

  • I appreciate your advice, and I apologize for the late response. What had happened was there was an issue with my first installation of postgresql, and I was in a bind; I uninstalled (left the data directory alone and did not perform a dump) and reinstalled with postgres.app. I have not tried your method yet, but it seems to me that in your assumption, you assume that I still have old instance available; to which I unfortunately do not. Please do tell me if I am wrong. Jun 29, 2016 at 5:39
  • For this you just need the old data directory. Whether your new installed postgresql is running an instance or not is not important because you will manually start a new one in a different port (5433) with a different data directory (your old data directory) which is supposed to be valid because it was created with the same version of postgresql in a previous install. Try the command and see if that works. Please make a backup of your backup just in case ;)
    – cachique
    Jun 29, 2016 at 13:36
  • When using this command, I get invalid option --1 Jul 5, 2016 at 15:06
  • When dropping the /path/to/log, I get the server started -- however, when trying to access using pgadmin III I cannot connect to server Jul 5, 2016 at 15:39
  • The error is : `psql: could not connect to server: No such file or directory. Is the server running locally and accepting conections on Unix domain socket "/tmp/.s.PGSQL.5433"? Jul 5, 2016 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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