Skip to main content

Following the instructions on CKAN DataStore with a little information.

 

Enable the plugin

In your CKAN config file (/etc/ckan/default/ckan.ini), update the datastore plugin

ckan.plugins = datastore

 

Set-up the database

The DataStore requires a separate PostgreSQL database to save the DataStore resources.  List the existing databases:

sudo -u postgres psql -l

Response

                                    List of databases
       Name        |    Owner     | Encoding | Collate |  Ctype  |   Access privileges
-------------------+--------------+----------+---------+---------+-----------------------
 ckan_default      | ckan_default | UTF8     | C.UTF-8 | C.UTF-8 |
 datastore_default | ckan_default | UTF8     | C.UTF-8 | C.UTF-8 |
 postgres          | postgres     | UTF8     | C.UTF-8 | C.UTF-8 |
 template0         | postgres     | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
                   |              |          |         |         | postgres=CTc/postgres
 template1         | postgres     | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
                   |              |          |         |         | postgres=CTc/postgres

 

Create the database and user

Create a database_user called datastore_default. This user will be given read-only access to your DataStore database in the Set Permissions step below:

sudo -u postgres createuser -S -D -R -P -l datastore_default

Create the database (owned by ckan_default), in tis instance call the database datastore_default:

sudo -u postgres createdb -O ckan_default datastore_default -E utf-8

 

Set URLs in CKAN config file

Uncomment the ckan.datastore.write_url and ckan.datastore.read_url lines in your CKAN config file and edit them if necessary, for example:

ckan.datastore.write_url = postgresql://ckan_default:{pass}@localhost/datastore_default
ckan.datastore.read_url = postgresql://datastore_default:{pass}@localhost/datastore_default

Remember to replace {pass} with the passwords you created for your ckan_default and datastore_default database users.

 

Set permissions

If you can connect to your database server as the postgres superuser using:

sudo -u postgres psql

Then you can use this connection to set the permissions.  But do this step outside of being in the database.  If you have run the above command, enter exit to leave the database CLI.  Now you can run:

ckan -c /etc/ckan/default/ckan.ini datastore set-permissions | sudo -u postgres psql --set ON_ERROR_STOP=1

 

Check the permissions have been updated, by 

sudo -u postgres psql -l

Response

                                         List of databases
       Name        |    Owner     | Encoding | Collate |  Ctype  |        Access privileges
-------------------+--------------+----------+---------+---------+----------------------------------
 ckan_default      | ckan_default | UTF8     | C.UTF-8 | C.UTF-8 | =Tc/ckan_default                +
                   |              |          |         |         | ckan_default=CTc/ckan_default
 datastore_default | ckan_default | UTF8     | C.UTF-8 | C.UTF-8 | =Tc/ckan_default                +
                   |              |          |         |         | ckan_default=CTc/ckan_default   +
                   |              |          |         |         | datastore_default=c/ckan_default
 postgres          | postgres     | UTF8     | C.UTF-8 | C.UTF-8 |
 template0         | postgres     | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres                     +
                   |              |          |         |         | postgres=CTc/postgres
 template1         | postgres     | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres                     +
                   |              |          |         |         | postgres=CTc/postgres
(5 rows)

 

 

Related articles

Andrew Fletcher27 Oct 2023
Using OpenAI to summarise PDF
To use OpenAI to summarise text from a PDF using Python 3.11.6, you'll first need to extract the text from the PDF and then send it to the OpenAI API for summarisation. Preparation Set-uppip install python-dotenv langchain openai tiktoken pypdf pymupdf CodeThe current code is on my...
Andrew Fletcher20 Oct 2023
PermissionError: [Errno 13] Permission denied
Permission errorTraceback (most recent call last): File "/var/www/html/open-ai/summarise-ai.py", line 144, in <module> getfiles() File "/var/www/html/open-ai/summarise-ai.py", line 26, in getfiles summarise(filename) File "/var/www/html/open-ai/summarise-ai.py", line 105, in...
Andrew Fletcher19 Oct 2023
How to add an environment variable in Ubuntu
To set an environment variable on Ubuntu, can be achieved via a few options.  This depends on whether you want the variable to be system-wide or specific to a user's session.  Here are a couple of more common methods for setting environment variables:Setting environment variables for the...