Mystery: All postgres databases disapeared

152 Views Asked by At

I'm developing a Rails application with a postgresql database.

  • MacOS 10.15.3
  • ruby 2.6.3p62
  • postgres 12.3

I took a break and when I came back my laptop was slow to wake up. After pressing the on/off fingerprint button a few times, it eventually went into the startup sequence. This was odd because I did not recall shutting it off.

After starting, everything seemed normal. I opened some applications and resumed my work. But, when I tried to run a database migration, I got errors about not being able to connect to the server.

$ bundle exec rake db:migrate
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.5-compliant syntax, but you are running 2.6.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
/Users/emerson/.rbenv/versions/2.6.3/bin/bundle:23:in `load'
/Users/emerson/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I tried to start it with homebrew but no luck. I eventually read another question that suggested installing the Postgres app and using this to force it to restart. At first the app said "Empty data directory". I clicked "Initialize" and it worked. And I no longer get the bad connection error. But ALL my previous postgres databases are gone.

I'm puzzled. How could this have happened? And with almost no interaction from me whatsoever! Did Postgres.app wipe all my previous data with one click?

0

There are 0 best solutions below