OK. I'm in a bit of trouble.

I've got an Ubuntu, had Postgres 9.1 installed.

There was something wrong with it - I couldn't start it for some reason. Out of panic, I backed up /var/lib/postgres/9.1/main (my data directory) and did

apt-get purge postgres*

Which removed everything.

Then I did a fresh installation of Postgres 9.1

Now I tried just moving the old data directory to the new installation - there is an error.

I heard you can recover from a file in the pg_xlog.

What are my options?

  • So, what was the problem with the original install? Did you get errors? If yes, what errors? And what error do you get now? Jun 14, 2013 at 10:21

1 Answer 1


Without knowing your specific errors, I dont know what the easiest approach to recovering your database is. For example, there could be minor problems like bad settings that cause PostgreSQL to be unable to start. I would recommend asking a new question about getting PostgreSQL to start before looking at how to recover your data.

However, I can answer what are some aspects of your question about recovering data. I have actually never seen data corruption in PostgreSQL, and so all my experience with it is second-hand (email list threads and the like). It is very rare, and usually related to failing hardware. If you do have data corruption, my recommendation is to restore from backup onto a new server while you run diagnostics and determine the problem on your existing server.

When you talk about recovering from the files in pg_xlog you are talking about using write logs as incremental backups. You still need a compatible starting point, which means effectively you are going with a base backup plus all pg_xlog segments created from that point onward.

Now, if you have no good backups, and you have a lot of important data, it may be possible to hire an expert for significant expense to recover some or all of your data. This is not cheap.

I think your immediate steps are to step back and ask why PostgreSQL is not starting and see what you can do about that first before assuming you need to recover your data. If you need to recover your data, you hopefully have backups.

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.