A developer working on my server has fiddled with some settings and knocked my postgresql database offline. I've been messing with it for an hour and am considering just reinstalling postgresql fresh because I know it will work easily then.

I know this is where I database is. /var/lib/postgresql/9.1/main. Can I copy this file, then paste it back in and expect it to work for me? Its for the same machine and everything.

  • You want to copy PG data directory and paste it to other directory (on the same machine), after that, you will start PG server on new data directory ? – Luan Huynh Feb 24 '15 at 1:55

Yes, as long as you install version 9.1 (minor version doesn't matter). And normally you don't need to copy/move them anywhere, the installation will notice there is already a database system set up and will use it. Of course taking a backup is never a bad idea.

Then again, the reason for it being offline should be clear from PostgreSQL logs. Memory allocations can be too high, or some other thing, and this is reported in the log.

  • Do you have to stop Postres before copying the folder? I could imagine, that there are some writes in the folder while you copy it. Couldn't this cause a defunctional database? Or inconsistent data? – rubo77 Jan 18 '17 at 12:12
  • @rubo77 If you just copy the files then yes, it has to be turned off. If you want to clone a live system you have to tell PostgreSQL that you're going to do that so it knows to keep the files consistent while you copy. – Sami Kuhmonen Jan 18 '17 at 20:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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