Sqlite Database Hosted on Heroku Getting Automatically Reset

SQLite database hosted on Heroku getting automatically reset

Heroku has an ephemeral file system that loses any changes each time the dyno restarts, which happens frequently. You should store SQL lite files on amazon or use an Heroku database.

Heroku app database resetting

As stated by @DanielRoseman you should not use SQLite on heroku, because SQLite runs in memory, and backs up its data store in files on disk.
Let me quote from the heroku doku:

SQLite runs in memory, and backs up its data store in files on disk. While this strategy works well for development, Heroku’s Cedar stack has an ephemeral filesystem. You can write to it, and you can read from it, but the contents will be cleared periodically. If you were to use SQLite on Heroku, you would lose your entire database at least once every 24 hours.

Even if Heroku’s disks were persistent running SQLite would still not be a good fit. Since SQLite does not run as a service, each dyno would run a separate running copy. Each of these copies need their own disk backed store. This would mean that each dyno powering your app would have a different set of data since the disks are not synchronized.

Instead of using SQLite on Heroku you can configure your app to run on Postgres.

It is really easy to use postgres in django. You only have to change the database adapter in your settings file:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'myuser',
'PASSWORD': 'password',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}

There is also a tutorial on how to setup a django application on herku in their docu section:

https://devcenter.heroku.com/articles/django-app-configuration

Django: sudden DB reset after Heroku sleep

Heroku dynos have an ephemeral filesystem (https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem). Since you are using SQLite which is actually a file on the filesystem, everything will run smoothly until the dyno running your application needs to restart - so its filesystem will be reset and you'll lose everything !

To avoid it just configure your application to use Heroku-Postgresql.

Why is my app deployed on Heroku has its database reset periodically?

I looked up your question on the internet. The news is not good. As it turns out you can't really use SQLite on heroku. Check here under Disk Backed Storage. Unfortunately your probably going to have to change databases. I would suggest PostgreSQL. I use that on heroku with no problems.

Heroku db delete

I think it's because Heroku has a temporary filesystem (Ephemeral Filesystem). So when a dyno is restarted, all changes made to the application up to that time are undone and restored to the state you deployed.

Similar solutions are already available for this:

https://devcenter.heroku.com/articles/dynos#restarting

Added database records are deleted after restarting app (heroku/SQLAlchemy)

SQLite database hosted on Heroku getting automatically reset



Related Topics



Leave a reply



Submit