Postgresql – Repopulating PostgreSQL database with data directory from another database Instance

postgresql

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?

Best Answer

Assumptions

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.