Before you can run CKAN for the first time, you need to run db init to initialise your database:
ckan -c /etc/ckan/default/ckan.ini db init
If this fails due to a permission issue, then the user and group assigned are incorrect. Or if you are a root user, you can use sudo
sudo ckan -c /etc/ckan/default/ckan.ini db init
If you forget this step you'll see a 500 server error:
503 Service Unavailable: This site is currently offline. The database is not initialised.
Cleaning your db
Warning - This action will delete all data from your CKAN database! You can delete everything in the CKAN database, including the tables, to start from scratch:
ckan -c /etc/ckan/default/ckan.ini db clean
Once completed, you must either initialise the db or import a previously created dump.
Import and export your db
Like all databases, using CLI (command line tools) PostgreSQL you can export (pg_dump) and import (pg_restore) for content to/from a file.
To export your CKAN database:
sudo -u postgres pg_dump --format=custom -d ckan_default > ckan.dump
And to import, clean first then restore:
ckan -c /etc/ckan/default/ckan.ini db clean
sudo -u postgres pg_restore --clean --if-exists -d ckan_default < ckan.dump
If you are upgrading to a new CKAN major release, update your CKAN database’s schema:
ckan -c /etc/ckan/default/ckan.ini db upgrade
Once the import has been completed, rebuild the search index. This will prevent search indexes from getting out of sync with the main database:
ckan -c /etc/ckan/default/ckan.ini search-index rebuild