Webapp Database Setup¶
You must tell Django to create the database tables used by the graphite webapp. This is very straight forward, especially if you are using the default SQLite setup.
The following configures the Django database settings. Graphite uses the database for storing user profiles, dashboards, and for the Events functionality. Graphite uses an SQLite database file located at STORAGE_DIR/graphite.db
by default. If running multiple Graphite-web instances, a database such as PostgreSQL or MySQL is required so that all instances may share the same data source.
Note
As of Django 1.2, the database configuration is specified by the DATABASES
dictionary instead of the old DATABASE_*
format. Users must use the new
specification to have a working database.
See the Django documentation for full documentation of the DATABASES setting.
Note
If you are using a custom database backend (other than SQLite) you must first create a $GRAPHITE_ROOT/webapp/graphite/local_settings.py file that overrides the database related settings from settings.py. Use $GRAPHITE_ROOT/webapp/graphite/local_settings.py.example as a template.
To set up a new database and create the initial schema, run:
PYTHONPATH=$GRAPHITE_ROOT/webapp django-admin.py migrate --settings=graphite.settings
Note
Graphite-Web 1.0 and earlier had some models without migrations, and with Django 1.9 or later, the --run-syncdb
option was needed for migrate to create tables for these models. (Django 1.8 and earlier did not have this option, but always exhibited this behavior.) In Graphite-Web 1.1 and later all models have migrations, so --run-syncdb
is no longer needed. If upgrading a database created by Graphite-Web 1.0 or earlier, you need to use the --fake-initial
option for migrate: it considers an initial migration to already be applied if the tables it creates already exist.
If you are experiencing problems, uncomment the following line in /opt/graphite/webapp/graphite/local_settings.py:
# DEBUG = True
and review your webapp logs. If you’re using the default graphite-example-vhost.conf, your logs will be found in /opt/graphite/storage/log/webapp/.
If you’re using the default SQLite database, your webserver will need permissions to read and write to the database file. So, for example, if your webapp is running in Apache as the ‘nobody’ user, you will need to fix the permissions like this:
sudo chown nobody:nobody /opt/graphite/storage/graphite.db