Reputation: 25
OSX 10.9.3 psql 9.3.4
I had several database that I was working on and we had a power cut over night. Now non of my database (including the default database (username)) are present.
Why have all the database gone from psql? Wouldn't they have been saved? Is there any possibly that they are still present but not listed by \dt?
Any help on how to recover these databases will be greatly appreciated!
Upvotes: 1
Views: 115
Reputation: 324711
A power cut can only cause database corruption or loss if the underlying storage is unsafe - some cheap consumer SSDs don't flush writes properly, for example. However, it's really unlikely that this problem would cause whole databases to just vanish, and even less likely that your database server would start successfully if that happened.
Since you are on OS X, it is highly likely that you actually have more than one PostgreSQL version installed. I'd say you were working on one PostgreSQL install before the power cut, and after the power cut (and resulting reboot) you are working on a different PostgreSQL install.
In fact, since you have 9.3.4 installed, you have at least one other PostgreSQL on your computer: the one that came built-in that's bundled by Apple.
If you're just connecting to the wrong PostgreSQL instance the data should still all be there, it's just a matter of connecting to the correct PostgreSQL instance - and if necessary, starting it up first.
First, try:
SELECT version()
and make sure the server version you're connected to is what you expect.
I can't really give more specific instructions on how to find the PostgreSQL install with your data in it, because Mac users tend to install PostgreSQL in numerous different ways and often have several copies installed. They all get started up different ways too - via launchd, manually with pg_ctl, via postgres.app launcher, etc. So to help you I'd need specifics on exactly which PostgreSQL version(s) you installed, how, and where.
One tip I can give you is that you can search for PostgreSQL data directories with the Terminal command:
sudo find / -name PG_VERSION 2>/dev/null
which will show you a bunch of PG_VERSION
files for each install's data dir. You can also list ports that PostgreSQL processes are listening on with:
sudo netstat -ltnp | grep postgres
(assuming that works on OS X; I don't have access to an OS X machine to test).
Upvotes: 1