Search code examples
herokuheroku-postgres

Heroku: How Can I Stop My Postgres Databases from Disappearing after a few minutes?


Yesterday I uploaded a Rails 5 application with multiple databases to Heroku. I have a hobby-dev postgres add-on. This morning I successfully imported my 7 Postgres databases using pg_dump backups created according to the Heroku documentation.

PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump

heroku pg:backups:restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' HEROKU_POSTGRESQL_COLOR_URL

Several times I have imported these databases because after a few minutes they disappear. I ran my Heroku app and the first database was successfully accessed but by the time I tried to access the second one I received a 'relation "xxxx" does not exist'. When I went back to my datastore the databases were gone. When I tried to run my app a second time I got a 'relation "xxxx" does not exist' on the first table that I successfully accessed the previous time I ran my app.

I'm not seeing any errors when I look at the data-store for the database. They just disappear. I checked to see if there was a limit to the number of databases I could have with the hobby-dev but did not see any. The row count is under 10,000. Each time I have imported my pg_dump files I get a warning email about the number of rows.

UPDATE 2/17/2017 10:42 AM central: The only thing I have found so far are some posts stating that the Heroku filesystem is ephemeral, and does not persist between dyno restarts. If this is my problem:

  1. How do I know when dynos restart if I don't restart it? I had not restarted my app when my databases disappeared.
  2. How can I permanently store my databases using the Postgres add-on or do I have to store my databases elsewhere? Surely the add-on has a way to permanently store databases.

Solution

  • I assume you use Heroku PostgreSQL offering (instead of trying to set it up on your own). If that's the case the ephemeral nature of dyno file systems shouldn't be your concern.

    I recommend that you first create the seven (empty) databases and see if they disappear or not. You can create a single database with

    heroku addons:create heroku-postgresql:hobby-dev
    

    After each call run heroku pg:wait to wait until the database has been provisioned. If the databases don't disappear try restoring your backups then.