Skip to main content

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

 

Related articles

Andrew Fletcher29 Sep 2023
Installing CKAN from package on Ubuntu 20.04
&nbsp;Install the CKAN packageBegin by cleaning up your server environment. &nbsp;Do this by updating Ubuntu’s package index:sudo apt updateNow you can install the packages that CKAN requires (including ‘git’, which will allow you to install CKAN extensions):sudo apt install -y libpq5 redis-server...
Andrew Fletcher29 Sep 2023
Installing CKAN from source on Ubuntu 20.04
If you're planning to create extensions, generating CKAN from source is the preferred option. &nbsp;However, even if you have installed from package, you can make adjustments to creating extensions.&nbsp;Set up your serverBegin by cleaning up your server environment. &nbsp;Do this by updating...
Andrew Fletcher29 Sep 2023
CKAN adding an extension
CKAN extensions - adding to your installation&nbsp;Following the information on the CKAN siteUse the CKAN create command to create an empty extension:Activate your CKAN virtual environment, for example:. /usr/lib/ckan/default/bin/activateThen check your location iscd /usr/lib/ckan/default/srcSo you...