Postgresql – Is it possible to backup the ubuntu postgresql database by copying the /var/lib/postgresql/9.1/main file and pasting it back in

backuppostgresql

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.

Best Answer

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.